(userInput, secret)
| 5 | // Credits for the actual algorithm go to github/@Bruce17 |
| 6 | // Thanks to github/@hraban for making me implement this |
| 7 | function safeCompare(userInput, secret) { |
| 8 | const userInputLength = Buffer.byteLength(userInput) |
| 9 | const secretLength = Buffer.byteLength(secret) |
| 10 | |
| 11 | const userInputBuffer = Buffer.alloc(userInputLength, 0, 'utf8') |
| 12 | userInputBuffer.write(userInput) |
| 13 | const secretBuffer = Buffer.alloc(userInputLength, 0, 'utf8') |
| 14 | secretBuffer.write(secret) |
| 15 | |
| 16 | return !!(timingSafeEqual(userInputBuffer, secretBuffer) & userInputLength === secretLength) |
| 17 | } |
| 18 | |
| 19 | function ensureFunction(option, defaultValue) { |
| 20 | if(option == undefined) |
no outgoing calls
no test coverage detected
searching dependent graphs…