Skip to content

Commit 6166b2e

Browse files
committed
Change the RSA Signer to throw an error instead of returning a Boolean
1 parent 3477bf2 commit 6166b2e

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "strontium",
3-
"version": "2.6.4",
3+
"version": "2.6.5",
44
"description": "Strontium is a TypeScript toolkit for High Performance API servers built for Production not Projects.",
55
"main": "lib/src/index.js",
66
"types": "lib/src/index.d.ts",

src/cryptography/drivers/node/RSASHA256Signer.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { InvalidSignatureError } from "../../../errors/InvalidSignatureError";
12
import { AsymmetricSigner } from "../../abstract/AsymmetricSigner"
23

34
// Typescript Types not available for JWT - Proceed with caution
@@ -12,6 +13,13 @@ export class RSASHA256Signer extends AsymmetricSigner {
1213
}
1314

1415
public async verify(plaintext: Buffer, signature: Buffer): Promise<Buffer> {
15-
return RS256.verify(plaintext, signature, this.publicKey)
16+
let isValid = await RS256.verify(plaintext, signature, this.publicKey)
17+
18+
if (!isValid) {
19+
throw new InvalidSignatureError()
20+
}
21+
22+
// Spawn an empty buffer to fulfill the return type
23+
return Buffer.from([])
1624
}
1725
}

src/errors/InvalidSignatureError.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { StrontiumError } from "./StrontiumError"
2+
3+
/**
4+
* An InvalidSignatureError is thrown when a Cryptographic signature does not match.
5+
*/
6+
export class InvalidSignatureError extends StrontiumError {
7+
constructor() {
8+
super(
9+
`The signature provided was not valid.`
10+
)
11+
}
12+
}

0 commit comments

Comments
 (0)