1 | "use strict";
|
2 |
|
3 | const crypto = require('crypto');
|
4 |
|
5 | function createHash(algos) {
|
6 | if(!Array.isArray(algos))
|
7 | algos = [algos];
|
8 |
|
9 | let hashes = algos.reduce((acc, algo) => ({
|
10 | ...acc,
|
11 | [algo] : crypto.createHash(algo)
|
12 | }), {});
|
13 |
|
14 | function update(data) {
|
15 | for(let algo of algos)
|
16 | hashes[algo].update(data);
|
17 | }
|
18 |
|
19 | function digest(encode) {
|
20 | for(let algo of algos)
|
21 | hashes[algo] = hashes[algo].digest(encode);
|
22 | return hashes;
|
23 | }
|
24 |
|
25 | return {update, digest};
|
26 | }
|
27 |
|
28 | module.exports = createHash;
|