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