summaryrefslogtreecommitdiff
path: root/lib/internal/crypto/hash.js
diff options
context:
space:
mode:
authorTobias Nießen <tniessen@tnie.de>2019-07-19 02:44:31 +0200
committerRich Trott <rtrott@gmail.com>2019-07-25 23:00:41 -0700
commit31d9b2f14fe9851b530c213b92e14b4646f6d131 (patch)
tree6499824adfea4686e4dfd9695204ae187a275905 /lib/internal/crypto/hash.js
parent64e4b0c0ac5073e6606b1ccd79a464f2c5925741 (diff)
downloadandroid-node-v8-31d9b2f14fe9851b530c213b92e14b4646f6d131.tar.gz
android-node-v8-31d9b2f14fe9851b530c213b92e14b4646f6d131.tar.bz2
android-node-v8-31d9b2f14fe9851b530c213b92e14b4646f6d131.zip
crypto: add outputLength option to crypto.createHash
This change adds an outputLength option to crypto.createHash which allows users to produce variable-length hash values using XOF hash functons. Fixes: https://github.com/nodejs/node/issues/28757 PR-URL: https://github.com/nodejs/node/pull/28805 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'lib/internal/crypto/hash.js')
-rw-r--r--lib/internal/crypto/hash.js7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/internal/crypto/hash.js b/lib/internal/crypto/hash.js
index a581648021..667624dce0 100644
--- a/lib/internal/crypto/hash.js
+++ b/lib/internal/crypto/hash.js
@@ -25,7 +25,7 @@ const {
ERR_CRYPTO_HASH_UPDATE_FAILED,
ERR_INVALID_ARG_TYPE
} = require('internal/errors').codes;
-const { validateString } = require('internal/validators');
+const { validateString, validateUint32 } = require('internal/validators');
const { normalizeEncoding } = require('internal/util');
const { isArrayBufferView } = require('internal/util/types');
const LazyTransform = require('internal/streams/lazy_transform');
@@ -36,7 +36,10 @@ function Hash(algorithm, options) {
if (!(this instanceof Hash))
return new Hash(algorithm, options);
validateString(algorithm, 'algorithm');
- this[kHandle] = new _Hash(algorithm);
+ const xofLen = typeof options === 'object' ? options.outputLength : undefined;
+ if (xofLen !== undefined)
+ validateUint32(xofLen, 'options.outputLength');
+ this[kHandle] = new _Hash(algorithm, xofLen);
this[kState] = {
[kFinalized]: false
};