Skip to content

Commit

Permalink
Fix tests and build on arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
ranisalt committed Dec 16, 2023
1 parent 74c2388 commit b794bd9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 36 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/dummy-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
matrix:
include:
- arch: aarch64
distro: ubuntu20.04
distro: ubuntu_latest
- arch: aarch64
distro: alpine_latest

Expand All @@ -88,18 +88,20 @@ jobs:
dockerRunArgs: --volume "${PWD}:/repo"
install: |
case "${{ matrix.distro }}" in
ubuntu*|jessie|stretch|buster)
ubuntu*)
apt update -yq
apt install -yq curl make g++ python
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt install -yq nodejs
apt install -yq ca-certificates curl g++ gnupg make python3
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list
apt update -yq
apt install -yq nodejs yarn
;;
alpine*)
apk add --update make g++ python3
apk add --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/v3.17/main/ nodejs~=20 npm~=20
apk add --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/v3.19/main/ nodejs~=20 yarn
;;
esac
npm install --global yarn
run: |
cd /repo
yarn install --frozen-lockfile --ignore-scripts
Expand Down Expand Up @@ -149,7 +151,7 @@ jobs:
uses: actions/checkout@v4
with:
submodules: true

- name: Download artifacts
id: download-artifact
uses: actions/download-artifact@v3
Expand Down
37 changes: 18 additions & 19 deletions argon2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -137,30 +137,29 @@ export function needsRehash(digest, options) {
* @return {Promise<boolean>} `true` if the digest parameters matches the hash generated from `plain`, otherwise `false`
*/
export async function verify(digest, plain, options) {
const { id, ...rest } = deserialize(digest);
if (!(id in types)) {
return false;
}

const {
id,
version = 0x10,
params: { m, t, p, data },
salt,
hash,
} = deserialize(digest);
} = rest;

// Only "types" have the "params" key, so if the password was encoded
// using any other method, the destructuring throws an error
return (
id in types &&
timingSafeEqual(
await bindingsHash(Buffer.from(plain), salt, {
...options,
type: types[id],
version: +version,
hashLength: hash.length,
memoryCost: +m,
timeCost: +t,
parallelism: +p,
...(data ? { associatedData: Buffer.from(data, "base64") } : {}),
}),
hash,
)
return timingSafeEqual(
await bindingsHash(Buffer.from(plain), salt, {
...options,
type: types[id],
version: +version,
hashLength: hash.length,
memoryCost: +m,
timeCost: +t,
parallelism: +p,
...(data ? { associatedData: Buffer.from(data, "base64") } : {}),
}),
hash,
);
}
14 changes: 5 additions & 9 deletions test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from "node:assert/strict";
import { describe, it } from "node:test";
import * as argon2 from "./argon2.mjs";

const { argon2i, argon2d, argon2id, defaults, limits } = argon2;
const { argon2i, argon2d, argon2id, limits } = argon2;

const password = "password";
const salt = Buffer.alloc(16, "salt");
Expand Down Expand Up @@ -213,19 +213,15 @@ describe("needsRehash", () => {
});

it("needs rehash low memory cost", async () => {
const hash = await argon2.hash(password, {
memoryCost: defaults.memoryCost / 2,
});
const hash = await argon2.hash(password, { memoryCost: 1 << 15 });
assert(argon2.needsRehash(hash));
assert(!argon2.needsRehash(hash, { memoryCost: defaults.memoryCost / 2 }));
assert(!argon2.needsRehash(hash, { memoryCost: 1 << 15 }));
});

it("needs rehash low time cost", async () => {
const hash = await argon2.hash(password, {
timeCost: defaults.timeCost - 1,
});
const hash = await argon2.hash(password, { timeCost: 2 });
assert(argon2.needsRehash(hash));
assert(!argon2.needsRehash(hash, { timeCost: defaults.timeCost - 1 }));
assert(!argon2.needsRehash(hash, { timeCost: 2 }));
});
});

Expand Down

0 comments on commit b794bd9

Please sign in to comment.