@@ -9,6 +9,9 @@ const fs = require('fs');
9
9
10
10
const fixtures = require ( '../common/fixtures' ) ;
11
11
12
+ let cryptoType ;
13
+ let digest ;
14
+
12
15
// Test hashing
13
16
const a1 = crypto . createHash ( 'sha1' ) . update ( 'Test123' ) . digest ( 'hex' ) ;
14
17
const a2 = crypto . createHash ( 'sha256' ) . update ( 'Test123' ) . digest ( 'base64' ) ;
@@ -37,16 +40,29 @@ a8.end();
37
40
a8 = a8 . read ( ) ;
38
41
39
42
if ( ! common . hasFipsCrypto ) {
40
- const a0 = crypto . createHash ( 'md5' ) . update ( 'Test123' ) . digest ( 'latin1' ) ;
43
+ cryptoType = 'md5' ;
44
+ digest = 'latin1' ;
45
+ const a0 = crypto . createHash ( cryptoType ) . update ( 'Test123' ) . digest ( digest ) ;
41
46
assert . strictEqual (
42
47
a0 ,
43
48
'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca\u00bd\u008c' ,
44
- 'Test MD5 as latin1'
49
+ ` ${ cryptoType } with ${ digest } digest failed to evaluate to expected hash`
45
50
) ;
46
51
}
47
- assert . strictEqual ( a1 , '8308651804facb7b9af8ffc53a33a22d6a1c8ac2' , 'Test SHA1' ) ;
48
- assert . strictEqual ( a2 , '2bX1jws4GYKTlxhloUB09Z66PoJZW+y+hq5R8dnx9l4=' ,
49
- 'Test SHA256 as base64' ) ;
52
+ cryptoType = 'md5' ;
53
+ digest = 'hex' ;
54
+ assert . strictEqual (
55
+ a1 ,
56
+ '8308651804facb7b9af8ffc53a33a22d6a1c8ac2' ,
57
+ `${ cryptoType } with ${ digest } digest failed to evaluate to expected hash` ) ;
58
+ cryptoType = 'sha256' ;
59
+ digest = 'base64' ;
60
+ assert . strictEqual (
61
+ a2 ,
62
+ '2bX1jws4GYKTlxhloUB09Z66PoJZW+y+hq5R8dnx9l4=' ,
63
+ `${ cryptoType } with ${ digest } digest failed to evaluate to expected hash` ) ;
64
+ cryptoType = 'sha512' ;
65
+ digest = 'latin1' ;
50
66
assert . deepStrictEqual (
51
67
a3 ,
52
68
Buffer . from (
@@ -56,11 +72,13 @@ assert.deepStrictEqual(
56
72
'\u00d7\u00d6\u00a2\u00a8\u0085\u00e3<\u0083\u009c\u0093' +
57
73
'\u00c2\u0006\u00da0\u00a1\u00879(G\u00ed\'' ,
58
74
'latin1' ) ,
59
- 'Test SHA512 as assumed buffer' ) ;
75
+ `${ cryptoType } with ${ digest } digest failed to evaluate to expected hash` ) ;
76
+ cryptoType = 'sha1' ;
77
+ digest = 'hex' ;
60
78
assert . deepStrictEqual (
61
79
a4 ,
62
80
Buffer . from ( '8308651804facb7b9af8ffc53a33a22d6a1c8ac2' , 'hex' ) ,
63
- 'Test SHA1'
81
+ ` ${ cryptoType } with ${ digest } digest failed to evaluate to expected hash`
64
82
) ;
65
83
66
84
// stream interface should produce the same result.
0 commit comments