Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ab4c53e

Browse filesBrowse files
addaleaxBridgeAR
authored andcommitted
crypto: remove arbitrary UTF16 restriction
Since 71f633a, this is no longer necessary. Refs: #22622 Fixes: #29793 PR-URL: #29795 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com>
1 parent 87fb1c2 commit ab4c53e
Copy full SHA for ab4c53e

File tree

Expand file treeCollapse file tree

6 files changed

+22
-31
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

6 files changed

+22
-31
lines changed
Open diff view settings
Collapse file

‎doc/api/errors.md‎

Copy file name to clipboardExpand all lines: doc/api/errors.md
+12-8Lines changed: 12 additions & 8 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -763,14 +763,6 @@ to enable or disable FIPS mode in the `crypto` module.
763763
An attempt was made to enable or disable FIPS mode, but FIPS mode was not
764764
available.
765765

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-
774766
<a id="ERR_CRYPTO_HASH_FINALIZED"></a>
775767
### ERR_CRYPTO_HASH_FINALIZED
776768

@@ -2070,6 +2062,18 @@ removed: v11.12.0
20702062
There was an attempt to use a `MessagePort` instance in a closed
20712063
state, usually after `.close()` has been called.
20722064

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
2070+
-->
2071+
2072+
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+
20732077
<a id="ERR_HTTP2_FRAME_ERROR"></a>
20742078
### ERR_HTTP2_FRAME_ERROR
20752079
<!-- YAML
Collapse file

‎lib/internal/crypto/hash.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/hash.js
+4-7Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ const {
2020
const { Buffer } = require('buffer');
2121

2222
const {
23-
ERR_CRYPTO_HASH_DIGEST_NO_UTF16,
2423
ERR_CRYPTO_HASH_FINALIZED,
2524
ERR_CRYPTO_HASH_UPDATE_FAILED,
2625
ERR_INVALID_ARG_TYPE
2726
} = require('internal/errors').codes;
28-
const { validateString, validateUint32 } = require('internal/validators');
29-
const { normalizeEncoding } = require('internal/util');
27+
const {
28+
validateString,
29+
validateUint32
30+
} = require('internal/validators');
3031
const { isArrayBufferView } = require('internal/util/types');
3132
const LazyTransform = require('internal/streams/lazy_transform');
3233
const kState = Symbol('kState');
@@ -85,8 +86,6 @@ Hash.prototype.digest = function digest(outputEncoding) {
8586
if (state[kFinalized])
8687
throw new ERR_CRYPTO_HASH_FINALIZED();
8788
outputEncoding = outputEncoding || getDefaultEncoding();
88-
if (normalizeEncoding(outputEncoding) === 'utf16le')
89-
throw new ERR_CRYPTO_HASH_DIGEST_NO_UTF16();
9089

9190
// Explicit conversion for backward compatibility.
9291
const ret = this[kHandle].digest(`${outputEncoding}`);
@@ -116,8 +115,6 @@ Hmac.prototype.update = Hash.prototype.update;
116115
Hmac.prototype.digest = function digest(outputEncoding) {
117116
const state = this[kState];
118117
outputEncoding = outputEncoding || getDefaultEncoding();
119-
if (normalizeEncoding(outputEncoding) === 'utf16le')
120-
throw new ERR_CRYPTO_HASH_DIGEST_NO_UTF16();
121118

122119
if (state[kFinalized]) {
123120
const buf = Buffer.from('');
Collapse file

‎lib/internal/errors.js‎

Copy file name to clipboardExpand all lines: lib/internal/errors.js
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,6 @@ E('ERR_CRYPTO_FIPS_FORCED',
744744
'Cannot set FIPS mode, it was forced with --force-fips at startup.', Error);
745745
E('ERR_CRYPTO_FIPS_UNAVAILABLE', 'Cannot set FIPS mode in a non-FIPS build.',
746746
Error);
747-
E('ERR_CRYPTO_HASH_DIGEST_NO_UTF16', 'hash.digest() does not support UTF-16',
748-
Error);
749747
E('ERR_CRYPTO_HASH_FINALIZED', 'Digest already called', Error);
750748
E('ERR_CRYPTO_HASH_UPDATE_FAILED', 'Hash update failed', Error);
751749
E('ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS', 'The selected key encoding %s %s.',
Collapse file

‎src/node_crypto.cc‎

Copy file name to clipboardExpand all lines: src/node_crypto.cc
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4676,7 +4676,6 @@ void Hmac::HmacDigest(const FunctionCallbackInfo<Value>& args) {
46764676
if (args.Length() >= 1) {
46774677
encoding = ParseEncoding(env->isolate(), args[0], BUFFER);
46784678
}
4679-
CHECK_NE(encoding, UCS2); // Digest does not support UTF-16
46804679

46814680
unsigned char md_value[EVP_MAX_MD_SIZE];
46824681
unsigned int md_len = 0;
Collapse file

‎test/parallel/test-crypto-hash.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-hash.js
+3-7Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,9 @@ common.expectsError(
161161
type: Error
162162
});
163163

164-
common.expectsError(
165-
() => crypto.createHash('sha256').digest('ucs2'),
166-
{
167-
code: 'ERR_CRYPTO_HASH_DIGEST_NO_UTF16',
168-
type: Error
169-
}
170-
);
164+
assert.strictEqual(
165+
crypto.createHash('sha256').update('test').digest('ucs2'),
166+
crypto.createHash('sha256').update('test').digest().toString('ucs2'));
171167

172168
common.expectsError(
173169
() => crypto.createHash(),
Collapse file

‎test/parallel/test-crypto-hmac.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-hmac.js
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,9 @@ const rfc2202_sha1 = [
408408
for (const { key, data, hmac } of rfc2202_sha1)
409409
testHmac('sha1', key, data, hmac);
410410

411-
common.expectsError(
412-
() => crypto.createHmac('sha256', 'w00t').digest('ucs2'),
413-
{
414-
code: 'ERR_CRYPTO_HASH_DIGEST_NO_UTF16',
415-
type: Error
416-
});
411+
assert.strictEqual(
412+
crypto.createHmac('sha256', 'w00t').digest('ucs2'),
413+
crypto.createHmac('sha256', 'w00t').digest().toString('ucs2'));
417414

418415
// Check initialized -> uninitialized state transition after calling digest().
419416
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.