@@ -167,42 +167,66 @@ testImmutability(crypto.getCurves);
167167
168168// Regression tests for https://github.com/nodejs/node-v0.x-archive/pull/5725:
169169// hex input that's not a power of two should throw, not assert in C++ land.
170- assert . throws ( function ( ) {
171- crypto . createCipher ( 'aes192' , 'test' ) . update ( '0' , 'hex' ) ;
172- } , ( err ) => {
173- const errorMessage =
174- common . hasFipsCrypto ? / n o t s u p p o r t e d i n F I P S m o d e / : / B a d i n p u t s t r i n g / ;
175- // Throws general Error, so there is no opensslErrorStack property.
176- if ( ( err instanceof Error ) &&
177- errorMessage . test ( err ) &&
178- err . opensslErrorStack === undefined ) {
179- return true ;
180- }
181- } ) ;
182170
183- assert . throws ( function ( ) {
184- crypto . createDecipher ( 'aes192' , 'test' ) . update ( '0' , 'hex' ) ;
185- } , ( err ) => {
186- const errorMessage =
187- common . hasFipsCrypto ? / n o t s u p p o r t e d i n F I P S m o d e / : / B a d i n p u t s t r i n g / ;
188- // Throws general Error, so there is no opensslErrorStack property.
189- if ( ( err instanceof Error ) &&
190- errorMessage . test ( err ) &&
191- err . opensslErrorStack === undefined ) {
192- return true ;
171+ common . expectsError (
172+ ( ) => crypto . createCipher ( 'aes192' , 'test' ) . update ( '0' , 'hex' ) ,
173+ Object . assign (
174+ common . hasFipsCrypto ?
175+ {
176+ code : undefined ,
177+ type : Error ,
178+ message : / n o t s u p p o r t e d i n F I P S m o d e / ,
179+ } :
180+ {
181+ code : 'ERR_INVALID_ARG_VALUE' ,
182+ type : TypeError ,
183+ message : "The argument 'encoding' is invalid for data of length 1." +
184+ " Received 'hex'" ,
185+ } ,
186+ { opensslErrorStack : undefined }
187+ )
188+ ) ;
189+
190+ common . expectsError (
191+ ( ) => crypto . createDecipher ( 'aes192' , 'test' ) . update ( '0' , 'hex' ) ,
192+ Object . assign (
193+ common . hasFipsCrypto ?
194+ {
195+ code : undefined ,
196+ type : Error ,
197+ message : / n o t s u p p o r t e d i n F I P S m o d e / ,
198+ } :
199+ {
200+ code : 'ERR_INVALID_ARG_VALUE' ,
201+ type : TypeError ,
202+ message : "The argument 'encoding' is invalid for data of length 1." +
203+ " Received 'hex'" ,
204+ } ,
205+ { opensslErrorStack : undefined }
206+ )
207+ ) ;
208+
209+ common . expectsError (
210+ ( ) => crypto . createHash ( 'sha1' ) . update ( '0' , 'hex' ) ,
211+ {
212+ code : 'ERR_INVALID_ARG_VALUE' ,
213+ type : TypeError ,
214+ message : "The argument 'encoding' is invalid for data of length 1." +
215+ " Received 'hex'" ,
216+ opensslErrorStack : undefined
193217 }
194- } ) ;
218+ ) ;
195219
196- assert . throws ( function ( ) {
197- crypto . createHash ( 'sha1' ) . update ( '0' , 'hex' ) ;
198- } , ( err ) => {
199- // Throws TypeError, so there is no opensslErrorStack property.
200- if ( ( err instanceof Error ) &&
201- / ^ T y p e E r r o r : B a d i n p u t s t r i n g $ / . test ( err ) &&
202- err . opensslErrorStack === undefined ) {
203- return true ;
220+ common . expectsError (
221+ ( ) => crypto . createHmac ( 'sha256' , 'a secret' ) . update ( '0' , 'hex' ) ,
222+ {
223+ code : 'ERR_INVALID_ARG_VALUE' ,
224+ type : TypeError ,
225+ message : "The argument 'encoding' is invalid for data of length 1." +
226+ " Received 'hex'" ,
227+ opensslErrorStack : undefined
204228 }
205- } ) ;
229+ ) ;
206230
207231assert . throws ( function ( ) {
208232 const priv = [
0 commit comments