mirror of https://github.com/nodejs/node.git
crypto: remove arbitrary UTF16 restriction
Since 71f633a32f
, this is no longer necessary.
Refs: https://github.com/nodejs/node/pull/22622
Fixes: https://github.com/nodejs/node/issues/29793
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
500720f578
commit
389969ea92
|
@ -765,14 +765,6 @@ to enable or disable FIPS mode in the `crypto` module.
|
|||
An attempt was made to enable or disable FIPS mode, but FIPS mode was not
|
||||
available.
|
||||
|
||||
<a id="ERR_CRYPTO_HASH_DIGEST_NO_UTF16"></a>
|
||||
### ERR_CRYPTO_HASH_DIGEST_NO_UTF16
|
||||
|
||||
The UTF-16 encoding was used with [`hash.digest()`][]. While the
|
||||
`hash.digest()` method does allow an `encoding` argument to be passed in,
|
||||
causing the method to return a string rather than a `Buffer`, the UTF-16
|
||||
encoding (e.g. `ucs` or `utf16le`) is not supported.
|
||||
|
||||
<a id="ERR_CRYPTO_HASH_FINALIZED"></a>
|
||||
### ERR_CRYPTO_HASH_FINALIZED
|
||||
|
||||
|
@ -2078,6 +2070,18 @@ removed: v11.12.0
|
|||
There was an attempt to use a `MessagePort` instance in a closed
|
||||
state, usually after `.close()` has been called.
|
||||
|
||||
<a id="ERR_CRYPTO_HASH_DIGEST_NO_UTF16"></a>
|
||||
### ERR_CRYPTO_HASH_DIGEST_NO_UTF16
|
||||
<!-- YAML
|
||||
added: v9.0.0
|
||||
removed: REPLACEME
|
||||
-->
|
||||
|
||||
The UTF-16 encoding was used with [`hash.digest()`][]. While the
|
||||
`hash.digest()` method does allow an `encoding` argument to be passed in,
|
||||
causing the method to return a string rather than a `Buffer`, the UTF-16
|
||||
encoding (e.g. `ucs` or `utf16le`) is not supported.
|
||||
|
||||
<a id="ERR_HTTP2_FRAME_ERROR"></a>
|
||||
### ERR_HTTP2_FRAME_ERROR
|
||||
<!-- YAML
|
||||
|
|
|
@ -20,14 +20,12 @@ const {
|
|||
const { Buffer } = require('buffer');
|
||||
|
||||
const {
|
||||
ERR_CRYPTO_HASH_DIGEST_NO_UTF16,
|
||||
ERR_CRYPTO_HASH_FINALIZED,
|
||||
ERR_CRYPTO_HASH_UPDATE_FAILED,
|
||||
ERR_INVALID_ARG_TYPE
|
||||
} = require('internal/errors').codes;
|
||||
const { validateEncoding, validateString, validateUint32 } =
|
||||
require('internal/validators');
|
||||
const { normalizeEncoding } = require('internal/util');
|
||||
const { isArrayBufferView } = require('internal/util/types');
|
||||
const LazyTransform = require('internal/streams/lazy_transform');
|
||||
const kState = Symbol('kState');
|
||||
|
@ -90,8 +88,6 @@ Hash.prototype.digest = function digest(outputEncoding) {
|
|||
if (state[kFinalized])
|
||||
throw new ERR_CRYPTO_HASH_FINALIZED();
|
||||
outputEncoding = outputEncoding || getDefaultEncoding();
|
||||
if (normalizeEncoding(outputEncoding) === 'utf16le')
|
||||
throw new ERR_CRYPTO_HASH_DIGEST_NO_UTF16();
|
||||
|
||||
// Explicit conversion for backward compatibility.
|
||||
const ret = this[kHandle].digest(`${outputEncoding}`);
|
||||
|
@ -121,8 +117,6 @@ Hmac.prototype.update = Hash.prototype.update;
|
|||
Hmac.prototype.digest = function digest(outputEncoding) {
|
||||
const state = this[kState];
|
||||
outputEncoding = outputEncoding || getDefaultEncoding();
|
||||
if (normalizeEncoding(outputEncoding) === 'utf16le')
|
||||
throw new ERR_CRYPTO_HASH_DIGEST_NO_UTF16();
|
||||
|
||||
if (state[kFinalized]) {
|
||||
const buf = Buffer.from('');
|
||||
|
|
|
@ -749,8 +749,6 @@ E('ERR_CRYPTO_FIPS_FORCED',
|
|||
'Cannot set FIPS mode, it was forced with --force-fips at startup.', Error);
|
||||
E('ERR_CRYPTO_FIPS_UNAVAILABLE', 'Cannot set FIPS mode in a non-FIPS build.',
|
||||
Error);
|
||||
E('ERR_CRYPTO_HASH_DIGEST_NO_UTF16', 'hash.digest() does not support UTF-16',
|
||||
Error);
|
||||
E('ERR_CRYPTO_HASH_FINALIZED', 'Digest already called', Error);
|
||||
E('ERR_CRYPTO_HASH_UPDATE_FAILED', 'Hash update failed', Error);
|
||||
E('ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS', 'The selected key encoding %s %s.',
|
||||
|
|
|
@ -4678,7 +4678,6 @@ void Hmac::HmacDigest(const FunctionCallbackInfo<Value>& args) {
|
|||
if (args.Length() >= 1) {
|
||||
encoding = ParseEncoding(env->isolate(), args[0], BUFFER);
|
||||
}
|
||||
CHECK_NE(encoding, UCS2); // Digest does not support UTF-16
|
||||
|
||||
unsigned char md_value[EVP_MAX_MD_SIZE];
|
||||
unsigned int md_len = 0;
|
||||
|
|
|
@ -161,13 +161,9 @@ common.expectsError(
|
|||
type: Error
|
||||
});
|
||||
|
||||
common.expectsError(
|
||||
() => crypto.createHash('sha256').digest('ucs2'),
|
||||
{
|
||||
code: 'ERR_CRYPTO_HASH_DIGEST_NO_UTF16',
|
||||
type: Error
|
||||
}
|
||||
);
|
||||
assert.strictEqual(
|
||||
crypto.createHash('sha256').update('test').digest('ucs2'),
|
||||
crypto.createHash('sha256').update('test').digest().toString('ucs2'));
|
||||
|
||||
common.expectsError(
|
||||
() => crypto.createHash(),
|
||||
|
|
|
@ -408,12 +408,9 @@ const rfc2202_sha1 = [
|
|||
for (const { key, data, hmac } of rfc2202_sha1)
|
||||
testHmac('sha1', key, data, hmac);
|
||||
|
||||
common.expectsError(
|
||||
() => crypto.createHmac('sha256', 'w00t').digest('ucs2'),
|
||||
{
|
||||
code: 'ERR_CRYPTO_HASH_DIGEST_NO_UTF16',
|
||||
type: Error
|
||||
});
|
||||
assert.strictEqual(
|
||||
crypto.createHmac('sha256', 'w00t').digest('ucs2'),
|
||||
crypto.createHmac('sha256', 'w00t').digest().toString('ucs2'));
|
||||
|
||||
// Check initialized -> uninitialized state transition after calling digest().
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue