This repository has been archived by the owner on Aug 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
139 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
'use strict' | ||
const crypto = require('crypto') | ||
|
||
module.exports = (algorithm) => (data) => { | ||
return new Promise((resolve, reject) => { | ||
try { | ||
switch (algorithm) { | ||
case 'sha1': | ||
return resolve(crypto.createHash('sha1').update(data).digest()) | ||
case 'sha2-256': | ||
return resolve(crypto.createHash('sha256').update(data).digest()) | ||
case 'sha2-512': | ||
return resolve(crypto.createHash('sha512').update(data).digest()) | ||
case 'dbl-sha2-256': { | ||
const first = crypto.createHash('sha256').update(data).digest() | ||
return resolve(crypto.createHash('sha256').update(first).digest()) | ||
} | ||
default: | ||
throw new TypeError(`${algorithm} is not a supported algorithm`) | ||
} | ||
} catch (error) { | ||
return reject(error) | ||
// Note that although this function doesn't do any asynchronous work, we mark | ||
// the function as async because it must return a Promise to match the API | ||
// for other functions that do perform asynchronous work (see sha.browser.js) | ||
module.exports = (algorithm) => async (data) => { | ||
switch (algorithm) { | ||
case 'sha1': | ||
return crypto.createHash('sha1').update(data).digest() | ||
case 'sha2-256': | ||
return crypto.createHash('sha256').update(data).digest() | ||
case 'sha2-512': | ||
return crypto.createHash('sha512').update(data).digest() | ||
case 'dbl-sha2-256': { | ||
const first = crypto.createHash('sha256').update(data).digest() | ||
return crypto.createHash('sha256').update(first).digest() | ||
} | ||
}) | ||
default: | ||
throw new TypeError(`${algorithm} is not a supported algorithm`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters