@ac-kit/format-asn1 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +81 -0
- package/README.md +132 -4
- package/dist/_encoding/constants.d.ts +2 -0
- package/dist/_encoding/constants.d.ts.map +1 -1
- package/dist/_encoding/constants.js +7 -0
- package/dist/_encoding/constants.js.map +1 -1
- package/dist/_encoding/decode-primitive.d.ts +39 -0
- package/dist/_encoding/decode-primitive.d.ts.map +1 -0
- package/dist/_encoding/decode-primitive.js +144 -0
- package/dist/_encoding/decode-primitive.js.map +1 -0
- package/dist/_encoding/def-tags.d.ts +36 -3
- package/dist/_encoding/def-tags.d.ts.map +1 -1
- package/dist/_encoding/def-tags.js +88 -3
- package/dist/_encoding/def-tags.js.map +1 -1
- package/dist/_encoding/encoded-tag-sort-key.d.ts +7 -0
- package/dist/_encoding/encoded-tag-sort-key.d.ts.map +1 -0
- package/dist/_encoding/encoded-tag-sort-key.js +13 -0
- package/dist/_encoding/encoded-tag-sort-key.js.map +1 -0
- package/dist/_encoding/tag.d.ts +1 -6
- package/dist/_encoding/tag.d.ts.map +1 -1
- package/dist/_encoding/tag.js +5 -43
- package/dist/_encoding/tag.js.map +1 -1
- package/dist/_encoding/tlv.d.ts +4 -25
- package/dist/_encoding/tlv.d.ts.map +1 -1
- package/dist/_encoding/tlv.js +12 -48
- package/dist/_encoding/tlv.js.map +1 -1
- package/dist/_encoding/values.d.ts.map +1 -1
- package/dist/_encoding/values.js +31 -19
- package/dist/_encoding/values.js.map +1 -1
- package/dist/_encoding/vlq.d.ts.map +1 -1
- package/dist/_encoding/vlq.js +2 -2
- package/dist/_encoding/vlq.js.map +1 -1
- package/dist/_encoding/with-offset.d.ts +12 -0
- package/dist/_encoding/with-offset.d.ts.map +1 -0
- package/dist/_encoding/with-offset.js +22 -0
- package/dist/_encoding/with-offset.js.map +1 -0
- package/dist/ber/_decode.d.ts +25 -0
- package/dist/ber/_decode.d.ts.map +1 -0
- package/dist/ber/_decode.js +409 -0
- package/dist/ber/_decode.js.map +1 -0
- package/dist/ber/codec.d.ts +3 -2
- package/dist/ber/codec.d.ts.map +1 -1
- package/dist/ber/codec.js +45 -16
- package/dist/ber/codec.js.map +1 -1
- package/dist/ber/decode.d.ts +30 -1
- package/dist/ber/decode.d.ts.map +1 -1
- package/dist/ber/decode.js +31 -221
- package/dist/ber/decode.js.map +1 -1
- package/dist/ber/encode.d.ts +7 -1
- package/dist/ber/encode.d.ts.map +1 -1
- package/dist/ber/encode.js +46 -53
- package/dist/ber/encode.js.map +1 -1
- package/dist/cer/decode.d.ts +20 -1
- package/dist/cer/decode.d.ts.map +1 -1
- package/dist/cer/decode.js +27 -221
- package/dist/cer/decode.js.map +1 -1
- package/dist/cer/encode.d.ts +22 -6
- package/dist/cer/encode.d.ts.map +1 -1
- package/dist/cer/encode.js +147 -136
- package/dist/cer/encode.js.map +1 -1
- package/dist/der/decode.d.ts +27 -21
- package/dist/der/decode.d.ts.map +1 -1
- package/dist/der/decode.js +323 -398
- package/dist/der/decode.js.map +1 -1
- package/dist/der/encode.js +5 -8
- package/dist/der/encode.js.map +1 -1
- package/dist/errors.d.ts +56 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +31 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/per/decode.d.ts +9 -0
- package/dist/per/decode.d.ts.map +1 -1
- package/dist/per/decode.js +114 -32
- package/dist/per/decode.js.map +1 -1
- package/dist/per/encode.js +1 -1
- package/dist/per/encode.js.map +1 -1
- package/dist/reader/_framing.d.ts +38 -0
- package/dist/reader/_framing.d.ts.map +1 -0
- package/dist/reader/_framing.js +144 -0
- package/dist/reader/_framing.js.map +1 -0
- package/dist/reader/_header.d.ts +49 -0
- package/dist/reader/_header.d.ts.map +1 -0
- package/dist/reader/_header.js +130 -0
- package/dist/reader/_header.js.map +1 -0
- package/dist/reader/ber-reader.d.ts +240 -0
- package/dist/reader/ber-reader.d.ts.map +1 -0
- package/dist/reader/ber-reader.js +567 -0
- package/dist/reader/ber-reader.js.map +1 -0
- package/dist/reader/inspect.d.ts +68 -0
- package/dist/reader/inspect.d.ts.map +1 -0
- package/dist/reader/inspect.js +104 -0
- package/dist/reader/inspect.js.map +1 -0
- package/dist/schema/universal-tag-name.d.ts +26 -0
- package/dist/schema/universal-tag-name.d.ts.map +1 -0
- package/dist/schema/universal-tag-name.js +74 -0
- package/dist/schema/universal-tag-name.js.map +1 -0
- package/package.json +9 -8
- package/dist/_encoding/errors.d.ts +0 -8
- package/dist/_encoding/errors.d.ts.map +0 -1
- package/dist/_encoding/errors.js +0 -15
- package/dist/_encoding/errors.js.map +0 -1
package/dist/ber/codec.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ByteReader } from "@ac-kit/core";
|
|
2
1
|
import { decodeIncomplete, } from "@ac-kit/format-core";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { DecodingError } from "../errors.js";
|
|
3
|
+
import { createHeaderScratch, DEFAULT_MAX_TAG_OCTETS, readHeaderAt, } from "../reader/_header.js";
|
|
4
|
+
import { BER_POLICY, BER_STRICT_POLICY, decodeBerFamily, } from "./_decode.js";
|
|
5
5
|
import { berEncode } from "./encode.js";
|
|
6
6
|
/**
|
|
7
7
|
* Total byte length of the TLV at the front of `view`, or `undefined` when the
|
|
@@ -10,18 +10,36 @@ import { berEncode } from "./encode.js";
|
|
|
10
10
|
* Indefinite-length encodings are reported as `undefined` too: their extent is
|
|
11
11
|
* only known once the matching end-of-contents marker is found, which is a scan
|
|
12
12
|
* the framing layer must not do speculatively.
|
|
13
|
+
*
|
|
14
|
+
* @throws {DecodingError} `limit-exceeded` when the header and the contents it
|
|
15
|
+
* declares are together longer than the largest safe integer: no input can
|
|
16
|
+
* ever complete such a value, and the total is no number a hint can carry.
|
|
13
17
|
*/
|
|
14
|
-
function framedLength(view) {
|
|
18
|
+
function framedLength(view, scratch) {
|
|
19
|
+
if (view.length === 0) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
15
22
|
try {
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
readHeaderAt(view, 0, view.length, true, DEFAULT_MAX_TAG_OCTETS, scratch);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error instanceof DecodingError) {
|
|
27
|
+
// More input mends the others, not a limit.
|
|
28
|
+
if (error.code === "limit-exceeded")
|
|
29
|
+
throw error;
|
|
18
30
|
return undefined;
|
|
19
31
|
}
|
|
20
|
-
|
|
32
|
+
throw error;
|
|
21
33
|
}
|
|
22
|
-
|
|
34
|
+
const length = scratch.contentsLength;
|
|
35
|
+
if (length < 0) {
|
|
23
36
|
return undefined;
|
|
24
37
|
}
|
|
38
|
+
const headerLength = scratch.contentsOffset;
|
|
39
|
+
if (length > Number.MAX_SAFE_INTEGER - headerLength) {
|
|
40
|
+
throw new DecodingError(`Element of ${length} content octet(s) and a ${headerLength}-octet header is longer than the largest safe integer`, scratch.lengthOffset, "limit-exceeded");
|
|
41
|
+
}
|
|
42
|
+
return headerLength + length;
|
|
25
43
|
}
|
|
26
44
|
/**
|
|
27
45
|
* Creates a BER {@link Decoder} bound to `def`.
|
|
@@ -34,36 +52,47 @@ function framedLength(view) {
|
|
|
34
52
|
* bytes one value occupies, so an incomplete value is reported as such with a
|
|
35
53
|
* `needAtLeast` hint instead of being guessed at. Indefinite-length encodings
|
|
36
54
|
* are decoded only once the whole input is available, since their extent is not
|
|
37
|
-
* declared up front.
|
|
55
|
+
* declared up front; then `consumed` is the bytes the value used.
|
|
38
56
|
*
|
|
39
57
|
* A malformed value is `fatal`: the length that framed it cannot be trusted, so
|
|
40
|
-
* there is no position to resynchronise from.
|
|
58
|
+
* there is no position to resynchronise from. So is a header declaring more
|
|
59
|
+
* than `Number.MAX_SAFE_INTEGER` octets in all (`limit-exceeded`).
|
|
41
60
|
*/
|
|
42
61
|
export function createBerDecoder(def, options = {}) {
|
|
62
|
+
const policy = options.strict ? BER_STRICT_POLICY : BER_POLICY;
|
|
63
|
+
const scratch = createHeaderScratch();
|
|
43
64
|
return {
|
|
44
65
|
decode(view, context) {
|
|
45
|
-
|
|
66
|
+
let total;
|
|
67
|
+
try {
|
|
68
|
+
total = framedLength(view, scratch);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
// A framing error that no further input can mend.
|
|
72
|
+
return { status: "fatal", error };
|
|
73
|
+
}
|
|
46
74
|
if (total === undefined) {
|
|
47
75
|
if (!context.atEof) {
|
|
48
76
|
return { status: "incomplete" };
|
|
49
77
|
}
|
|
50
78
|
// At end of input the buffer is all there will ever be, so an
|
|
51
79
|
// indefinite-length value can finally be decoded against it.
|
|
52
|
-
return decodeSlice(def, view,
|
|
80
|
+
return decodeSlice(def, view, policy);
|
|
53
81
|
}
|
|
54
82
|
if (view.length < total) {
|
|
55
83
|
return decodeIncomplete(total);
|
|
56
84
|
}
|
|
57
|
-
return decodeSlice(def, view.subarray(0, total),
|
|
85
|
+
return decodeSlice(def, view.subarray(0, total), policy);
|
|
58
86
|
},
|
|
59
87
|
};
|
|
60
88
|
}
|
|
61
|
-
function decodeSlice(def, slice,
|
|
89
|
+
function decodeSlice(def, slice, policy) {
|
|
62
90
|
try {
|
|
91
|
+
const { value, end } = decodeBerFamily(def, slice, policy);
|
|
63
92
|
return {
|
|
64
93
|
status: "decoded",
|
|
65
|
-
value:
|
|
66
|
-
consumed,
|
|
94
|
+
value: value,
|
|
95
|
+
consumed: end,
|
|
67
96
|
};
|
|
68
97
|
}
|
|
69
98
|
catch (error) {
|
package/dist/ber/codec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../src/ber/codec.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"codec.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eAAe,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAC3D,OAAO;YACN,MAAM,EAAE,SAAS;YACjB,KAAK,EAAE,KAAsB;YAC7B,QAAQ,EAAE,GAAG;SACb,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO;YACN,MAAM,EAAE,OAAO;YACf,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SAChE,CAAC;IACH,CAAC;AACF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC/B,GAAM,EACN,OAAO,GAAqB,EAAE;IAE9B,OAAO;QACN,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC;KACjD,CAAC;AACH,CAAC"}
|
package/dist/ber/decode.d.ts
CHANGED
|
@@ -4,6 +4,35 @@ export interface BerDecodeOptions {
|
|
|
4
4
|
/** If true, perform DER/CER canonicality checks and throw on violations. */
|
|
5
5
|
readonly strict?: boolean;
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* BER decoder — decodes the first element of `bytes` according to `def`; bytes
|
|
9
|
+
* after it are ignored.
|
|
10
|
+
*
|
|
11
|
+
* The framing is `BerReader`'s with the rules `"ber"`: definite and indefinite
|
|
12
|
+
* lengths, constructed strings reassembled from their segments (a character
|
|
13
|
+
* split across segments decodes), end-of-contents octets only where an
|
|
14
|
+
* indefinite-length element ends. The contents are refused as `derDecode`
|
|
15
|
+
* refuses them under every mode (a BOOLEAN that is not one octet, an INTEGER
|
|
16
|
+
* that is empty or has a redundant leading octet, a BIT STRING without its
|
|
17
|
+
* initial octet or with unused bits it cannot have, a non-empty NULL, a
|
|
18
|
+
* BMPString or UniversalString of a length that is no multiple of its code
|
|
19
|
+
* unit, text that is not valid, a UTCTime or GeneralizedTime that does not
|
|
20
|
+
* exist). A SEQUENCE or SET with no extension marker refuses an element after
|
|
21
|
+
* its last component, an EXPLICIT tag a second element inside it, and a type
|
|
22
|
+
* that is only ever primitive (BOOLEAN, INTEGER, ENUMERATED, NULL, REAL, the
|
|
23
|
+
* object identifier types, the OID-IRI types, TIME and the types derived from
|
|
24
|
+
* it) its constructed form. SET components are read by tag, in any order;
|
|
25
|
+
* unknown extension additions are skipped, also those before the root
|
|
26
|
+
* components that follow a second extension marker. ANY values keep their
|
|
27
|
+
* original bytes, indefinite form included. Nesting deeper than 512 values is
|
|
28
|
+
* refused.
|
|
29
|
+
*
|
|
30
|
+
* @param def - Schema of the value.
|
|
31
|
+
* @param bytes - BER bytes.
|
|
32
|
+
* @param opts - `strict` also requires BOOLEAN TRUE to be `0xFF`.
|
|
33
|
+
* @throws {DecodingError} For anything wrong with the input, with its offset
|
|
34
|
+
* and a `code`; an error in a constructed string is placed on the octet of
|
|
35
|
+
* the input it concerns.
|
|
36
|
+
*/
|
|
8
37
|
export declare function berDecode<D extends AnyAsn1TypeDef>(def: D, bytes: Uint8Array, opts?: BerDecodeOptions): DefValueOf<D>;
|
|
9
38
|
//# sourceMappingURL=decode.d.ts.map
|
package/dist/ber/decode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/ber/decode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/ber/decode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D,MAAM,WAAW,gBAAgB;IAChC,4EAA4E;IAC5E,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,cAAc,EACjD,GAAG,EAAE,CAAC,EACN,KAAK,EAAE,UAAU,EACjB,IAAI,GAAE,gBAAqB,GACzB,UAAU,CAAC,CAAC,CAAC,CAMf"}
|
package/dist/ber/decode.js
CHANGED
|
@@ -1,225 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { choiceAlternatives, outerTagSet, outerTagSetHas, } from "../_encoding/def-tags.js";
|
|
3
|
-
import { freshDefault } from "../_encoding/default-output.js";
|
|
4
|
-
import { DecodingError } from "../_encoding/errors.js";
|
|
5
|
-
import { encodeDefiniteLength, encodeTag } from "../_encoding/tag.js";
|
|
6
|
-
import { readTlv } from "../_encoding/tlv.js";
|
|
7
|
-
import { decodeGeneralizedTime, decodeOid, decodeReal, decodeRelativeOid, decodeUtcTime, } from "../_encoding/values.js";
|
|
8
|
-
import { universalTagFor } from "./tags.js";
|
|
9
|
-
const decodingError = (message) => new DecodingError(message);
|
|
10
|
-
/** BER decoder — reads one TLV from bytes and decodes it according to def. */
|
|
11
|
-
export function berDecode(def, bytes, opts = {}) {
|
|
12
|
-
const reader = new ByteReader(bytes);
|
|
13
|
-
return berDecodeReader(def, reader, opts);
|
|
14
|
-
}
|
|
1
|
+
import { BER_POLICY, BER_STRICT_POLICY, decodeBerFamily } from "./_decode.js";
|
|
15
2
|
/**
|
|
16
|
-
* BER decoder —
|
|
17
|
-
*
|
|
3
|
+
* BER decoder — decodes the first element of `bytes` according to `def`; bytes
|
|
4
|
+
* after it are ignored.
|
|
5
|
+
*
|
|
6
|
+
* The framing is `BerReader`'s with the rules `"ber"`: definite and indefinite
|
|
7
|
+
* lengths, constructed strings reassembled from their segments (a character
|
|
8
|
+
* split across segments decodes), end-of-contents octets only where an
|
|
9
|
+
* indefinite-length element ends. The contents are refused as `derDecode`
|
|
10
|
+
* refuses them under every mode (a BOOLEAN that is not one octet, an INTEGER
|
|
11
|
+
* that is empty or has a redundant leading octet, a BIT STRING without its
|
|
12
|
+
* initial octet or with unused bits it cannot have, a non-empty NULL, a
|
|
13
|
+
* BMPString or UniversalString of a length that is no multiple of its code
|
|
14
|
+
* unit, text that is not valid, a UTCTime or GeneralizedTime that does not
|
|
15
|
+
* exist). A SEQUENCE or SET with no extension marker refuses an element after
|
|
16
|
+
* its last component, an EXPLICIT tag a second element inside it, and a type
|
|
17
|
+
* that is only ever primitive (BOOLEAN, INTEGER, ENUMERATED, NULL, REAL, the
|
|
18
|
+
* object identifier types, the OID-IRI types, TIME and the types derived from
|
|
19
|
+
* it) its constructed form. SET components are read by tag, in any order;
|
|
20
|
+
* unknown extension additions are skipped, also those before the root
|
|
21
|
+
* components that follow a second extension marker. ANY values keep their
|
|
22
|
+
* original bytes, indefinite form included. Nesting deeper than 512 values is
|
|
23
|
+
* refused.
|
|
24
|
+
*
|
|
25
|
+
* @param def - Schema of the value.
|
|
26
|
+
* @param bytes - BER bytes.
|
|
27
|
+
* @param opts - `strict` also requires BOOLEAN TRUE to be `0xFF`.
|
|
28
|
+
* @throws {DecodingError} For anything wrong with the input, with its offset
|
|
29
|
+
* and a `code`; an error in a constructed string is placed on the octet of
|
|
30
|
+
* the input it concerns.
|
|
18
31
|
*/
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
if (def.kind === "lazy") {
|
|
22
|
-
const inner = def.getter();
|
|
23
|
-
return berDecodeReader(inner, reader, opts);
|
|
24
|
-
}
|
|
25
|
-
if (def.kind === "transform") {
|
|
26
|
-
const decoded = berDecodeReader(def.innerType, reader, opts);
|
|
27
|
-
const fn = def.fn ?? ((v) => v);
|
|
28
|
-
return fn(decoded);
|
|
29
|
-
}
|
|
30
|
-
// CHOICE: peek at the next tag and dispatch
|
|
31
|
-
if (def.kind === "choice") {
|
|
32
|
-
return decodeChoice(def, reader, opts);
|
|
33
|
-
}
|
|
34
|
-
// Tagged types
|
|
35
|
-
if (def.kind === "tagged") {
|
|
36
|
-
return decodeTagged(def, reader, opts);
|
|
37
|
-
}
|
|
38
|
-
// ANY: consume the raw TLV and return it as { encoded: Uint8Array }
|
|
39
|
-
if (def.kind === "any") {
|
|
40
|
-
//const startPos = reader.position;
|
|
41
|
-
const { tag, contents } = readTlv(reader);
|
|
42
|
-
// Re-assemble the full TLV for the AnyValue
|
|
43
|
-
const tagBytes = encodeTag(tag);
|
|
44
|
-
const lenBytes = encodeDefiniteLength(contents.length);
|
|
45
|
-
const encoded = concatBytes(tagBytes, lenBytes, contents);
|
|
46
|
-
return { encoded };
|
|
47
|
-
}
|
|
48
|
-
// Normal types: read the TLV and verify the tag
|
|
49
|
-
const { tag, contents } = readTlv(reader);
|
|
50
|
-
const expectedTagInfo = universalTagFor(def);
|
|
51
|
-
if (expectedTagInfo) {
|
|
52
|
-
if (tag.tagClass !== "universal" ||
|
|
53
|
-
tag.tagNumber !== expectedTagInfo.tagNumber) {
|
|
54
|
-
throw new DecodingError(`Expected UNIVERSAL tag ${expectedTagInfo.tagNumber}, got ${tag.tagClass} ${tag.tagNumber}`, reader.position);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return decodeContents(def, contents, opts);
|
|
58
|
-
}
|
|
59
|
-
/** Decode the raw contents bytes (without TLV header) for a given def. */
|
|
60
|
-
function decodeContents(def, contents, opts) {
|
|
61
|
-
switch (def.kind) {
|
|
62
|
-
case "boolean":
|
|
63
|
-
if (opts.strict && contents[0] !== 0x00 && contents[0] !== 0xff) {
|
|
64
|
-
throw new DecodingError("DER: BOOLEAN TRUE must be 0xFF");
|
|
65
|
-
}
|
|
66
|
-
return contents[0] !== 0x00;
|
|
67
|
-
case "integer":
|
|
68
|
-
case "enumerated":
|
|
69
|
-
return bigIntFromBytesBe(contents);
|
|
70
|
-
case "bitString": {
|
|
71
|
-
if (contents.length === 0)
|
|
72
|
-
return { bytes: new Uint8Array(0), unusedBits: 0 };
|
|
73
|
-
const unusedBits = contents[0];
|
|
74
|
-
return { bytes: contents.slice(1), unusedBits };
|
|
75
|
-
}
|
|
76
|
-
case "octetString":
|
|
77
|
-
return contents.slice();
|
|
78
|
-
case "null":
|
|
79
|
-
return null;
|
|
80
|
-
case "objectIdentifier":
|
|
81
|
-
return decodeOid(contents);
|
|
82
|
-
case "relativeOid":
|
|
83
|
-
return decodeRelativeOid(contents);
|
|
84
|
-
case "oidIri":
|
|
85
|
-
case "relativeOidIri":
|
|
86
|
-
return decodeText(contents, "utf-8", { fatal: true, ignoreBOM: true });
|
|
87
|
-
case "real":
|
|
88
|
-
return decodeReal(contents);
|
|
89
|
-
case "any":
|
|
90
|
-
return { encoded: contents.slice() };
|
|
91
|
-
case "utf8String":
|
|
92
|
-
return decodeText(contents, "utf-8", { fatal: true, ignoreBOM: true });
|
|
93
|
-
case "numericString":
|
|
94
|
-
case "printableString":
|
|
95
|
-
case "teletexString":
|
|
96
|
-
case "videotexString":
|
|
97
|
-
case "ia5String":
|
|
98
|
-
case "graphicString":
|
|
99
|
-
case "visibleString":
|
|
100
|
-
case "generalString":
|
|
101
|
-
return decodeText(contents, "latin1");
|
|
102
|
-
case "universalString":
|
|
103
|
-
return decodeText(contents, "utf-32be");
|
|
104
|
-
case "bmpString":
|
|
105
|
-
return decodeText(contents, "utf-16be", { ignoreBOM: true });
|
|
106
|
-
case "utcTime":
|
|
107
|
-
return decodeUtcTime(contents);
|
|
108
|
-
case "generalizedTime":
|
|
109
|
-
return decodeGeneralizedTime(contents);
|
|
110
|
-
case "time":
|
|
111
|
-
case "date":
|
|
112
|
-
case "timeOfDay":
|
|
113
|
-
case "dateTime":
|
|
114
|
-
case "duration":
|
|
115
|
-
return decodeText(contents, "latin1");
|
|
116
|
-
case "sequence":
|
|
117
|
-
case "set":
|
|
118
|
-
return decodeSequenceContents(def, contents, opts);
|
|
119
|
-
case "sequenceOf":
|
|
120
|
-
return decodeOfContents(def.elementType, contents, opts);
|
|
121
|
-
case "setOf":
|
|
122
|
-
return decodeOfContents(def.elementType, contents, opts);
|
|
123
|
-
case "external":
|
|
124
|
-
case "embeddedPdv":
|
|
125
|
-
case "characterString":
|
|
126
|
-
return contents.slice();
|
|
127
|
-
case "lazy": {
|
|
128
|
-
const inner = def.getter();
|
|
129
|
-
return decodeContents(inner, contents, opts);
|
|
130
|
-
}
|
|
131
|
-
case "transform":
|
|
132
|
-
return decodeContents(def.innerType, contents, opts);
|
|
133
|
-
default:
|
|
134
|
-
throw new DecodingError(`Cannot BER-decode def kind: ${def.kind}`);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
function decodeTagged(def, reader, opts) {
|
|
138
|
-
const { tag, contents } = readTlv(reader);
|
|
139
|
-
// Verify the outer tag matches the expected tagged tag
|
|
140
|
-
const expectedClass = def.tag.tagClass;
|
|
141
|
-
const expectedNum = def.tag.tagNumber;
|
|
142
|
-
if (tag.tagClass !== expectedClass || tag.tagNumber !== expectedNum) {
|
|
143
|
-
throw new DecodingError(`Expected ${expectedClass} tag ${expectedNum}, got ${tag.tagClass} ${tag.tagNumber}`, reader.position);
|
|
144
|
-
}
|
|
145
|
-
if (def.mode === "explicit") {
|
|
146
|
-
// Explicit: decode the inner TLV from the contents
|
|
147
|
-
const innerReader = new ByteReader(contents);
|
|
148
|
-
return berDecodeReader(def.innerType, innerReader, opts);
|
|
149
|
-
}
|
|
150
|
-
// Implicit: the contents ARE the inner value (tag was replaced)
|
|
151
|
-
return decodeContents(def.innerType, contents, opts);
|
|
152
|
-
}
|
|
153
|
-
function decodeChoice(def, reader, opts) {
|
|
154
|
-
// Peek at the next tag to find which alternative matches
|
|
155
|
-
const savedPos = reader.position;
|
|
156
|
-
const { tag: nextTag } = readTlv(reader);
|
|
157
|
-
reader.seek(savedPos);
|
|
158
|
-
let fallback;
|
|
159
|
-
for (const altDef of choiceAlternatives(def)) {
|
|
160
|
-
const tags = outerTagSet(altDef.type, decodingError);
|
|
161
|
-
if (tags === undefined) {
|
|
162
|
-
fallback ??= altDef;
|
|
163
|
-
}
|
|
164
|
-
else if (outerTagSetHas(tags, nextTag)) {
|
|
165
|
-
const value = berDecodeReader(altDef.type, reader, opts);
|
|
166
|
-
return { kind: altDef.name, value };
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (fallback !== undefined) {
|
|
170
|
-
return {
|
|
171
|
-
kind: fallback.name,
|
|
172
|
-
value: berDecodeReader(fallback.type, reader, opts),
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
throw new DecodingError(`CHOICE: no alternative matches tag ${nextTag.tagClass} ${nextTag.tagNumber}`, reader.position);
|
|
176
|
-
}
|
|
177
|
-
function decodeSequenceContents(def, contents, opts) {
|
|
178
|
-
const reader = new ByteReader(contents);
|
|
179
|
-
const result = {};
|
|
180
|
-
for (const comp of def.components) {
|
|
181
|
-
if (comp.kind === "extensionMarker" || comp.kind === "componentsOf")
|
|
182
|
-
continue;
|
|
183
|
-
if (comp.kind === "extensionAdditionGroup") {
|
|
184
|
-
for (const inner of comp.components) {
|
|
185
|
-
decodeComponentFrom(reader, inner, result, opts);
|
|
186
|
-
}
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
decodeComponentFrom(reader, comp, result, opts);
|
|
190
|
-
}
|
|
191
|
-
return result;
|
|
192
|
-
}
|
|
193
|
-
function decodeComponentFrom(reader, comp, result, opts) {
|
|
194
|
-
if (reader.atEnd) {
|
|
195
|
-
if (comp.defaultValue !== undefined) {
|
|
196
|
-
setRecordEntry(result, comp.name, freshDefault(comp));
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
if (comp.optional)
|
|
200
|
-
return;
|
|
201
|
-
throw new DecodingError(`Required component "${comp.name}" missing`);
|
|
202
|
-
}
|
|
203
|
-
// Peek at next tag to determine if this optional component is present
|
|
204
|
-
const savedPos = reader.position;
|
|
205
|
-
const { tag: nextTag } = readTlv(reader);
|
|
206
|
-
reader.seek(savedPos);
|
|
207
|
-
if (!outerTagSetHas(outerTagSet(comp.type, decodingError), nextTag)) {
|
|
208
|
-
if (comp.optional || comp.defaultValue !== undefined) {
|
|
209
|
-
if (comp.defaultValue !== undefined)
|
|
210
|
-
setRecordEntry(result, comp.name, freshDefault(comp));
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
throw new DecodingError(`Required component "${comp.name}": tag mismatch`);
|
|
214
|
-
}
|
|
215
|
-
setRecordEntry(result, comp.name, berDecodeReader(comp.type, reader, opts));
|
|
216
|
-
}
|
|
217
|
-
function decodeOfContents(elementDef, contents, opts) {
|
|
218
|
-
const reader = new ByteReader(contents);
|
|
219
|
-
const result = [];
|
|
220
|
-
while (!reader.atEnd) {
|
|
221
|
-
result.push(berDecodeReader(elementDef, reader, opts));
|
|
222
|
-
}
|
|
223
|
-
return result;
|
|
32
|
+
export function berDecode(def, bytes, opts = {}) {
|
|
33
|
+
return decodeBerFamily(def, bytes, opts.strict ? BER_STRICT_POLICY : BER_POLICY).value;
|
|
224
34
|
}
|
|
225
35
|
//# sourceMappingURL=decode.js.map
|
package/dist/ber/decode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../../src/ber/decode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../../src/ber/decode.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAO9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,SAAS,CACxB,GAAM,EACN,KAAiB,EACjB,IAAI,GAAqB,EAAE;IAE3B,OAAO,eAAe,CACrB,GAAG,EACH,KAAK,EACL,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,UAAU,CAC5C,CAAC,KAAsB,CAAC;AAC1B,CAAC"}
|
package/dist/ber/encode.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ export interface BerEncodeOptions {
|
|
|
7
7
|
*/
|
|
8
8
|
readonly indefiniteLength?: boolean;
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* BER encoder — produces a complete TLV for the given def + value. Tags wrap or
|
|
12
|
+
* replace as in `derEncode` and `cerEncode`: an IMPLICIT tag on an untagged
|
|
13
|
+
* CHOICE, ANY or open type is EXPLICIT (X.680 §31.2.7), and the constructed bit
|
|
14
|
+
* follows the form of what the tag wraps or replaces, through `lazy`,
|
|
15
|
+
* `transform`, parameterized and tagged types.
|
|
16
|
+
*/
|
|
11
17
|
export declare function berEncode<D extends AnyAsn1TypeDef>(def: D, value: DefInputOf<D>, opts?: BerEncodeOptions): Uint8Array;
|
|
12
18
|
//# sourceMappingURL=encode.d.ts.map
|
package/dist/ber/encode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/ber/encode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/ber/encode.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAqB5D,MAAM,WAAW,gBAAgB;IAChC;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;CACpC;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,cAAc,EACjD,GAAG,EAAE,CAAC,EACN,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,EACpB,IAAI,GAAE,gBAAqB,GACzB,UAAU,CAEZ"}
|
package/dist/ber/encode.js
CHANGED
|
@@ -1,65 +1,64 @@
|
|
|
1
1
|
import { ByteBuilder, bigIntToBytesBe, encodeTextLatin1, encodeTextUtf16Be, encodeTextUtf32Be, encodeTextUtf8, } from "@ac-kit/core";
|
|
2
|
-
import {
|
|
2
|
+
import { effectiveTaggingMode, isConstructedEncoding, unwrapDef, } from "../_encoding/def-tags.js";
|
|
3
3
|
import { writeTlv, writeTlvIndefinite } from "../_encoding/tlv.js";
|
|
4
4
|
import { encodeBitString, encodeGeneralizedTime, encodeOid, encodeReal, encodeRelativeOid, encodeUtcTime, } from "../_encoding/values.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
5
|
+
import { EncodingError } from "../errors.js";
|
|
6
|
+
import { universalTagFor } from "./tags.js";
|
|
7
|
+
const encodingError = (message) => new EncodingError(message);
|
|
8
|
+
/**
|
|
9
|
+
* BER encoder — produces a complete TLV for the given def + value. Tags wrap or
|
|
10
|
+
* replace as in `derEncode` and `cerEncode`: an IMPLICIT tag on an untagged
|
|
11
|
+
* CHOICE, ANY or open type is EXPLICIT (X.680 §31.2.7), and the constructed bit
|
|
12
|
+
* follows the form of what the tag wraps or replaces, through `lazy`,
|
|
13
|
+
* `transform`, parameterized and tagged types.
|
|
14
|
+
*/
|
|
8
15
|
export function berEncode(def, value, opts = {}) {
|
|
9
16
|
return berEncodeDef(def, value, opts);
|
|
10
17
|
}
|
|
11
18
|
function berEncodeDef(def, value, opts) {
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
return berEncodeDef(inner, value, opts);
|
|
16
|
-
}
|
|
17
|
-
if (def.kind === "transform") {
|
|
18
|
-
return berEncodeDef(def.innerType, value, opts);
|
|
19
|
-
}
|
|
20
|
-
if (def.kind === "parameterizedTypeInstance") {
|
|
21
|
-
// parameterizedTypeInstance: resolve before encoding
|
|
22
|
-
return berEncodeDef(resolveInstance(def), value, opts);
|
|
23
|
-
}
|
|
24
|
-
// Tagged types
|
|
25
|
-
if (def.kind === "tagged") {
|
|
26
|
-
return encodeTagged(def, value, opts);
|
|
27
|
-
}
|
|
19
|
+
const base = unwrapDef(def, encodingError);
|
|
20
|
+
if (base.kind === "tagged")
|
|
21
|
+
return encodeTagged(base, value, opts);
|
|
28
22
|
// Encode contents, then wrap with UNIVERSAL tag
|
|
29
|
-
const contents = encodeContents(
|
|
30
|
-
const tagInfo = universalTagFor(
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
const contents = encodeContents(base, value, opts);
|
|
24
|
+
const tagInfo = universalTagFor(base);
|
|
25
|
+
// CHOICE or ANY: already a whole TLV
|
|
26
|
+
if (!tagInfo)
|
|
33
27
|
return contents;
|
|
34
|
-
|
|
35
|
-
const tag = {
|
|
28
|
+
return writeElement({
|
|
36
29
|
tagClass: "universal",
|
|
37
30
|
tagNumber: tagInfo.tagNumber,
|
|
38
31
|
constructed: tagInfo.constructed,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return
|
|
32
|
+
}, contents, opts);
|
|
33
|
+
}
|
|
34
|
+
/** Definite or, when asked and the encoding is constructed, indefinite length. */
|
|
35
|
+
function writeElement(tag, contents, opts) {
|
|
36
|
+
return opts.indefiniteLength && tag.constructed
|
|
37
|
+
? writeTlvIndefinite(tag, contents)
|
|
38
|
+
: writeTlv(tag, contents);
|
|
44
39
|
}
|
|
45
40
|
function encodeTagged(def, value, opts) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
41
|
+
const tag = {
|
|
42
|
+
tagClass: def.tag.tagClass,
|
|
43
|
+
tagNumber: def.tag.tagNumber,
|
|
44
|
+
constructed: isConstructedEncoding(def, encodingError) ?? false,
|
|
45
|
+
};
|
|
46
|
+
return effectiveTaggingMode(def, encodingError) === "explicit"
|
|
47
|
+
? writeElement(tag, berEncodeDef(def.innerType, value, opts), opts)
|
|
48
|
+
: encodeAs(tag, def.innerType, value, opts);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Writes `def`'s contents under `tag`, which replaced the tag `def` would carry
|
|
52
|
+
* (an IMPLICIT tag).
|
|
53
|
+
*/
|
|
54
|
+
function encodeAs(tag, def, value, opts) {
|
|
55
|
+
const base = unwrapDef(def, encodingError);
|
|
56
|
+
if (base.kind !== "tagged") {
|
|
57
|
+
return writeElement(tag, encodeContents(base, value, opts), opts);
|
|
61
58
|
}
|
|
62
|
-
return
|
|
59
|
+
return effectiveTaggingMode(base, encodingError) === "explicit"
|
|
60
|
+
? writeElement(tag, berEncodeDef(base.innerType, value, opts), opts)
|
|
61
|
+
: encodeAs(tag, base.innerType, value, opts);
|
|
63
62
|
}
|
|
64
63
|
/** Encode the VALUE portion (contents) without the TLV wrapper. */
|
|
65
64
|
function encodeContents(def, value, opts = {}) {
|
|
@@ -133,12 +132,6 @@ function encodeContents(def, value, opts = {}) {
|
|
|
133
132
|
if (value instanceof Uint8Array)
|
|
134
133
|
return value;
|
|
135
134
|
return new Uint8Array(0);
|
|
136
|
-
case "lazy": {
|
|
137
|
-
const inner = def.getter();
|
|
138
|
-
return encodeContents(inner, value, opts);
|
|
139
|
-
}
|
|
140
|
-
case "transform":
|
|
141
|
-
return encodeContents(def.innerType, value, opts);
|
|
142
135
|
default:
|
|
143
136
|
throw new EncodingError(`Cannot BER-encode def kind: ${def.kind}`);
|
|
144
137
|
}
|
package/dist/ber/encode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../src/ber/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,GACd,MAAM,cAAc,CAAC;AAEtB,OAAO,
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../src/ber/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,GACd,MAAM,cAAc,CAAC;AAEtB,OAAO,EACN,oBA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