Skip to content

Commit

Permalink
Start throwing specific error classes
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensby committed Oct 3, 2022
1 parent 0ab1c6e commit 24ff31e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/errors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { UnsupportedAlgorithmError } from './unsupported-algorithm-error';
6 changes: 6 additions & 0 deletions src/errors/unsupported-algorithm-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Thrown when a key is presented to verify a signature with
* an algorithm that is not supported
*/
export class UnsupportedAlgorithmError extends Error {
}
5 changes: 5 additions & 0 deletions src/httpbis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
CommonConfig,
VerifyingKey,
} from '../types';
import { UnsupportedAlgorithmError } from '../errors';

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

0 comments on commit 24ff31e

Please sign in to comment.