Skip to content

Commit d90f674

Browse files
committed
fix: prevent DEFAULT_ALGORITHM mutation
1 parent 4e94d15 commit d90f674

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class IntegrityStream extends MiniPass {
3434
new Set(opts.algorithms.concat(this.algorithm ? [this.algorithm] : []))
3535
)
3636
} else {
37-
this.algorithms = DEFAULT_ALGORITHMS
37+
this.algorithms = [...DEFAULT_ALGORITHMS]
3838

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

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

529529
module.exports.create = createIntegrity
530530
function createIntegrity (opts) {
531-
const algorithms = opts?.algorithms || DEFAULT_ALGORITHMS
531+
const algorithms = opts?.algorithms || [...DEFAULT_ALGORITHMS]
532532
const optString = getOptString(opts?.options)
533533

534534
const hashes = algorithms.map(crypto.createHash)

0 commit comments

Comments
 (0)