Skip to content

Commit

Permalink
use buffer shims
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmetcalf committed Sep 16, 2016
1 parent 7e87fc7 commit e7b2455
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"timing-safe-equal": "^1.0.0"
},
"devDependencies": {
"buffer-shims": "^1.0.0",
"hash-test-vectors": "~1.3.2",
"pseudorandombytes": "^2.0.0",
"standard": "^5.0.2",
Expand Down
11 changes: 6 additions & 5 deletions test/timing-safe-equal.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
var test = require('tape')
var timingSafeEqual = require('timing-safe-equal/browser')
var bufferShims = require('buffer-shims')
test('timingSafeEqual', function (t) {
t.plan(5)
t.strictEqual(
timingSafeEqual(Buffer.from('foo'), Buffer.from('foo')),
timingSafeEqual(bufferShims.from('foo'), bufferShims.from('foo')),
true,
'should consider equal strings to be equal'
)

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

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

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

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

0 comments on commit e7b2455

Please sign in to comment.