Skip to content

Commit

Permalink
fix: when algo is an object of SubtleAlgorithm (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjhman21 authored Sep 18, 2024
1 parent 05d18e2 commit 89b45cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Hashnames.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { HashAlgorithm } from './keys';
import type { HashAlgorithm, SubtleAlgorithm } from './keys';

export enum HashContext {
Node,
Expand Down Expand Up @@ -79,10 +79,13 @@ const kHashNames: HashNames = {
}

export function normalizeHashName(
algo: string | HashAlgorithm | undefined,
algo: string | HashAlgorithm | SubtleAlgorithm | undefined,
context: HashContext = HashContext.Node,
): HashAlgorithm {
if (typeof algo !== 'undefined') {
if (typeof algo === 'object') {
algo = algo.name;
}
const normAlgo = algo.toString().toLowerCase();
try {
const alias = kHashNames[normAlgo]![context] as HashAlgorithm;
Expand Down
1 change: 1 addition & 0 deletions test/hashnames.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ test('normalizeHashName happy', () => {
expect(normalizeHashName('SHA-256')).toBe('sha256');
expect(normalizeHashName('SHA-384')).toBe('sha384');
expect(normalizeHashName('SHA-512')).toBe('sha512');
expect(normalizeHashName({ name: 'SHA-256' })).toBe('sha256');
});

test('normalizeHashName sad', () => {
Expand Down

0 comments on commit 89b45cc

Please sign in to comment.