Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(argon): #variants to rely on argon2 exports #17

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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