Skip to content

Commit 6ea0b6c

Browse files
itsuki-hayashixingoxu
authored andcommitted
Remove polyfills for Node.js 6 (#149)
1 parent c5086af commit 6ea0b6c

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

lib/validate-signature.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,21 @@
11
import { createHmac, timingSafeEqual } from "crypto";
22

33
function s2b(str: string, encoding: string): Buffer {
4-
if (Buffer.from) {
5-
try {
6-
return Buffer.from(str, encoding);
7-
} catch (err) {
8-
if (err.name === "TypeError") {
9-
return new Buffer(str, encoding);
10-
}
11-
throw err;
4+
try {
5+
return Buffer.from(str, encoding);
6+
} catch (err) {
7+
if (err.name === "TypeError") {
8+
return new Buffer(str, encoding);
129
}
13-
} else {
14-
return new Buffer(str, encoding);
10+
throw err;
1511
}
1612
}
1713

1814
function safeCompare(a: Buffer, b: Buffer): boolean {
1915
if (a.length !== b.length) {
2016
return false;
2117
}
22-
23-
if (timingSafeEqual) {
24-
return timingSafeEqual(a, b);
25-
} else {
26-
let result = 0;
27-
for (let i = 0; i < a.length; i++) {
28-
result |= a[i] ^ b[i];
29-
}
30-
return result === 0;
31-
}
18+
return timingSafeEqual(a, b);
3219
}
3320

3421
export default function validateSignature(

0 commit comments

Comments
 (0)