(a: string, b: string)
| 11 | } |
| 12 | |
| 13 | export function secureCompare(a: string, b: string): boolean { |
| 14 | if ( |
| 15 | typeof a !== 'string' || |
| 16 | typeof b !== 'string' || |
| 17 | !a || |
| 18 | !b || |
| 19 | a.length !== b.length |
| 20 | ) |
| 21 | return false; |
| 22 | |
| 23 | const buffer1 = Buffer.from(a); |
| 24 | const buffer2 = Buffer.from(b); |
| 25 | try { |
| 26 | return timingSafeEqual(buffer1, buffer2); |
| 27 | } catch (exception) { |
| 28 | return false; |
| 29 | } |
| 30 | } |
no outgoing calls
no test coverage detected