Skip to content

Commit e61237b

Browse files
committed
Start throwing specific error classes
1 parent 6584838 commit e61237b

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

src/errors/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { UnsupportedAlgorithmError } from './unsupported-algorithm-error';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Thrown when a key is presented to verify a signature with
3+
* an algorithm that is not supported
4+
*/
5+
export class UnsupportedAlgorithmError extends Error {
6+
}

src/httpbis/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
CommonConfig,
2525
VerifyingKey,
2626
} from '../types';
27+
import { UnsupportedAlgorithmError } from '../errors';
2728

2829
export function deriveComponent(component: string, params: Map<string, string | number | boolean>, res: Response, req?: Request): string[];
2930
export function deriveComponent(component: string, params: Map<string, string | number | boolean>, req: Request): string[];
@@ -378,6 +379,10 @@ export async function verifyMessage(config: VerifyConfig, message: Request | Res
378379
return params;
379380
}, {})),
380381
]);
382+
if (input[1].has('alg') && key.algs?.includes(input[1].get('alg') as string) === false) {
383+
throw new UnsupportedAlgorithmError('Unsupported key algorithm');
384+
}
385+
// @todo - confirm this is all working as expected
381386
if (!config.all && !key) {
382387
return null;
383388
}

0 commit comments

Comments
 (0)