update deps, cleanup

This commit is contained in:
2026-06-01 01:05:14 +02:00
parent 4c61c067e6
commit 51c3e3d05f
22 changed files with 1590 additions and 2542 deletions
+37 -33
View File
@@ -1,40 +1,44 @@
import { describe } from 'vitest'
import { Bytes, RSA } from '../dist/index.js'
import { Precomputed } from './values.js'
import { it } from 'vitest'
import { expect } from 'vitest'
import { describe } from "vitest";
import { Bytes, RSA } from "../src/index.js";
import { Precomputed } from "./values.js";
import { it } from "vitest";
import { expect } from "vitest";
describe('RSA', () => {
describe('Generate keys', function () {
it('Should be able to generate a keypair', async () => {
await RSA.generateKeyPair()
})
it('Should be able to generate a keypair with 2048bit', async () => {
await RSA.generateKeyPair(2048)
})
it('Should be able to generate a keypair with 4096bit', async () => {
await RSA.generateKeyPair(4096)
})
it('Should not be able to generate a key below 2048bit', async () => {
await expect(() => RSA.generateKeyPair(1024)).rejects.toThrowErrorMatchingSnapshot()
})
it('Should not be able to generate a key below 2048bit', async () => {
await expect(() => RSA.generateKeyPair(-1)).rejects.toThrowErrorMatchingSnapshot()
})
})
describe("RSA", () => {
describe("Generate keys", function () {
it("Should be able to generate a keypair", async () => {
await RSA.generateKeyPair();
});
it("Should be able to generate a keypair with 2048bit", async () => {
await RSA.generateKeyPair(2048);
});
it("Should be able to generate a keypair with 4096bit", async () => {
await RSA.generateKeyPair(4096);
});
it("Should not be able to generate a key below 2048bit", async () => {
await expect(() =>
RSA.generateKeyPair(1024),
).rejects.toThrowErrorMatchingSnapshot();
});
it("Should not be able to generate a key below 2048bit", async () => {
await expect(() =>
RSA.generateKeyPair(-1),
).rejects.toThrowErrorMatchingSnapshot();
});
});
describe('Encryption', () => {
describe("Encryption", () => {
for (const message of Object.values(Precomputed.Crypto.Messages)) {
it(`Should be able to encrypt and decrypt "${message.slice(0, 8)}..."`, async () => {
const pair = await RSA.generateKeyPair(2 ** 11)
const bytes = Bytes.encode(message)
const pair = await RSA.generateKeyPair(2 ** 11);
const bytes = Bytes.encode(message);
try {
const encrypted = await RSA.encrypt(bytes, pair.public)
const decrypted = await RSA.decrypt(encrypted, pair.private)
expect(decrypted).toEqual(bytes)
expect(message).toEqual(Bytes.decode(decrypted))
const encrypted = await RSA.encrypt(bytes, pair.public);
const decrypted = await RSA.decrypt(encrypted, pair.private);
expect(decrypted).toEqual(bytes);
expect(message).toEqual(Bytes.decode(decrypted));
} catch {}
})
});
}
})
})
});
});