From 31d9b2f14fe9851b530c213b92e14b4646f6d131 Mon Sep 17 00:00:00 2001 From: Tobias Nießen Date: Fri, 19 Jul 2019 02:44:31 +0200 Subject: 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 Reviewed-By: Sam Roberts Reviewed-By: Rich Trott --- lib/internal/crypto/hash.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/internal/crypto/hash.js') 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 }; -- cgit v1.2.3