Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Commit

Permalink
fix(hashes): change default hashAlgorithm to sha512
Browse files Browse the repository at this point in the history
sha512 is notably faster than sha256 on 64-bit systems, and sha1
was recently proven to be borked.

Fixes: #44

BREAKING CHANGE:
Default hashAlgorithm changed from sha1 to sha512. If you
rely on the prior setting, pass `opts.hashAlgorithm` in explicitly.
  • Loading branch information
zkat committed Mar 2, 2017
1 parent aa03088 commit ea00ba6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/content/read.js
Expand Up @@ -14,7 +14,7 @@ function readStream (cache, address, opts) {
opts = opts || {}
const stream = checksumStream({
digest: address,
algorithm: opts.hashAlgorithm || 'sha1'
algorithm: opts.hashAlgorithm || 'sha512'
})
const cpath = contentPath(cache, address)
hasContent(cache, address).then(exists => {
Expand Down
2 changes: 1 addition & 1 deletion lib/verify.js
Expand Up @@ -113,7 +113,7 @@ function garbageCollect (cache, opts) {
return Promise.reduce(files, (stats, f) => {
var fullPath = path.join(contentDir, f)
if (byDigest[f]) {
var algo = opts.hashAlgorithm || 'sha1'
var algo = opts.hashAlgorithm || 'sha512'
return verifyContent(fullPath, algo).then(info => {
if (!info.valid) {
stats.collectedCount++
Expand Down
4 changes: 2 additions & 2 deletions test/content.read.js
Expand Up @@ -15,7 +15,7 @@ const read = require('../lib/content/read')

test('readStream: returns a stream with cache content data', function (t) {
const CONTENT = 'foobarbaz'
const DIGEST = crypto.createHash('sha1').update(CONTENT).digest('hex')
const DIGEST = crypto.createHash('sha512').update(CONTENT).digest('hex')
const dir = {}
dir[DIGEST] = File(CONTENT)
const fixture = new Tacks(Dir({
Expand All @@ -35,7 +35,7 @@ test('readStream: returns a stream with cache content data', function (t) {

test('readStream: allows hashAlgorithm configuration', function (t) {
const CONTENT = 'foobarbaz'
const HASH = 'sha512'
const HASH = 'whirlpool'
const DIGEST = crypto.createHash(HASH).update(CONTENT).digest('hex')
const dir = {}
dir[DIGEST] = File(CONTENT)
Expand Down

0 comments on commit ea00ba6

Please sign in to comment.