diff options
Diffstat (limited to 'lib/internal/crypto/cipher.js')
-rw-r--r-- | lib/internal/crypto/cipher.js | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/lib/internal/crypto/cipher.js b/lib/internal/crypto/cipher.js index 48c5ba23c7..4eb1aee69c 100644 --- a/lib/internal/crypto/cipher.js +++ b/lib/internal/crypto/cipher.js @@ -22,7 +22,7 @@ const { const { getDefaultEncoding, kHandle, - toBuf + getArrayBufferView } = require('internal/crypto/util'); const { isArrayBufferView } = require('internal/util/types'); @@ -105,20 +105,9 @@ function createCipherBase(cipher, credential, options, decipher, iv) { LazyTransform.call(this, options); } -function invalidArrayBufferView(name, value) { - return new ERR_INVALID_ARG_TYPE( - name, - ['string', 'Buffer', 'TypedArray', 'DataView'], - value - ); -} - function createCipher(cipher, password, options, decipher) { validateString(cipher, 'cipher'); - password = toBuf(password); - if (!isArrayBufferView(password)) { - throw invalidArrayBufferView('password', password); - } + password = getArrayBufferView(password, 'password'); createCipherBase.call(this, cipher, password, options, decipher); } @@ -126,10 +115,7 @@ function createCipher(cipher, password, options, decipher) { function createCipherWithIV(cipher, key, options, decipher, iv) { validateString(cipher, 'cipher'); key = prepareSecretKey(key); - iv = toBuf(iv); - if (iv !== null && !isArrayBufferView(iv)) { - throw invalidArrayBufferView('iv', iv); - } + iv = iv === null ? null : getArrayBufferView(iv, 'iv'); createCipherBase.call(this, cipher, key, options, decipher, iv); } @@ -164,7 +150,8 @@ Cipher.prototype.update = function update(data, inputEncoding, outputEncoding) { outputEncoding = outputEncoding || encoding; if (typeof data !== 'string' && !isArrayBufferView(data)) { - throw invalidArrayBufferView('data', data); + throw new ERR_INVALID_ARG_TYPE( + 'data', ['string', 'Buffer', 'TypedArray', 'DataView'], data); } validateEncoding(data, inputEncoding); |