Initial Commit

This commit is contained in:
2026-05-27 23:47:53 +01:00
parent fbc70f96e6
commit 9b28db724f
18103 changed files with 1600554 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import { describe, expect, it } from "@suaveplan/testing/runner";
import { encodeCounter } from "./encode-counter.js";
describe("encodeCounter — RFC 4226 §5.1 8-byte big-endian", () => {
it("encodes 0 to all-zero block", { timeout: 5000 }, () => {
expect(Array.from(encodeCounter(0n))).toEqual([0, 0, 0, 0, 0, 0, 0, 0]);
});
it("encodes 1 to ...0x01", { timeout: 5000 }, () => {
expect(Array.from(encodeCounter(1n))).toEqual([0, 0, 0, 0, 0, 0, 0, 1]);
});
it("encodes 2^32 - 1 to 0x00..0xFF FF FF FF", { timeout: 5000 }, () => {
expect(Array.from(encodeCounter((1n << 32n) - 1n))).toEqual([
0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff,
]);
});
it("encodes 2^64 - 1 to all-0xFF block", { timeout: 5000 }, () => {
expect(Array.from(encodeCounter((1n << 64n) - 1n))).toEqual([
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
]);
});
it("rejects negative counter", { timeout: 5000 }, () => {
expect(() => encodeCounter(-1n)).toThrow(/INVALID_OPTIONS/);
});
it("rejects counter > 2^64 - 1", { timeout: 5000 }, () => {
expect(() => encodeCounter(1n << 64n)).toThrow(/INVALID_OPTIONS/);
});
});