Skip to content

Commit ea00ba6

Browse files
committed
fix(hashes): change default hashAlgorithm to sha512
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.
1 parent aa03088 commit ea00ba6

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

lib/content/read.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function readStream (cache, address, opts) {
1414
opts = opts || {}
1515
const stream = checksumStream({
1616
digest: address,
17-
algorithm: opts.hashAlgorithm || 'sha1'
17+
algorithm: opts.hashAlgorithm || 'sha512'
1818
})
1919
const cpath = contentPath(cache, address)
2020
hasContent(cache, address).then(exists => {

lib/verify.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function garbageCollect (cache, opts) {
113113
return Promise.reduce(files, (stats, f) => {
114114
var fullPath = path.join(contentDir, f)
115115
if (byDigest[f]) {
116-
var algo = opts.hashAlgorithm || 'sha1'
116+
var algo = opts.hashAlgorithm || 'sha512'
117117
return verifyContent(fullPath, algo).then(info => {
118118
if (!info.valid) {
119119
stats.collectedCount++

test/content.read.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const read = require('../lib/content/read')
1515

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

3636
test('readStream: allows hashAlgorithm configuration', function (t) {
3737
const CONTENT = 'foobarbaz'
38-
const HASH = 'sha512'
38+
const HASH = 'whirlpool'
3939
const DIGEST = crypto.createHash(HASH).update(CONTENT).digest('hex')
4040
const dir = {}
4141
dir[DIGEST] = File(CONTENT)

0 commit comments

Comments
 (0)