@@ -83,15 +83,19 @@ function createCipherBase(cipher, credential, options, decipher, iv) { |
83 | 83 | LazyTransform.call(this, options); |
84 | 84 | } |
85 | 85 |
|
| 86 | +function invalidArrayBufferView(name, value) { |
| 87 | + return new ERR_INVALID_ARG_TYPE( |
| 88 | + name, |
| 89 | + ['string', 'Buffer', 'TypedArray', 'DataView'], |
| 90 | + value |
| 91 | + ); |
| 92 | +} |
| 93 | + |
86 | 94 | function createCipher(cipher, password, options, decipher) { |
87 | 95 | validateString(cipher, 'cipher'); |
88 | 96 | password = toBuf(password); |
89 | 97 | if (!isArrayBufferView(password)) { |
90 | | - throw new ERR_INVALID_ARG_TYPE( |
91 | | - 'password', |
92 | | - ['string', 'Buffer', 'TypedArray', 'DataView'], |
93 | | - password |
94 | | - ); |
| 98 | + throw invalidArrayBufferView('password', password); |
95 | 99 | } |
96 | 100 |
|
97 | 101 | createCipherBase.call(this, cipher, password, options, decipher); |
@@ -101,20 +105,12 @@ function createCipherWithIV(cipher, key, options, decipher, iv) { |
101 | 105 | validateString(cipher, 'cipher'); |
102 | 106 | key = toBuf(key); |
103 | 107 | if (!isArrayBufferView(key)) { |
104 | | - throw new ERR_INVALID_ARG_TYPE( |
105 | | - 'key', |
106 | | - ['string', 'Buffer', 'TypedArray', 'DataView'], |
107 | | - key |
108 | | - ); |
| 108 | + throw invalidArrayBufferView('key', key); |
109 | 109 | } |
110 | 110 |
|
111 | 111 | iv = toBuf(iv); |
112 | 112 | if (iv !== null && !isArrayBufferView(iv)) { |
113 | | - throw new ERR_INVALID_ARG_TYPE( |
114 | | - 'iv', |
115 | | - ['string', 'Buffer', 'TypedArray', 'DataView'], |
116 | | - iv |
117 | | - ); |
| 113 | + throw invalidArrayBufferView('iv', iv); |
118 | 114 | } |
119 | 115 | createCipherBase.call(this, cipher, key, options, decipher, iv); |
120 | 116 | } |
@@ -149,11 +145,7 @@ Cipher.prototype.update = function update(data, inputEncoding, outputEncoding) { |
149 | 145 | outputEncoding = outputEncoding || encoding; |
150 | 146 |
|
151 | 147 | if (typeof data !== 'string' && !isArrayBufferView(data)) { |
152 | | - throw new ERR_INVALID_ARG_TYPE( |
153 | | - 'data', |
154 | | - ['string', 'Buffer', 'TypedArray', 'DataView'], |
155 | | - data |
156 | | - ); |
| 148 | + throw invalidArrayBufferView('data', data); |
157 | 149 | } |
158 | 150 |
|
159 | 151 | const ret = this._handle.update(data, inputEncoding); |
|