import { ErrorResult, Micro509Error } from "../result/result.js"; import { DerElement, ReadRootElementOptions, ReadSequenceChildrenOptions } from "../internal/asn1/der.js"; import { DerBitString } from "../internal/asn1/asn1.js"; //#region src/der/der.d.ts /** Machine-readable failure reason for the DER readers and decoders. */ type DecodeDerErrorCode = "malformed"; /** Structured failure payload for DER reading and decoding. */ interface DecodeDerFailure extends Micro509Error { /** Always `false` for failures. */ readonly ok: false; } /** Success-or-failure result from a DER reader or decoder. */ type DecodeDerResult = { readonly ok: true; readonly value: TValue; } | ErrorResult, DecodeDerFailure>; /** * Reads one TLV element from {@linkcode bytes} starting at {@linkcode offset}. * * @param offset Byte position of the tag octet. Defaults to 0. * @throws if the element is truncated, indefinite-length, or non-minimally encoded. */ declare function readDerElementOrThrow(bytes: Uint8Array, offset?: number): DerElement; /** * Reads one TLV element from {@linkcode bytes} starting at {@linkcode offset}. * * @param offset Byte position of the tag octet. Defaults to 0. */ declare function readDerElement(bytes: Uint8Array, offset?: number): DecodeDerResult; /** * Reads the single top-level TLV element from {@linkcode bytes}. * * @throws if {@linkcode bytes} carries trailing data, or nesting exceeds the depth guard. */ declare function readDerRootOrThrow(bytes: Uint8Array, options?: ReadRootElementOptions): DerElement; /** Reads the single top-level TLV element from {@linkcode bytes}. */ declare function readDerRoot(bytes: Uint8Array, options?: ReadRootElementOptions): DecodeDerResult; /** * Reads a DER-encoded SEQUENCE from {@linkcode bytes} and returns its direct children. * * @throws if the root element is not a SEQUENCE, or if child boundaries are inconsistent. */ declare function readDerSequenceOrThrow(bytes: Uint8Array, options?: ReadSequenceChildrenOptions): DerElement[]; /** Reads a DER-encoded SEQUENCE from {@linkcode bytes} and returns its direct children. */ declare function readDerSequence(bytes: Uint8Array, options?: ReadSequenceChildrenOptions): DecodeDerResult; /** * Reads the direct children of a constructed {@linkcode parent} within {@linkcode source}. * * @throws if a child overflows {@linkcode parent}, or data is left between the last child and its end. */ declare function derChildrenOrThrow(source: Uint8Array, parent: DerElement): DerElement[]; /** Reads the direct children of a constructed {@linkcode parent} within {@linkcode source}. */ declare function derChildren(source: Uint8Array, parent: DerElement): DecodeDerResult; /** * Decodes a BOOLEAN element (tag `0x01`). * * @throws if {@linkcode element} is mis-tagged, or holds anything but `0x00` or `0xff`. */ declare function decodeDerBooleanOrThrow(element: DerElement): boolean; /** Decodes a BOOLEAN element (tag `0x01`). */ declare function decodeDerBoolean(element: DerElement): DecodeDerResult; /** * Decodes an INTEGER element (tag `0x02`) into a `number`. * * @throws if {@linkcode element} is mis-tagged, negative, non-minimally encoded, * or exceeds {@linkcode Number.MAX_SAFE_INTEGER}. */ declare function decodeDerIntegerOrThrow(element: DerElement): number; /** Decodes an INTEGER element (tag `0x02`) into a `number`. */ declare function decodeDerInteger(element: DerElement): DecodeDerResult; /** * Decodes an OCTET STRING element (tag `0x04`) into its payload bytes. * * @throws if {@linkcode element} is mis-tagged. */ declare function decodeDerOctetStringOrThrow(element: DerElement): Uint8Array; /** Decodes an OCTET STRING element (tag `0x04`) into its payload bytes. */ declare function decodeDerOctetString(element: DerElement): DecodeDerResult; /** * Decodes an OBJECT IDENTIFIER element (tag `0x06`) into dotted-decimal form. * * @throws if {@linkcode element} is mis-tagged, or holds a malformed sub-identifier. */ declare function decodeDerOidOrThrow(element: DerElement): string; /** Decodes an OBJECT IDENTIFIER element (tag `0x06`) into dotted-decimal form. */ declare function decodeDerOid(element: DerElement): DecodeDerResult; /** * Decodes a BIT STRING element (tag `0x03`) into a {@linkcode DerBitString}. * * Unused trailing bits are returned as encoded, with a violation of {@linkcode https://www.itu.int/rec/T-REC-X.690-202102-I/en | X.690 §11.2.1} reported * through {@linkcode DerBitString.nonZeroPadding}, since certificates in the wild carry them. * * @throws if {@linkcode element} is mis-tagged, or claims more than seven unused bits. */ declare function decodeDerBitStringOrThrow(element: DerElement): DerBitString; /** * Decodes a BIT STRING element (tag `0x03`) into a {@linkcode DerBitString}. * * Unused trailing bits are returned as encoded, with a violation of {@linkcode https://www.itu.int/rec/T-REC-X.690-202102-I/en | X.690 §11.2.1} reported * through {@linkcode DerBitString.nonZeroPadding}, since certificates in the wild carry them. */ declare function decodeDerBitString(element: DerElement): DecodeDerResult; /** * Decodes a string element into text, dispatching on its tag. * * Supports UTF8String, PrintableString, IA5String, UniversalString, and BMPString. * * @throws on TeletexString, and on every other string tag. */ declare function decodeDerStringOrThrow(element: DerElement): string; /** * Decodes a string element into text, dispatching on its tag. * * Supports UTF8String, PrintableString, IA5String, UniversalString, and BMPString. */ declare function decodeDerString(element: DerElement): DecodeDerResult; /** * Decodes a UTCTime (tag `0x17`) or GeneralizedTime (tag `0x18`) element into a {@linkcode Date}. * * @throws if {@linkcode element} carries any other tag, or a malformed time value. */ declare function decodeDerTimeOrThrow(element: DerElement): Date; /** Decodes a UTCTime (tag `0x17`) or GeneralizedTime (tag `0x18`) element into a {@linkcode Date}. */ declare function decodeDerTime(element: DerElement): DecodeDerResult; //#endregion export { DecodeDerErrorCode, DecodeDerFailure, DecodeDerResult, decodeDerBitString, decodeDerBitStringOrThrow, decodeDerBoolean, decodeDerBooleanOrThrow, decodeDerInteger, decodeDerIntegerOrThrow, decodeDerOctetString, decodeDerOctetStringOrThrow, decodeDerOid, decodeDerOidOrThrow, decodeDerString, decodeDerStringOrThrow, decodeDerTime, decodeDerTimeOrThrow, derChildren, derChildrenOrThrow, readDerElement, readDerElementOrThrow, readDerRoot, readDerRootOrThrow, readDerSequence, readDerSequenceOrThrow }; //# sourceMappingURL=der.d.ts.map