IF Commons GitHub

der

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-formats FR-009

ASN.1 DER (ITU-T X.690), encoded and read with no outside package (commons 0001-formats FR-009): every value a tag, a length and its content, as bytes; enough to build CMS structures (RFC 5652) and read the fields of an X.509 certificate (RFC 5280). Encoders give the one DER form (minimal lengths and integers, a SET OF sorted); a malformed input to an encoder (an OID that is not dotted numbers) is a programming error and throws a RangeError. Readers return a Result: what is not DER this reader knows is an error saying where. Taken from Stolos's src/archon/export/der.ts (S/MIME for emailed exports), with negative integers and integers read.

import { oid, readOid, readTlv } from "./der.ts";
const t = readTlv(oid("1.2.840.113549.1.7.1"));
if (t.kind === "ok") readOid(t.value.content); // { kind: "ok", value: "1.2.840.113549.1.7.1" }

Source: commons/formats/src/der.ts

17 of 43 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

dernamespace
namespace der
der.TAGconstno test imports it
const TAG: { readonly boolean: 1; readonly integer: 2; readonly bitString: 3; readonly octetString: 4; readonly null: 5; readonly oid: 6; readonly utf8String: 12; readonly printableString: 19; readonly ia5String: 22; readonly utcTime: 23; readonly generalizedTime: 24; readonly sequence: 48; readonly set: 49; }

The universal tags used (class universal, with the constructed bit where it applies).

der.DerErrortypeno test imports it
type DerError = { readonly kind: "der"; readonly at: number; readonly message: string };

Why bytes are not DER this reader knows: what, and at which byte.

der.Tlvtypeno test imports it
type Tlv = { readonly tag: number; readonly content: Uint8Array; readonly raw: Uint8Array };

One element read: its tag byte, its content, and its whole encoding (to copy it into another structure).

der.encodeLengthfunctionno test imports it
function encodeLength(n: number): Uint8Array<ArrayBufferLike>

A DER length: the short form below 128, else 0x80 with the number of length bytes, then the bytes.

der.tlvfunctionno test imports it
function tlv(tag: number, content: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>

One element: the tag byte, the content's length, the content.

der.sequencefunctionno test imports it
function sequence(...items: readonly Uint8Array<ArrayBufferLike>[]): Uint8Array<ArrayBufferLike>

A SEQUENCE of these encodings, in order.

der.compareBytesfunctionno test imports it
function compareBytes(a: Uint8Array<ArrayBufferLike>, b: Uint8Array<ArrayBufferLike>): number

Two byte strings compared as DER sorts them: byte by byte, a prefix first.

der.setOffunctionno test imports it
function setOf(...items: readonly Uint8Array<ArrayBufferLike>[]): Uint8Array<ArrayBufferLike>

A SET OF these encodings, sorted as DER requires (X.690 §11.6).

der.octetStringfunctionno test imports it
function octetString(b: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>

An OCTET STRING.

der.bitStringfunctionno test imports it
function bitString(b: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>

A BIT STRING of whole bytes (no unused bits).

der.utf8Stringfunctionno test imports it
function utf8String(s: string): Uint8Array<ArrayBufferLike>

A UTF8String.

der.booleanfunctionno test imports it
function boolean(v: boolean): Uint8Array<ArrayBufferLike>

A BOOLEAN.

der.derNullfunctionno test imports it
function derNull(): Uint8Array<ArrayBufferLike>

NULL.

der.integerfunctionno test imports it
function integer(v: number | bigint | Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>

An INTEGER: a JavaScript integer or a bigint (negative too), or big-endian unsigned magnitude bytes; always in its minimal form.

der.oidfunctionno test imports it
function oid(dotted: string): Uint8Array<ArrayBufferLike>

An OBJECT IDENTIFIER from its dotted form (1.2.840.113549).

der.explicitfunctionno test imports it
function explicit(n: number, inner: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>

A context-specific EXPLICIT tag [n] around one encoding.

der.implicitfunctionno test imports it
function implicit(n: number, content: Uint8Array<ArrayBufferLike>, constructed: boolean): Uint8Array<ArrayBufferLike>

A context-specific IMPLICIT tag [n]: this content under the tag, constructed where the underlying type is.

der.algorithmfunctionno test imports it
function algorithm(id: string, params?: Uint8Array<ArrayBufferLike> | undefined): Uint8Array<ArrayBufferLike>

An AlgorithmIdentifier: SEQUENCE { algorithm OID, parameters ANY OPTIONAL }.

der.readTlvfunctionno test imports it
function readTlv(bytes: Uint8Array<ArrayBufferLike>, offset?: number): Result<Tlv, DerError>

The element that starts at offset: its tag, its content and its whole encoding; or why it is not DER this reader knows.

der.childrenfunctionno test imports it
function children(content: Uint8Array<ArrayBufferLike>): Result<readonly Tlv[], DerError>

The elements inside a constructed element's content, in order.

der.readOidfunctionno test imports it
function readOid(content: Uint8Array<ArrayBufferLike>): Result<string, DerError>

The dotted form of an OBJECT IDENTIFIER's content.

der.readIntegerfunctionno test imports it
function readInteger(content: Uint8Array<ArrayBufferLike>): Result<bigint, DerError>

The value of an INTEGER's content, as a bigint (two's complement).

TAGconst
const TAG: { readonly boolean: 1; readonly integer: 2; readonly bitString: 3; readonly octetString: 4; readonly null: 5; readonly oid: 6; readonly utf8String: 12; readonly printableString: 19; readonly ia5String: 22; readonly utcTime: 23; readonly generalizedTime: 24; readonly sequence: 48; readonly set: 49; }

The universal tags used (class universal, with the constructed bit where it applies).

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

DerErrortypeno test imports it
type DerError = { readonly kind: "der"; readonly at: number; readonly message: string };

Why bytes are not DER this reader knows: what, and at which byte.

Tlvtypeno test imports it
type Tlv = { readonly tag: number; readonly content: Uint8Array; readonly raw: Uint8Array };

One element read: its tag byte, its content, and its whole encoding (to copy it into another structure).

encodeLengthfunction
function encodeLength(n: number): Uint8Array<ArrayBufferLike>

A DER length: the short form below 128, else 0x80 with the number of length bytes, then the bytes.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

tlvfunctionno test imports it
function tlv(tag: number, content: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>

One element: the tag byte, the content's length, the content.

sequencefunction
function sequence(...items: readonly Uint8Array<ArrayBufferLike>[]): Uint8Array<ArrayBufferLike>

A SEQUENCE of these encodings, in order.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

compareBytesfunctionno test imports it
function compareBytes(a: Uint8Array<ArrayBufferLike>, b: Uint8Array<ArrayBufferLike>): number

Two byte strings compared as DER sorts them: byte by byte, a prefix first.

setOffunction
function setOf(...items: readonly Uint8Array<ArrayBufferLike>[]): Uint8Array<ArrayBufferLike>

A SET OF these encodings, sorted as DER requires (X.690 §11.6).

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

octetStringfunction
function octetString(b: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>

An OCTET STRING.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

bitStringfunction
function bitString(b: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>

A BIT STRING of whole bytes (no unused bits).

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

utf8Stringfunction
function utf8String(s: string): Uint8Array<ArrayBufferLike>

A UTF8String.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

booleanfunction
function boolean(v: boolean): Uint8Array<ArrayBufferLike>

A BOOLEAN.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

derNullfunction
function derNull(): Uint8Array<ArrayBufferLike>

NULL.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

integerfunction
function integer(v: number | bigint | Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>

An INTEGER: a JavaScript integer or a bigint (negative too), or big-endian unsigned magnitude bytes; always in its minimal form.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

oidfunction
function oid(dotted: string): Uint8Array<ArrayBufferLike>

An OBJECT IDENTIFIER from its dotted form (1.2.840.113549).

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

explicitfunction
function explicit(n: number, inner: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>

A context-specific EXPLICIT tag [n] around one encoding.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

implicitfunction
function implicit(n: number, content: Uint8Array<ArrayBufferLike>, constructed: boolean): Uint8Array<ArrayBufferLike>

A context-specific IMPLICIT tag [n]: this content under the tag, constructed where the underlying type is.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

algorithmfunction
function algorithm(id: string, params?: Uint8Array<ArrayBufferLike> | undefined): Uint8Array<ArrayBufferLike>

An AlgorithmIdentifier: SEQUENCE { algorithm OID, parameters ANY OPTIONAL }.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

readTlvfunction
function readTlv(bytes: Uint8Array<ArrayBufferLike>, offset?: number): Result<Tlv, DerError>

The element that starts at offset: its tag, its content and its whole encoding; or why it is not DER this reader knows.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

readOidfunction
function readOid(content: Uint8Array<ArrayBufferLike>): Result<string, DerError>

The dotted form of an OBJECT IDENTIFIER's content.

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

readIntegerfunction
function readInteger(content: Uint8Array<ArrayBufferLike>): Result<bigint, DerError>

The value of an INTEGER's content, as a bigint (two's complement).

Imported by 5 tests of the run (5 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.