-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
hash.spec.js
39 lines (32 loc) · 900 Bytes
/
hash.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
require('chai').should();
const crypto = require('crypto');
function sha1(content) {
const hash = crypto.createHash('sha1');
hash.update(content);
return hash.digest();
}
describe('hash', () => {
const hash = require('../lib/hash');
it('hash', () => {
const content = '123456';
hash.hash(content).should.eql(sha1(content));
});
it('createSha1Hash', () => {
const _sha1 = hash.createSha1Hash();
const content = '123456';
_sha1.update(content);
_sha1.digest().should.eql(sha1(content));
});
it('createSha1Hash - streamMode', () => {
const content1 = '123456';
const content2 = '654321';
const stream = hash.createSha1Hash();
// explicit convert
stream.write(Buffer.from(content1));
// implicit convert
stream.write(content2);
stream.end();
stream.read().should.eql(sha1(content1 + content2));
});
});