Skip to content

Commit

Permalink
fix: properly validate hmac strings
Browse files Browse the repository at this point in the history
  • Loading branch information
frytg committed Dec 17, 2024
1 parent 7268e4a commit 74a7ed0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crypto/hmac-buffer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ test('bufferFromHex - converts hex strings to Buffer correctly', () => {
}
})

test('bufferFromHex - validates hex strings correctly', () => {
test('bufferFromHex - validates valid hex strings correctly', () => {
// Valid hex strings should work
const validHexes = ['0123456789abcdef', 'ABCDEF', '', '00', 'ff', 'deadbeef']

for (const hex of validHexes) {
assertEquals(typeof bufferFromHex(hex), 'object', `bufferFromHex should accept valid hex string "${hex}"`)
}
})

test('bufferFromHex - validates invalid hex strings correctly', () => {
// Invalid hex strings should throw
const invalidHexes = [
'0123456789abcdefg', // invalid hex char
Expand Down
1 change: 1 addition & 0 deletions crypto/hmac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

// load packages
// deno-fmt-ignore
import { Buffer, atob } from 'node:buffer'
import { createHmac } from 'node:crypto'

Expand Down

0 comments on commit 74a7ed0

Please sign in to comment.