Skip to content

Commit

Permalink
Avoid decoding empty buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Jun 10, 2018
1 parent 9046264 commit 8c28fcf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ describe('keysign', () => {
expect(result).toEqual(undefined)
})

it('should fail to decode empty buffer', () => {
const result = keysign.decode(Buffer.alloc(0))

expect(result).toEqual(undefined)
})

it('should verify the hmac is correct', () => {
const signed = keysign.encode(Buffer.from('example', 'utf8'))

Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export class Keysign {
}

decode (data: Buffer): Buffer | undefined {
if (!data.length) return undefined

const index = data.readUInt8(0)
const algorithm = ALGORITHMS[index]

Expand Down

0 comments on commit 8c28fcf

Please sign in to comment.