38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
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);
|
|
});
|
|
});
|