Skip to content

Commit

Permalink
fix: verify/decrypt without a footer
Browse files Browse the repository at this point in the history
closes #33
  • Loading branch information
panva committed Sep 12, 2022
1 parent 09f0900 commit 0d8be5e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/help/consume.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function post(version, buffer, options, complete, m, f, purpose) {
throw new TypeError('options cannot contain claims when options.buffer is true')
}
if (complete) {
return { payload: m, footer: f.length ? f : undefined, version, purpose }
return { payload: m, footer: f?.length ? f : undefined, version, purpose }
}

return m
Expand All @@ -44,7 +44,7 @@ function post(version, buffer, options, complete, m, f, purpose) {
assertPayload(options, payload)

if (complete) {
return { payload, footer: f.length ? f : undefined, version, purpose }
return { payload, footer: f?.length ? f : undefined, version, purpose }
}

return payload
Expand Down
13 changes: 13 additions & 0 deletions test/issue-33.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = require('ava')

const {
V4: { sign, verify, generateKey },
} = require('../lib')

test('https://github.com/panva/paseto/issues/33', async (t) => {
await t.notThrowsAsync(async () => {
const key = await generateKey('public', { format: 'paserk' })
const token = await sign({}, key.secretKey)
await verify(token, key.publicKey, { complete: true })
})
})

0 comments on commit 0d8be5e

Please sign in to comment.