Skip to content

Commit

Permalink
fix(checkStream): integrityStream now takes opts.integrity algos into…
Browse files Browse the repository at this point in the history
… account
  • Loading branch information
zkat committed Jan 18, 2018
1 parent d0343e0 commit d262910
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ function integrityStream (opts) {
const algorithm = goodSri && sri.pickAlgorithm(opts)
const digests = goodSri && sri[algorithm]
// Calculating stream
const algorithms = opts.algorithms || [algorithm || 'sha512']
const algorithms = (opts.algorithms || ['sha512'])
.concat(algorithm ? [algorithm] : [])
const hashes = algorithms.map(crypto.createHash)
let streamSize = 0
const stream = new Transform({
Expand Down
30 changes: 30 additions & 0 deletions test/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,36 @@ test('checkStream', t => {
})['sha384'][0],
'picks the "strongest" available algorithm, by default'
)
return ssri.checkStream(fileStream(), [
`sha1-${hash(TEST_DATA, 'sha1')}`,
`sha384-${hash(TEST_DATA, 'sha384')}`,
`sha256-${hash(TEST_DATA, 'sha256')}`
].join(' '), {
algorithms: ['sha256']
})
}).then(res => {
t.deepEqual(
res,
ssri.parse({
algorithm: 'sha384', digest: hash(TEST_DATA, 'sha384')
})['sha384'][0],
'opts.algorithm still takes into account algo to check against'
)
return ssri.checkStream(fileStream(), [
`sha1-${hash(TEST_DATA, 'sha1')}`,
`sha384-${hash(TEST_DATA, 'sha384')}`,
`sha256-${hash(TEST_DATA, 'sha256')}`
].join(' '), {
algorithms: ['sha512']
})
}).then(res => {
t.deepEqual(
res,
ssri.parse({
algorithm: 'sha384', digest: hash(TEST_DATA, 'sha384')
})['sha384'][0],
'...even if opts.algorithms includes a hash that is not present'
)
return ssri.checkStream(
fileStream(), `sha256-${hash(TEST_DATA, 'sha256')}`, {
size: TEST_DATA.length - 1
Expand Down

0 comments on commit d262910

Please sign in to comment.