Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
gha updates, fix lint issues from margelo#211
Browse files Browse the repository at this point in the history
  • Loading branch information
boorad committed Jan 18, 2024
1 parent e379ead commit 625e021
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 27 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/validate-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ jobs:
name: Compile JS (tsc)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install reviewdog
uses: reviewdog/action-setup@v1

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
run: echo "dir=$(yarn cache dir) >> $GITHUB_OUTPUT"
- name: Restore node_modules from cache
uses: actions/cache@v2
uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
Expand Down Expand Up @@ -71,13 +71,13 @@ jobs:
name: Lint JS (eslint, prettier)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
run: echo "dir=$(yarn cache dir) >> $GITHUB_OUTPUT"
- name: Restore node_modules from cache
uses: actions/cache@v2
uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"registry": "https://registry.npmjs.org/"
},
"devDependencies": {
"@firmnav/eslint-github-actions-formatter": "^1.0.1",
"@jamesacarr/eslint-formatter-github-actions": "^0.1.0",
"@react-native-community/eslint-plugin": "^1.3.0",
"@react-native/eslint-config": "^0.72.2",
Expand Down
17 changes: 9 additions & 8 deletions src/Hashnames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ export enum HashContext {
JwkRsaPss,
JwkRsaOaep,
JwkHmac,
};
}

// WebCrypto and JWK use a bunch of different names for the
// standard set of SHA-* digest algorithms... which is ... fun.
// Here we provide a utility for mapping between them in order
// make it easier in the code.

type HashNames = {
[key: string]: { [key in HashContext as string]: string; };
[key: string]: { [key in HashContext as string]: string };
};

const kHashNames: HashNames = {
Expand Down Expand Up @@ -57,21 +57,22 @@ const kHashNames: HashNames = {
for (let n: number = 0; n < keys.length; n++) {
const contexts: string[] = Object.keys(kHashNames[keys[n]!]!);
for (let i: number = 0; i < contexts.length; i++) {
const alias: string =
(kHashNames[keys[n]!]![contexts[i]!]!).toLowerCase();
const alias: string = kHashNames[keys[n]!]![contexts[i]!]!.toLowerCase();
if (kHashNames[alias] === undefined)
kHashNames[alias] = kHashNames[keys[n]!]!;
}
}
}

export function normalizeHashName(name: string, context: HashContext = HashContext.Node) {
if (typeof name !== 'string')
return name;
export function normalizeHashName(
name: string,
context: HashContext = HashContext.Node
) {
if (typeof name !== 'string') return name;
name = name.toLowerCase();
try {
const alias = kHashNames[name]![context];
return alias || name;
} catch(_e) {}
} catch (_e) {}
return name;
}
8 changes: 7 additions & 1 deletion src/pbkdf2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ export function pbkdf2(
const normalizedDigest = normalizeHashName(digest, HashContext.Node);

nativePbkdf2
.pbkdf2(sanitizedPassword, sanitizedSalt, iterations, keylen, normalizedDigest)
.pbkdf2(
sanitizedPassword,
sanitizedSalt,
iterations,
keylen,
normalizedDigest
)
.then(
(res: ArrayBuffer) => {
callback!(null, Buffer.from(res));
Expand Down
10 changes: 7 additions & 3 deletions test/hashnames.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { HashContext, normalizeHashName } from "../src/Hashnames";
import { HashContext, normalizeHashName } from '../src/Hashnames';

test('normalizeHashName happy', () => {
expect(normalizeHashName('SHA-1')).toBe('sha1');
expect(normalizeHashName('RSA-OAEP-512', HashContext.JwkRsaPss)).toBe('PS512');
expect(normalizeHashName('RSA-OAEP-512', HashContext.JwkRsaPss)).toBe(
'PS512'
);
});

test('normalizeHashName sad', () => {
expect(normalizeHashName('SHA-2')).toBe('sha-2');
expect(normalizeHashName('NOT-a-hash', HashContext.JwkRsaPss)).toBe('not-a-hash');
expect(normalizeHashName('NOT-a-hash', HashContext.JwkRsaPss)).toBe(
'not-a-hash'
);
});
9 changes: 1 addition & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
resolved "https://registry.yarnpkg.com/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz#bd9154aec9983f77b3a034ecaa015c2e4201f6cf"
integrity sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==

"@actions/core@^1.2.0", "@actions/core@^1.2.6":
"@actions/core@^1.2.6":
version "1.10.1"
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.10.1.tgz#61108e7ac40acae95ee36da074fa5850ca4ced8a"
integrity sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g==
Expand Down Expand Up @@ -1328,13 +1328,6 @@
resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.0.tgz#0709e9f4cb252351c609c6e6d8d6779a8d25edff"
integrity sha512-+KpH+QxZU7O4675t3mnkQKcZZg56u+K/Ct2K+N2AZYNVK8kyeo/bI18tI8aPm3tvNNRyTWfj6s5tnGNlcbQRsA==

"@firmnav/eslint-github-actions-formatter@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@firmnav/eslint-github-actions-formatter/-/eslint-github-actions-formatter-1.0.1.tgz#dbedcc4d8a799faf9b709417981039819980aab0"
integrity sha512-KbhZwNPFuwoRWspUfoJISOeGZHGSm7tvdOC+uOUlbcY9LNmusRHHmBcq3KaorvW9WmmiOS/2EOo0nafFZ0gpEQ==
dependencies:
"@actions/core" "^1.2.0"

"@hapi/hoek@^9.0.0":
version "9.3.0"
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.3.0.tgz#8368869dcb735be2e7f5cb7647de78e167a251fb"
Expand Down

0 comments on commit 625e021

Please sign in to comment.