Files
suaveplan/packages/security-stack/security/x509/src/extensions/subject-key-id.test.ts
2026-05-27 23:47:53 +01:00

23 lines
943 B
TypeScript

import { describe, expect, it } from "@suaveplan/testing/runner";
import { UNIVERSAL_TAGS } from "../asn1/asn1.types.js";
import { encodeAsn1, makePrimitive } from "../asn1/encoder.js";
import { X509Error } from "../errors/error-codes.js";
import { decodeSubjectKeyIdentifier } from "./subject-key-id.js";
describe("decodeSubjectKeyIdentifier", () => {
it("decodes SKI keyIdentifier byte-identically", { timeout: 5000 }, () => {
const ki = new Uint8Array(20).fill(0x5a);
const der = encodeAsn1(
makePrimitive("universal", UNIVERSAL_TAGS.OCTET_STRING, ki)
);
const ski = decodeSubjectKeyIdentifier(der);
expect(Array.from(ski.keyIdentifier)).toEqual(Array.from(ki));
});
it("rejects non-OCTET-STRING input", { timeout: 5000 }, () => {
expect(() =>
decodeSubjectKeyIdentifier(new Uint8Array([0x02, 0x01, 0x00]))
).toThrowError(X509Error);
});
});