diff options
author | Jon Moss <me@jonathanmoss.me> | 2018-08-02 18:51:02 -0400 |
---|---|---|
committer | Jon Moss <me@jonathanmoss.me> | 2018-08-07 10:51:27 -0400 |
commit | e570ae79f5b1d74fed52d2aed7f014caaa0836dd (patch) | |
tree | 004749b9ff1a59964ba7186c105956614671e48a /lib/internal/crypto/hash.js | |
parent | 080316b32a0e6320e012214c32725099a0248de6 (diff) | |
download | android-node-v8-e570ae79f5b1d74fed52d2aed7f014caaa0836dd.tar.gz android-node-v8-e570ae79f5b1d74fed52d2aed7f014caaa0836dd.tar.bz2 android-node-v8-e570ae79f5b1d74fed52d2aed7f014caaa0836dd.zip |
lib: extract validateString validator
Pulls out a common argument validator to `internal/validators`
PR-URL: https://github.com/nodejs/node/pull/22101
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/internal/crypto/hash.js')
-rw-r--r-- | lib/internal/crypto/hash.js | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/internal/crypto/hash.js b/lib/internal/crypto/hash.js index d172a6a3c8..7127d4d7ef 100644 --- a/lib/internal/crypto/hash.js +++ b/lib/internal/crypto/hash.js @@ -18,6 +18,7 @@ const { ERR_CRYPTO_HASH_UPDATE_FAILED, ERR_INVALID_ARG_TYPE } = require('internal/errors').codes; +const { validateString } = require('internal/validators'); const { inherits } = require('util'); const { normalizeEncoding } = require('internal/util'); const { isArrayBufferView } = require('internal/util/types'); @@ -28,8 +29,7 @@ const kFinalized = Symbol('finalized'); function Hash(algorithm, options) { if (!(this instanceof Hash)) return new Hash(algorithm, options); - if (typeof algorithm !== 'string') - throw new ERR_INVALID_ARG_TYPE('algorithm', 'string', algorithm); + validateString(algorithm, 'algorithm'); this._handle = new _Hash(algorithm); this[kState] = { [kFinalized]: false @@ -83,8 +83,7 @@ Hash.prototype.digest = function digest(outputEncoding) { function Hmac(hmac, key, options) { if (!(this instanceof Hmac)) return new Hmac(hmac, key, options); - if (typeof hmac !== 'string') - throw new ERR_INVALID_ARG_TYPE('hmac', 'string', hmac); + validateString(hmac, 'hmac'); if (typeof key !== 'string' && !isArrayBufferView(key)) { throw new ERR_INVALID_ARG_TYPE('key', ['string', 'TypedArray', 'DataView'], key); |