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,37 @@
import { describe, expect, it } from "@suaveplan/testing/runner";
import { UNIVERSAL_TAGS } from "./asn1.types.js";
import { decodeGeneralizedTime, decodeUtcTime, encodeTime } from "./time.js";
describe("Time codec", () => {
it("UTCTime 50/49 split — YY < 50 resolves to 20YY", {
timeout: 5000,
}, () => {
const ms = decodeUtcTime(new TextEncoder().encode("250101000000Z"));
expect(ms).toBe(Date.UTC(2025, 0, 1));
});
it("UTCTime 50/49 split — YY >= 50 resolves to 19YY", {
timeout: 5000,
}, () => {
const ms = decodeUtcTime(new TextEncoder().encode("750101000000Z"));
expect(ms).toBe(Date.UTC(1975, 0, 1));
});
it("GeneralizedTime requires Z", { timeout: 5000 }, () => {
expect(() =>
decodeGeneralizedTime(new TextEncoder().encode("20250101000000"))
).toThrow();
});
it("encodeTime picks UTCTime before 2050", { timeout: 5000 }, () => {
const out = encodeTime(Date.UTC(2024, 0, 15));
expect(out.tagNumber).toBe(UNIVERSAL_TAGS.UTC_TIME);
});
it("encodeTime picks GeneralizedTime at/after 2050", {
timeout: 5000,
}, () => {
const out = encodeTime(Date.UTC(2055, 0, 15));
expect(out.tagNumber).toBe(UNIVERSAL_TAGS.GENERALIZED_TIME);
});
});