10BC0
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 87fb1c2 commit ab4c53eCopy full SHA for ab4c53e
doc/api/errors.md
@@ -763,14 +763,6 @@ to enable or disable FIPS mode in the `crypto` module.
763
An attempt was made to enable or disable FIPS mode, but FIPS mode was not
764
available.
765
766
-<a id="ERR_CRYPTO_HASH_DIGEST_NO_UTF16"></a>
767
-### ERR_CRYPTO_HASH_DIGEST_NO_UTF16
768
-
769
-The UTF-16 encoding was used with [`hash.digest()`][]. While the
770
-`hash.digest()` method does allow an `encoding` argument to be passed in,
771
-causing the method to return a string rather than a `Buffer`, the UTF-16
772
-encoding (e.g. `ucs` or `utf16le`) is not supported.
773
774
<a id="ERR_CRYPTO_HASH_FINALIZED"></a>
775
### ERR_CRYPTO_HASH_FINALIZED
776
@@ -2070,6 +2062,18 @@ removed: v11.12.0
2070
2062
There was an attempt to use a `MessagePort` instance in a closed
2071
2063
state, usually after `.close()` has been called.
2072
2064
2065
+<a id="ERR_CRYPTO_HASH_DIGEST_NO_UTF16"></a>
2066
+### ERR_CRYPTO_HASH_DIGEST_NO_UTF16
2067
+<!-- YAML
2068
+added: v9.0.0
2069
+removed: REPLACEME
+-->
+
+The UTF-16 encoding was used with [`hash.digest()`][]. While the
2073
+`hash.digest()` method does allow an `encoding` argument to be passed in,
2074
+causing the method to return a string rather than a `Buffer`, the UTF-16
2075
+encoding (e.g. `ucs` or `utf16le`) is not supported.
2076
2077
<a id="ERR_HTTP2_FRAME_ERROR"></a>
2078
### ERR_HTTP2_FRAME_ERROR
2079
<!-- YAML
lib/internal/crypto/hash.js
@@ -20,13 +20,14 @@ const {
20
const { Buffer } = require('buffer');
21
22
const {
23
- ERR_CRYPTO_HASH_DIGEST_NO_UTF16,
24
ERR_CRYPTO_HASH_FINALIZED,
25
ERR_CRYPTO_HASH_UPDATE_FAILED,
26
ERR_INVALID_ARG_TYPE
27
} = require('internal/errors').codes;
28
-const { validateString, validateUint32 } = require('internal/validators');
29
-const { normalizeEncoding } = require('internal/util');
+const {
+ validateString,
+ validateUint32
30
+} = require('internal/validators');
31
const { isArrayBufferView } = require('internal/util/types');
32
const LazyTransform = require('internal/streams/lazy_transform');
33
const kState = Symbol('kState');
@@ -85,8 +86,6 @@ Hash.prototype.digest = function digest(outputEncoding) {
85
86
if (state[kFinalized])
87
throw new ERR_CRYPTO_HASH_FINALIZED();
88
outputEncoding = outputEncoding || getDefaultEncoding();
- if (normalizeEncoding(outputEncoding) === 'utf16le')
89
- throw new ERR_CRYPTO_HASH_DIGEST_NO_UTF16();
90
91
// Explicit conversion for backward compatibility.
92
const ret = this[kHandle].digest(`${outputEncoding}`);
@@ -116,8 +115,6 @@ Hmac.prototype.update = Hash.prototype.update;
116
115
Hmac.prototype.digest = function digest(outputEncoding) {
117
const state = this[kState];
118
119
120
121
122
if (state[kFinalized]) {
123
const buf = Buffer.from('');
lib/internal/errors.js
@@ -744,8 +744,6 @@ E('ERR_CRYPTO_FIPS_FORCED',
744
'Cannot set FIPS mode, it was forced with --force-fips at startup.', Error);
745
E('ERR_CRYPTO_FIPS_UNAVAILABLE', 'Cannot set FIPS mode in a non-FIPS build.',
746
Error);
747
-E('ERR_CRYPTO_HASH_DIGEST_NO_UTF16', 'hash.digest() does not support UTF-16',
748
- Error);
749
E('ERR_CRYPTO_HASH_FINALIZED', 'Digest already called', Error);
750
E('ERR_CRYPTO_HASH_UPDATE_FAILED', 'Hash update failed', Error);
751
E('ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS', 'The selected key encoding %s %s.',
src/node_crypto.cc
@@ -4676,7 +4676,6 @@ void Hmac::HmacDigest(const FunctionCallbackInfo<Value>& args) {
4676
if (args.Length() >= 1) {
4677
encoding = ParseEncoding(env->isolate(), args[0], BUFFER);
4678
}
4679
- CHECK_NE(encoding, UCS2); // Digest does not support UTF-16
4680
4681
unsigned char md_value[EVP_MAX_MD_SIZE];
4682
unsigned int md_len = 0;
test/parallel/test-crypto-hash.js
@@ -161,13 +161,9 @@ common.expectsError(
161
type: Error
162
});
163
164
-common.expectsError(
165
- () => crypto.createHash('sha256').digest('ucs2'),
166
- {
167
- code: 'ERR_CRYPTO_HASH_DIGEST_NO_UTF16',
168
- type: Error
169
- }
170
-);
+assert.strictEqual(
+ crypto.createHash('sha256').update('test').digest('ucs2'),
+ crypto.createHash('sha256').update('test').digest().toString('ucs2'));
171
172
common.expectsError(
173
() => crypto.createHash(),
test/parallel/test-crypto-hmac.js
@@ -408,12 +408,9 @@ const rfc2202_sha1 = [
408
for (const { key, data, hmac } of rfc2202_sha1)
409
testHmac('sha1', key, data, hmac);
410
411
412
- () => crypto.createHmac('sha256', 'w00t').digest('ucs2'),
413
414
415
416
- });
+ crypto.createHmac('sha256', 'w00t').digest('ucs2'),
+ crypto.createHmac('sha256', 'w00t').digest().toString('ucs2'));
417
418
// Check initiali 3E1A zed -> uninitialized state transition after calling digest().
419
{