Skip to content

Commit

Permalink
Test pkcs1 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Apr 16, 2024
1 parent 08ca985 commit 744dbec
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/tokens/tokenencryption.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { expect } from "chai";

describe("TokenEncryption", () => {
let keyPromise: Promise<Buffer>;
let keyPromisePKCS1: Promise<Buffer>;
async function createTokenEncryption() {
return new TokenEncryption(await keyPromise);
}
Expand All @@ -24,6 +25,21 @@ describe("TokenEncryption", () => {
} satisfies RSAKeyPairOptions<"pem", "pem">, (err, _, privateKey) => {
if (err) { reject(err) } else { resolve(Buffer.from(privateKey)) }
}));
keyPromisePKCS1 = new Promise<Buffer>((resolve, reject) => generateKeyPair("rsa", {
// Deliberately shorter length to speed up test
modulusLength: 2048,
privateKeyEncoding: {
type: "pkcs1",
format: "pem",
},
publicKeyEncoding: {
format: "pem",
type: "pkcs1",
}
} satisfies RSAKeyPairOptions<"pem", "pem">, (err, _, privateKey) => {
if (err) { reject(err) } else { resolve(Buffer.from(privateKey)) }
}));

}, );
it('should be able to encrypt a string into a single part', async() => {
const tokenEncryption = await createTokenEncryption();
Expand All @@ -45,4 +61,9 @@ describe("TokenEncryption", () => {
const result = tokenEncryption.decrypt(value);
expect(result).to.equal(plaintext);
});
it('should support pkcs1 format keys', async() => {
const tokenEncryption = new TokenEncryption(await keyPromisePKCS1);
const result = tokenEncryption.encrypt('hello world');
expect(result).to.have.lengthOf(1);
});
});

0 comments on commit 744dbec

Please sign in to comment.