-
-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathtiming-safe-equal.js
More file actions
29 lines (25 loc) · 908 Bytes
/
timing-safe-equal.js
File metadata and controls
29 lines (25 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var test = require('tape')
var timingSafeEqual = require('timing-safe-equal/browser')
var Buffer = require('safe-buffer').Buffer
test('timingSafeEqual', function (t) {
t.plan(5)
t.strictEqual(
timingSafeEqual(Buffer.from('foo'), Buffer.from('foo')),
true,
'should consider equal strings to be equal'
)
t.strictEqual(
timingSafeEqual(Buffer.from('foo'), Buffer.from('bar')),
false,
'should consider unequal strings to be unequal'
)
t.throws(function () {
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', Buffer.from([1, 2]))
}, 'should throw if the first argument is not a buffer')
t.throws(function () {
timingSafeEqual(Buffer.from([1, 2]), 'not a buffer')
}, 'should throw if the second argument is not a buffer')
})