Skip to content

Commit

Permalink
test(crypto): test timingSafeEqual() in handling DataViews (#5268)
Browse files Browse the repository at this point in the history
  • Loading branch information
iuioiua authored Jul 3, 2024
1 parent c9a4eff commit 735609e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions crypto/timing_safe_equal_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,33 @@ Deno.test({
assert(!timingSafeEqual(ua, ub));
},
});

Deno.test({
name: "timingSafeEqual() compares equal DataViews",
fn() {
const a = new ArrayBuffer(2);
const va = new DataView(a);
va.setUint8(0, 212);
va.setUint8(1, 213);
const b = new ArrayBuffer(2);
const vb = new DataView(b);
vb.setUint8(0, 212);
vb.setUint8(1, 213);
assert(timingSafeEqual(va, vb));
},
});

Deno.test({
name: "timingSafeEqual() compares unequal DataViews",
fn() {
const a = new ArrayBuffer(2);
const va = new DataView(a);
va.setUint8(0, 212);
va.setUint8(1, 213);
const b = new ArrayBuffer(2);
const vb = new DataView(b);
vb.setUint8(0, 212);
vb.setUint8(1, 212);
assert(!timingSafeEqual(va, vb));
},
});

0 comments on commit 735609e

Please sign in to comment.