diff options
author | Michaël Zasso <targos@protonmail.com> | 2018-03-04 22:16:24 +0100 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2018-03-07 14:54:38 +0100 |
commit | 1d2fd8b65bacaf4401450edc8ed529106cbcfc67 (patch) | |
tree | dd6230e888c69ef3dc1b19de1ea8f9de7a81fd63 /lib/internal/crypto/hash.js | |
parent | cb5f9a6d871f6b2e0da8fa72dc2e91fb37ef9713 (diff) | |
download | android-node-v8-1d2fd8b65bacaf4401450edc8ed529106cbcfc67.tar.gz android-node-v8-1d2fd8b65bacaf4401450edc8ed529106cbcfc67.tar.bz2 android-node-v8-1d2fd8b65bacaf4401450edc8ed529106cbcfc67.zip |
lib: port remaining errors to new system
PR-URL: https://github.com/nodejs/node/pull/19137
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'lib/internal/crypto/hash.js')
-rw-r--r-- | lib/internal/crypto/hash.js | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/lib/internal/crypto/hash.js b/lib/internal/crypto/hash.js index 952cc34d21..41e00b88b9 100644 --- a/lib/internal/crypto/hash.js +++ b/lib/internal/crypto/hash.js @@ -12,7 +12,12 @@ const { const { Buffer } = require('buffer'); -const errors = require('internal/errors'); +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 { inherits } = require('util'); const { normalizeEncoding } = require('internal/util'); const { isArrayBufferView } = require('internal/util/types'); @@ -24,7 +29,7 @@ function Hash(algorithm, options) { if (!(this instanceof Hash)) return new Hash(algorithm, options); if (typeof algorithm !== 'string') - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'algorithm', 'string'); + throw new ERR_INVALID_ARG_TYPE('algorithm', 'string'); this._handle = new _Hash(algorithm); this[kState] = { [kFinalized]: false @@ -47,15 +52,15 @@ Hash.prototype._flush = function _flush(callback) { Hash.prototype.update = function update(data, encoding) { const state = this[kState]; if (state[kFinalized]) - throw new errors.Error('ERR_CRYPTO_HASH_FINALIZED'); + throw new ERR_CRYPTO_HASH_FINALIZED(); if (typeof data !== 'string' && !isArrayBufferView(data)) { - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'data', - ['string', 'TypedArray', 'DataView']); + throw new ERR_INVALID_ARG_TYPE('data', + ['string', 'TypedArray', 'DataView']); } if (!this._handle.update(data, encoding || getDefaultEncoding())) - throw new errors.Error('ERR_CRYPTO_HASH_UPDATE_FAILED'); + throw new ERR_CRYPTO_HASH_UPDATE_FAILED(); return this; }; @@ -63,10 +68,10 @@ Hash.prototype.update = function update(data, encoding) { Hash.prototype.digest = function digest(outputEncoding) { const state = this[kState]; if (state[kFinalized]) - throw new errors.Error('ERR_CRYPTO_HASH_FINALIZED'); + throw new ERR_CRYPTO_HASH_FINALIZED(); outputEncoding = outputEncoding || getDefaultEncoding(); if (normalizeEncoding(outputEncoding) === 'utf16le') - throw new errors.Error('ERR_CRYPTO_HASH_DIGEST_NO_UTF16'); + throw new ERR_CRYPTO_HASH_DIGEST_NO_UTF16(); // Explicit conversion for backward compatibility. const ret = this._handle.digest(`${outputEncoding}`); @@ -79,10 +84,9 @@ function Hmac(hmac, key, options) { if (!(this instanceof Hmac)) return new Hmac(hmac, key, options); if (typeof hmac !== 'string') - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'hmac', 'string'); + throw new ERR_INVALID_ARG_TYPE('hmac', 'string'); if (typeof key !== 'string' && !isArrayBufferView(key)) { - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'key', - ['string', 'TypedArray', 'DataView']); + throw new ERR_INVALID_ARG_TYPE('key', ['string', 'TypedArray', 'DataView']); } this._handle = new _Hmac(); this._handle.init(hmac, toBuf(key)); @@ -100,7 +104,7 @@ Hmac.prototype.digest = function digest(outputEncoding) { const state = this[kState]; outputEncoding = outputEncoding || getDefaultEncoding(); if (normalizeEncoding(outputEncoding) === 'utf16le') - throw new errors.Error('ERR_CRYPTO_HASH_DIGEST_NO_UTF16'); + throw new ERR_CRYPTO_HASH_DIGEST_NO_UTF16(); if (state[kFinalized]) { const buf = Buffer.from(''); |