You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
12 lines
416 B
12 lines
416 B
var createHash = require('crypto').createHash
|
|
var stringify = require('fast-safe-stringify')
|
|
|
|
module.exports = function shasum (input, hash, digest) {
|
|
if (!hash) hash = 'sha1'
|
|
if (!digest) digest = 'hex'
|
|
if (typeof input !== 'string' && !Buffer.isBuffer(input)) input = stringify.stable(input)
|
|
|
|
return createHash(hash)
|
|
.update(input, typeof input === 'string' ? 'utf8' : undefined)
|
|
.digest(digest)
|
|
}
|