Skip to content

Commit

Permalink
fix: prevent DEFAULT_ALGORITHM mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Apr 11, 2023
1 parent 4e94d15 commit d90f674
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/index.js
Expand Up @@ -34,7 +34,7 @@ class IntegrityStream extends MiniPass {
new Set(opts.algorithms.concat(this.algorithm ? [this.algorithm] : []))
)
} else {
this.algorithms = DEFAULT_ALGORITHMS
this.algorithms = [...DEFAULT_ALGORITHMS]

if (this.algorithm !== null && this.algorithm !== DEFAULT_ALGORITHMS[0]) {
this.algorithms.push(this.algorithm)
Expand Down Expand Up @@ -416,7 +416,7 @@ function fromHex (hexDigest, algorithm, opts) {

module.exports.fromData = fromData
function fromData (data, opts) {
const algorithms = opts?.algorithms || DEFAULT_ALGORITHMS
const algorithms = opts?.algorithms || [...DEFAULT_ALGORITHMS]
const optString = getOptString(opts?.options)
return algorithms.reduce((acc, algo) => {
const digest = crypto.createHash(algo).update(data).digest('base64')
Expand Down Expand Up @@ -528,7 +528,7 @@ function integrityStream (opts = Object.create(null)) {

module.exports.create = createIntegrity
function createIntegrity (opts) {
const algorithms = opts?.algorithms || DEFAULT_ALGORITHMS
const algorithms = opts?.algorithms || [...DEFAULT_ALGORITHMS]
const optString = getOptString(opts?.options)

const hashes = algorithms.map(crypto.createHash)
Expand Down

0 comments on commit d90f674

Please sign in to comment.