@@ -22,7 +22,7 @@ const {
22
22
const {
23
23
getDefaultEncoding,
24
24
kHandle,
25
- toBuf
25
+ getArrayBufferView
26
26
} = require ( 'internal/crypto/util' ) ;
27
27
28
28
const { isArrayBufferView } = require ( 'internal/util/types' ) ;
@@ -105,31 +105,17 @@ function createCipherBase(cipher, credential, options, decipher, iv) {
105
105
LazyTransform . call ( this , options ) ;
106
106
}
107
107
108
- function invalidArrayBufferView ( name , value ) {
109
- return new ERR_INVALID_ARG_TYPE (
110
- name ,
111
- [ 'string' , 'Buffer' , 'TypedArray' , 'DataView' ] ,
112
- value
113
- ) ;
114
- }
115
-
116
108
function createCipher ( cipher , password , options , decipher ) {
117
109
validateString ( cipher , 'cipher' ) ;
118
- password = toBuf ( password ) ;
119
- if ( ! isArrayBufferView ( password ) ) {
120
- throw invalidArrayBufferView ( 'password' , password ) ;
121
- }
110
+ password = getArrayBufferView ( password , 'password' ) ;
122
111
123
112
createCipherBase . call ( this , cipher , password , options , decipher ) ;
124
113
}
125
114
126
115
function createCipherWithIV ( cipher , key , options , decipher , iv ) {
127
116
validateString ( cipher , 'cipher' ) ;
128
117
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' ) ;
133
119
createCipherBase . call ( this , cipher , key , options , decipher , iv ) ;
134
120
}
135
121
@@ -164,7 +150,8 @@ Cipher.prototype.update = function update(data, inputEncoding, outputEncoding) {
164
150
outputEncoding = outputEncoding || encoding ;
165
151
166
152
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 ) ;
168
155
}
169
156
170
157
const ret = this [ kHandle ] . update ( data , inputEncoding ) ;
0 commit comments