Skip to content
Permalink
Browse files

Merge pull request #7 from billinghamj/patch-1

Fix native Buffer allocation
  • Loading branch information...
Bruce17 committed Feb 11, 2018
2 parents 19c8469 + 9e416b3 commit ba88084d0cdc6a8834616acce086225e5a336d3f
Showing with 7 additions and 3 deletions.
  1. +3 −3 index.js
  2. +4 −0 test/test.js
@@ -51,10 +51,10 @@ var nativeTimingSafeEqual = function nativeTimingSafeEqual(a, b) {
var strA = String(a);
var strB = String(b);

var len = Math.max(strA.length, strB.length);
var len = Math.max(Buffer.byteLength(strA), Buffer.byteLength(strB));

var bufA = bufferAlloc(len, strA, 'binary');
var bufB = bufferAlloc(len, strB, 'binary');
var bufA = bufferAlloc(len, strA, 'utf8');
var bufB = bufferAlloc(len, strB, 'utf8');

return crypto.timingSafeEqual(bufA, bufB);
};
@@ -36,6 +36,10 @@ describe('safe compare', function () {
it('"สวัสดีชาวโลก" against "สวัสดี"', function () {
assert.equal(false, safeCompare('สวัสดีชาวโลก', 'สวัสดี'));
});

it('"\\u00e8" against "\\u01e8"', function () {
assert.equal(false, safeCompare('\u00e8', '\u01e8'));
});
});

describe('should not throw an error for non string argument', function () {

0 comments on commit ba88084

Please sign in to comment.
You can’t perform that action at this time.