Skip to content

Commit

Permalink
fix(argon): #variants to rely on argon2 exports
Browse files Browse the repository at this point in the history
  • Loading branch information
austinfelipe committed Nov 13, 2024
1 parent 9463702 commit 8dd82f4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/drivers/argon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import type argon2 from 'argon2'
import { argon2i, argon2d, argon2id } from 'argon2'
import { safeEqual } from '@poppinss/utils'

import { PhcFormatter } from '../phc_formatter.js'
Expand Down Expand Up @@ -55,9 +56,9 @@ export class Argon implements HashDriverContract {
* Supported variants
*/
#variants: { [K in ArgonVariants]: 0 | 1 | 2 } = {
i: 0,
d: 1,
id: 2,
i: argon2i,
d: argon2d,
id: argon2id,
}

/**
Expand Down
40 changes: 37 additions & 3 deletions tests/drivers/argon2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ test.group('argon | verify', () => {
assert.isTrue(matches)
})

test('should verify a precomputed hash', async ({ assert }) => {
test('should verify a precomputed hash for variant id', async ({ assert }) => {
// Precomputed hash for "password"
const hash =
'$argon2id$v=19$m=4096,t=3,p=1$PcEZHj1maR/+ZQynyJHWZg$2jEN4xcww7CYp1jakZB1rxbYsZ55XH2HgjYRtdZtubI'
Expand All @@ -220,8 +220,42 @@ test.group('argon | verify', () => {
assert.isTrue(await argon.verify(hash, 'password'))
})

test('should verify a precomputed hash with old parameters order', async ({ assert }) => {
test('should verify a precomputed hash for variant i', async ({ assert }) => {
// Precomputed hash for "password"
const hash =
'$argon2i$v=19$m=4096,t=4,p=2$dHRHRnJrNXhMS3hGdXp2Sg$rjAqTHriWP3GhO5/ZYoxuKcXDks/02JLGld9uBTsUgc'

const argon = new Argon({
variant: 'i',
iterations: 4,
memory: 4096,
parallelism: 2,
version: 19,
saltSize: 16,
})

assert.isTrue(await argon.verify(hash, 'password'))
})

test('should verify a precomputed hash for variant d', async ({ assert }) => {
// Precomputed hash for "password"
const hash =
'$argon2d$v=19$m=4096,t=4,p=2$dHRHRnJrNXhMS3hGdXp2Sg$F4lQNEt3xXSCNwTOflBJPzSlNk9dN3h1+lizNakqEzs'

const argon = new Argon({
variant: 'd',
iterations: 4,
memory: 4096,
parallelism: 2,
version: 19,
saltSize: 16,
})

assert.isTrue(await argon.verify(hash, 'password'))
})

test('should verify a precomputed hash with old parameters order', async ({ assert }) => {
// Precomputed hash for "test-124_arg"
const hash =
'$argon2id$v=19$t=4,m=65536,p=1$oNZeAqWynNAkeJUGcuNMSw$O47kb/ayyV1VWoQLDpI/IkDOYUCF/Ctqzxys4cyEeGc'

Expand All @@ -239,7 +273,7 @@ test.group('argon | verify', () => {
})

test('should verify a precomputed hash with new parameters order', async ({ assert }) => {
// Precomputed hash for "password"
// Precomputed hash for "test-124_arg"
const hash =
'$argon2id$v=19$m=65536,t=4,p=1$oNZeAqWynNAkeJUGcuNMSw$O47kb/ayyV1VWoQLDpI/IkDOYUCF/Ctqzxys4cyEeGc'

Expand Down

0 comments on commit 8dd82f4

Please sign in to comment.