Initial Commit
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
import { UNIVERSAL_TAGS } from "../asn1/asn1.types.js";
|
||||
import { encodeAsn1, makeConstructed, makePrimitive } from "../asn1/encoder.js";
|
||||
import { OID_BASIC_CONSTRAINTS } from "./basic-constraints.js";
|
||||
import {
|
||||
type DecodedExtension,
|
||||
decodeExtension,
|
||||
RECOGNISED_EXTENSION_OIDS,
|
||||
} from "./registry.js";
|
||||
|
||||
function bcValue(cA: boolean, pathLen: number): Uint8Array {
|
||||
return encodeAsn1(
|
||||
makeConstructed("universal", UNIVERSAL_TAGS.SEQUENCE, [
|
||||
makePrimitive(
|
||||
"universal",
|
||||
UNIVERSAL_TAGS.BOOLEAN,
|
||||
new Uint8Array([cA ? 0xff : 0x00])
|
||||
),
|
||||
makePrimitive(
|
||||
"universal",
|
||||
UNIVERSAL_TAGS.INTEGER,
|
||||
new Uint8Array([pathLen])
|
||||
),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
describe("decodeExtension dispatch", () => {
|
||||
it("dispatches basic constraints to typed decoder", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
const got = decodeExtension({
|
||||
oid: OID_BASIC_CONSTRAINTS,
|
||||
critical: true,
|
||||
value: bcValue(true, 3),
|
||||
}) as Extract<DecodedExtension, { kind: "basicConstraints" }>;
|
||||
expect(got.kind).toBe("basicConstraints");
|
||||
expect(got.value.cA).toBe(true);
|
||||
expect(got.value.pathLenConstraint).toBe(3);
|
||||
expect(got.critical).toBe(true);
|
||||
});
|
||||
|
||||
it("unknown non-critical extension yields RawExtension", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
const got = decodeExtension({
|
||||
oid: "1.2.3.4.5.6.7.8.9",
|
||||
critical: false,
|
||||
value: new Uint8Array([0x05, 0x00]),
|
||||
});
|
||||
expect(got.kind).toBe("raw");
|
||||
if (got.kind !== "raw") throw new Error();
|
||||
expect(got.critical).toBe(false);
|
||||
expect(Array.from(got.value)).toEqual([0x05, 0x00]);
|
||||
});
|
||||
|
||||
it("unknown critical extension yields RawExtension with critical: true", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
const got = decodeExtension({
|
||||
oid: "1.2.3.4.5.6.7.8.10",
|
||||
critical: true,
|
||||
value: new Uint8Array([0x05, 0x00]),
|
||||
});
|
||||
expect(got.kind).toBe("raw");
|
||||
if (got.kind !== "raw") throw new Error();
|
||||
expect(got.critical).toBe(true);
|
||||
});
|
||||
|
||||
it("recognised set covers the documented OIDs", { timeout: 5000 }, () => {
|
||||
for (const oid of [
|
||||
"2.5.29.19",
|
||||
"2.5.29.15",
|
||||
"2.5.29.37",
|
||||
"2.5.29.17",
|
||||
"2.5.29.30",
|
||||
"2.5.29.35",
|
||||
"2.5.29.14",
|
||||
"2.5.29.31",
|
||||
]) {
|
||||
expect(RECOGNISED_EXTENSION_OIDS.has(oid)).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user