@@ -22,7 +22,7 @@ const {
2222const {
2323 getDefaultEncoding,
2424 kHandle,
25- toBuf
25+ getArrayBufferView
2626} = require ( 'internal/crypto/util' ) ;
2727
2828const { isArrayBufferView } = require ( 'internal/util/types' ) ;
@@ -105,31 +105,17 @@ function createCipherBase(cipher, credential, options, decipher, iv) {
105105 LazyTransform . call ( this , options ) ;
106106}
107107
108- function invalidArrayBufferView ( name , value ) {
109- return new ERR_INVALID_ARG_TYPE (
110- name ,
111- [ 'string' , 'Buffer' , 'TypedArray' , 'DataView' ] ,
112- value
113- ) ;
114- }
115-
116108function createCipher ( cipher , password , options , decipher ) {
117109 validateString ( cipher , 'cipher' ) ;
118- password = toBuf ( password ) ;
119- if ( ! isArrayBufferView ( password ) ) {
120- throw invalidArrayBufferView ( 'password' , password ) ;
121- }
110+ password = getArrayBufferView ( password , 'password' ) ;
122111
123112 createCipherBase . call ( this , cipher , password , options , decipher ) ;
124113}
125114
126115function createCipherWithIV ( cipher , key , options , decipher , iv ) {
127116 validateString ( cipher , 'cipher' ) ;
128117 key = prepareSecretKey ( key ) ;
129- iv = toBuf ( iv ) ;
130- if ( iv !== null && ! isArrayBufferView ( iv ) ) {
131- throw invalidArrayBufferView ( 'iv' , iv ) ;
132- }
118+ iv = iv === null ? null : getArrayBufferView ( iv , 'iv' ) ;
133119 createCipherBase . call ( this , cipher , key , options , decipher , iv ) ;
134120}
135121
@@ -164,7 +150,8 @@ Cipher.prototype.update = function update(data, inputEncoding, outputEncoding) {
164150 outputEncoding = outputEncoding || encoding ;
165151
166152 if ( typeof data !== 'string' && ! isArrayBufferView ( data ) ) {
167- throw invalidArrayBufferView ( 'data' , data ) ;
153+ throw new ERR_INVALID_ARG_TYPE (
154+ 'data' , [ 'string' , 'Buffer' , 'TypedArray' , 'DataView' ] , data ) ;
168155 }
169156
170157 const ret = this [ kHandle ] . update ( data , inputEncoding ) ;
0 commit comments