Schema
all() enumerates the registered set), is a member that composes the shared engine and the shared PKIX sub-schemas (AlgorithmIdentifier, Name, Extension), so a structural rule (bounds-checked positional reads, optional / tagged field ordering, SET-OF uniqueness, fail-closed typed errors) is defined once in the engine and no format can reintroduce the class of bug it prevents.
parse is the orchestrator: hand it DER (or PEM) and it detects which format the bytes encode and routes to that member's parser. Each member is also reachable directly (pki.schema.x509.parse, pki.schema.crl.parse), and all() enumerates the registered formats.
pki.schema.all
pki.schema.all() -> string[]
The names of every registered format, in detection order.
Example
pki.schema.all(); // -> ["cms", "tsp", "crmf", "cmp", "ocsp-request", "ocsp-response", "pkcs12", "pkcs8", "csr", "attrcert", "attrcert-v1", "crl", "x509"]
References
- spec RFC 5280
pki.schema.parse
pki.schema.parse(input) -> parsed
Detect which PKI format input (a DER Buffer or a PEM string) encodes and route to that format's parser, returning the same structured object the format's own parse returns. Throws SchemaError("schema/unknown-format") when the bytes match no registered format; the underlying decode / structural errors of the matched format propagate unchanged.
Example
async function example() {
var pair = await pki.key.generate("Ed25519");
var der = await pki.x509.sign({ subject: "example.com", subjectPublicKey: await pki.key.export(pair.publicKey),
notBefore: new Date("2026-01-01T00:00:00Z"), notAfter: new Date("2036-01-01T00:00:00Z") },
{ key: await pki.key.export(pair.privateKey) });
var parsed = pki.schema.parse(der); // cert -> the pki.schema.x509 shape
}
example();
References
- spec RFC 5280
pki.schema.detectFormat
pki.schema.detectFormat(input) -> string | null
Detect which registered PKI format input (a DER Buffer or PEM string) encodes and return its name, one of pki.schema.all(), without parsing it, or null when the decoded bytes match no registered format. This is the detection half of pki.schema.parse, running the same authoritative FORMATS ordering, exposed for a caller (e.g. pki.inspect.any) that needs the format name instead of the parsed result. Input that does not decode as DER throws the same coercion / decode error parse throws.
Example
async function example() {
var pair = await pki.key.generate("Ed25519");
var der = await pki.x509.sign({ subject: "example.com", subjectPublicKey: await pki.key.export(pair.publicKey),
notBefore: new Date("2026-01-01T00:00:00Z"), notAfter: new Date("2036-01-01T00:00:00Z") },
{ key: await pki.key.export(pair.privateKey) });
pki.schema.detectFormat(der); // "x509" | "crl" | "csr" | "cms" | ... | null
}
example();
References
- spec RFC 5280