Skip to content

Commit

Permalink
switch to safe-buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmetcalf committed Aug 9, 2018
1 parent d1088bf commit bc593db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@
"timing-safe-equal": "^1.0.0"
},
"devDependencies": {
"buffer-shims": "^1.0.0",
"hash-test-vectors": "~1.3.2",
"pseudorandombytes": "^2.0.0",
<<<<<<< HEAD
"safe-buffer": "^5.1.1",
=======
"safe-buffer": "^5.1.2",
>>>>>>> switch to safe-buffer
"standard": "^5.0.2",
"tape": "~2.3.2",
"zuul": "^3.6.0"
Expand Down
12 changes: 6 additions & 6 deletions test/timing-safe-equal.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
var test = require('tape')
var timingSafeEqual = require('timing-safe-equal/browser')
var bufferShims = require('buffer-shims')
var Buffer = require('safe-buffer').Buffer
test('timingSafeEqual', function (t) {
t.plan(5)
t.strictEqual(
timingSafeEqual(bufferShims.from('foo'), bufferShims.from('foo')),
timingSafeEqual(Buffer.from('foo'), Buffer.from('foo')),
true,
'should consider equal strings to be equal'
)

t.strictEqual(
timingSafeEqual(bufferShims.from('foo'), bufferShims.from('bar')),
timingSafeEqual(Buffer.from('foo'), Buffer.from('bar')),
false,
'should consider unequal strings to be unequal'
)

t.throws(function () {
timingSafeEqual(bufferShims.from([1, 2, 3]), bufferShims.from([1, 2]))
timingSafeEqual(Buffer.from([1, 2, 3]), Buffer.from([1, 2]))
}, 'should throw when given buffers with different lengths')

t.throws(function () {
timingSafeEqual('not a buffer', bufferShims.from([1, 2]))
timingSafeEqual('not a buffer', Buffer.from([1, 2]))
}, 'should throw if the first argument is not a buffer')

t.throws(function () {
timingSafeEqual(bufferShims.from([1, 2]), 'not a buffer')
timingSafeEqual(Buffer.from([1, 2]), 'not a buffer')
}, 'should throw if the second argument is not a buffer')
})

0 comments on commit bc593db

Please sign in to comment.