@ac-kit/format-asn1 0.3.1 → 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 +68 -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
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
import { concatBytes, describeValue, isIntegerInRange, } from "@ac-kit/core";
|
|
2
|
+
import { CER_STRING_SEGMENT_OCTETS, MAX_DECODE_DEPTH, } from "../_encoding/constants.js";
|
|
3
|
+
import { DecodingError } from "../errors.js";
|
|
4
|
+
import { createShared, parseHeader, reportNonCanonical, RULES_BER, RULES_CER, RULES_DER, walkIndefinite, } from "./_framing.js";
|
|
5
|
+
import { DEFAULT_MAX_TAG_OCTETS, limitError, TAG_CLASSES } from "./_header.js";
|
|
6
|
+
const STATE_IDLE = 0;
|
|
7
|
+
const STATE_HEADER = 1;
|
|
8
|
+
const STATE_LOCKED = 2;
|
|
9
|
+
const STATE_CLOSED = 3;
|
|
10
|
+
// Running the caller's `onNonCanonical`: the reader refuses every call made from it.
|
|
11
|
+
const STATE_BUSY = 4;
|
|
12
|
+
const UNIVERSAL_BIT_STRING = 0x03;
|
|
13
|
+
const UNIVERSAL_OCTET_STRING = 0x04;
|
|
14
|
+
// What `enter()` hands to the constructor of the child it makes, so that a
|
|
15
|
+
// child costs one allocation and nothing internal shows in the public
|
|
16
|
+
// signature.
|
|
17
|
+
let pendingParent;
|
|
18
|
+
let pendingPosition = 0;
|
|
19
|
+
let pendingBound = 0;
|
|
20
|
+
let pendingIndefinite = false;
|
|
21
|
+
let pendingInputEnd = false;
|
|
22
|
+
/** A reader over the contents of one of `parent`'s elements. */
|
|
23
|
+
function makeChild(parent, bytes, position, bound, indefinite, inputEnd) {
|
|
24
|
+
pendingParent = parent;
|
|
25
|
+
pendingPosition = position;
|
|
26
|
+
pendingBound = bound;
|
|
27
|
+
pendingIndefinite = indefinite;
|
|
28
|
+
pendingInputEnd = inputEnd;
|
|
29
|
+
return new BerReader(bytes, parent.rules);
|
|
30
|
+
}
|
|
31
|
+
function validateRules(rules) {
|
|
32
|
+
switch (rules) {
|
|
33
|
+
case "ber":
|
|
34
|
+
return RULES_BER;
|
|
35
|
+
case "cer":
|
|
36
|
+
return RULES_CER;
|
|
37
|
+
case "der":
|
|
38
|
+
return RULES_DER;
|
|
39
|
+
default:
|
|
40
|
+
throw new RangeError(`BerReader: rules must be "ber", "cer" or "der", got ${describeValue(rules)}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A forward-only cursor over BER, CER or DER bytes (X.690 §8–§10).
|
|
45
|
+
*
|
|
46
|
+
* One reader reads the elements of one level: the whole view for the reader the
|
|
47
|
+
* constructor returns, the contents of a constructed element for one `enter()`
|
|
48
|
+
* returns. `peekHeader()` reads the next element's identifier and length octets
|
|
49
|
+
* without consuming it; `readContents()`, `readElement()`, `skip()`, `enter()`,
|
|
50
|
+
* `readOctetStringContents()` or `readBitStringContents()` then consumes it.
|
|
51
|
+
* Every offset is relative to the view given to the root reader's constructor,
|
|
52
|
+
* children included.
|
|
53
|
+
*
|
|
54
|
+
* End-of-contents octets are recognised only where an indefinite-length element
|
|
55
|
+
* may end. Nothing is copied except by the two string helpers for a constructed
|
|
56
|
+
* string. The reader holds no resource: no `Symbol.dispose`.
|
|
57
|
+
*
|
|
58
|
+
* A method that throws (a `DecodingError`, or what `onNonCanonical` throws)
|
|
59
|
+
* consumes nothing: the reader stays open at the same offset, with no child
|
|
60
|
+
* open, so the element can be read again, with other rules, or the level ended
|
|
61
|
+
* with `finish()`. The current header, if any, may be gone: peek it again.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // The bytes a certificate's signature covers, as received.
|
|
65
|
+
* const certificate = new BerReader(der, "der").enter();
|
|
66
|
+
* const tbsCertificate = certificate.readElement();
|
|
67
|
+
*/
|
|
68
|
+
export class BerReader {
|
|
69
|
+
/** The rules this reader and every reader `enter()` derives from it enforce. */
|
|
70
|
+
rules;
|
|
71
|
+
/** 0 for a reader made by the constructor; its parent's depth + 1 otherwise. */
|
|
72
|
+
depth;
|
|
73
|
+
shared_;
|
|
74
|
+
parent_;
|
|
75
|
+
bound_;
|
|
76
|
+
indefinite_;
|
|
77
|
+
inputEnd_;
|
|
78
|
+
position_;
|
|
79
|
+
state_;
|
|
80
|
+
/**
|
|
81
|
+
* @param bytes - The view to read; not copied, so it must not change while a
|
|
82
|
+
* reader of it is in use. What a reader has parsed is not read again: a
|
|
83
|
+
* change cannot make a header's getters disagree, but the result of later
|
|
84
|
+
* reads is unspecified.
|
|
85
|
+
* @param rules - The rules to enforce.
|
|
86
|
+
* @param options - See {@link BerReaderOptions}.
|
|
87
|
+
* @throws {RangeError} When `rules` is not one of the three, or
|
|
88
|
+
* `options.maxTagOctets` is not a positive safe integer.
|
|
89
|
+
*/
|
|
90
|
+
constructor(bytes, rules, options) {
|
|
91
|
+
const parent = pendingParent;
|
|
92
|
+
if (parent !== undefined) {
|
|
93
|
+
pendingParent = undefined;
|
|
94
|
+
this.rules = parent.rules;
|
|
95
|
+
this.depth = parent.depth + 1;
|
|
96
|
+
this.shared_ = parent.shared_;
|
|
97
|
+
this.parent_ = parent;
|
|
98
|
+
this.bound_ = pendingBound;
|
|
99
|
+
this.indefinite_ = pendingIndefinite;
|
|
100
|
+
this.inputEnd_ = pendingInputEnd;
|
|
101
|
+
this.position_ = pendingPosition;
|
|
102
|
+
this.state_ = STATE_IDLE;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const rulesCode = validateRules(rules);
|
|
106
|
+
const maxTagOctets = options?.maxTagOctets ?? DEFAULT_MAX_TAG_OCTETS;
|
|
107
|
+
if (!isIntegerInRange(maxTagOctets, 1, Number.MAX_SAFE_INTEGER + 1)) {
|
|
108
|
+
throw new RangeError(`BerReader: maxTagOctets must be a positive safe integer, got ${describeValue(maxTagOctets)}`);
|
|
109
|
+
}
|
|
110
|
+
this.rules = rules;
|
|
111
|
+
this.depth = 0;
|
|
112
|
+
this.shared_ = createShared(bytes, rulesCode, maxTagOctets, rulesCode === RULES_BER ? undefined : options?.onNonCanonical);
|
|
113
|
+
this.parent_ = undefined;
|
|
114
|
+
this.bound_ = bytes.length;
|
|
115
|
+
this.indefinite_ = false;
|
|
116
|
+
this.inputEnd_ = true;
|
|
117
|
+
this.position_ = 0;
|
|
118
|
+
this.state_ = STATE_IDLE;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Offset of the next element of this level: the start of the current header's
|
|
122
|
+
* element while one is current, the end of the last consumed one otherwise.
|
|
123
|
+
*
|
|
124
|
+
* @throws {TypeError} While a child is open, or after `finish()`.
|
|
125
|
+
*/
|
|
126
|
+
get offset() {
|
|
127
|
+
this.assertOpen_();
|
|
128
|
+
return this.position_;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Whether no element is left at this level: the end of the view (root), of
|
|
132
|
+
* the contents (definite length), or end-of-contents octets next (indefinite
|
|
133
|
+
* length). `false` while a header is current. O(1); consumes nothing.
|
|
134
|
+
*
|
|
135
|
+
* @throws {TypeError} While a child is open, or after `finish()`.
|
|
136
|
+
*/
|
|
137
|
+
get atEnd() {
|
|
138
|
+
this.assertOpen_();
|
|
139
|
+
if (this.state_ === STATE_HEADER)
|
|
140
|
+
return false;
|
|
141
|
+
const position = this.position_;
|
|
142
|
+
if (!this.indefinite_)
|
|
143
|
+
return position >= this.bound_;
|
|
144
|
+
const bytes = this.shared_.bytes;
|
|
145
|
+
return (position + 2 <= this.bound_ &&
|
|
146
|
+
bytes[position] === 0 &&
|
|
147
|
+
bytes[position + 1] === 0);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Reads the identifier and length octets of the next element and makes them
|
|
151
|
+
* the current header, without consuming the element. Returns at once while a
|
|
152
|
+
* header is current. O(identifier + length octets); allocates nothing for a
|
|
153
|
+
* low tag number (one `ByteReader` for a high one).
|
|
154
|
+
*
|
|
155
|
+
* @throws {DecodingError} `missing-element` (none left at a level inside an
|
|
156
|
+
* element), `truncated` (none left in the view, or the input ends inside
|
|
157
|
+
* the header or contents), `overrun`, `invalid-tag`, `limit-exceeded`,
|
|
158
|
+
* `invalid-length`, `invalid-end-of-contents`, or `non-canonical` (the
|
|
159
|
+
* rules forbid the length form; not with `onNonCanonical`).
|
|
160
|
+
* @throws {TypeError} While a child is open, or after `finish()`.
|
|
161
|
+
*/
|
|
162
|
+
peekHeader() {
|
|
163
|
+
if (this.state_ === STATE_HEADER)
|
|
164
|
+
return;
|
|
165
|
+
this.assertOpen_();
|
|
166
|
+
const position = this.position_;
|
|
167
|
+
const bound = this.bound_;
|
|
168
|
+
if (this.indefinite_) {
|
|
169
|
+
const bytes = this.shared_.bytes;
|
|
170
|
+
if (position + 2 <= bound &&
|
|
171
|
+
bytes[position] === 0 &&
|
|
172
|
+
bytes[position + 1] === 0) {
|
|
173
|
+
throw new DecodingError("An element is required, but end-of-contents octets come next", position, "missing-element");
|
|
174
|
+
}
|
|
175
|
+
if (position >= bound) {
|
|
176
|
+
throw limitError("missing end-of-contents octets (X.690 §8.1.3.6)", bound, this.inputEnd_);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else if (position >= bound) {
|
|
180
|
+
throw this.parent_ === undefined
|
|
181
|
+
? new DecodingError("Input truncated: an element is required", bound, "truncated")
|
|
182
|
+
: new DecodingError("An element is required, but none is left in the contents", bound, "missing-element");
|
|
183
|
+
}
|
|
184
|
+
if (this.shared_.onNonCanonical === undefined) {
|
|
185
|
+
parseHeader(this.shared_, position, bound, this.inputEnd_);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
this.state_ = STATE_BUSY;
|
|
189
|
+
try {
|
|
190
|
+
parseHeader(this.shared_, position, bound, this.inputEnd_);
|
|
191
|
+
}
|
|
192
|
+
finally {
|
|
193
|
+
this.state_ = STATE_IDLE;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
this.state_ = STATE_HEADER;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Class of the current header.
|
|
200
|
+
*
|
|
201
|
+
* @throws {TypeError} When none is current.
|
|
202
|
+
*/
|
|
203
|
+
get tagClass() {
|
|
204
|
+
this.assertHeader_();
|
|
205
|
+
return TAG_CLASSES[this.shared_.scratch.identifier >> 6];
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Tag number of the current header, or `null` above `Number.MAX_SAFE_INTEGER`
|
|
209
|
+
* (see {@link BerReader.bigTagNumber}).
|
|
210
|
+
*
|
|
211
|
+
* @throws {TypeError} When none is current.
|
|
212
|
+
*/
|
|
213
|
+
get tagNumber() {
|
|
214
|
+
this.assertHeader_();
|
|
215
|
+
return this.shared_.scratch.tagNumber;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Exact tag number of the current header: the one `tagNumber` gives, as a
|
|
219
|
+
* `bigint`, or the larger one it hides. Allocates.
|
|
220
|
+
*
|
|
221
|
+
* @throws {TypeError} When none is current.
|
|
222
|
+
*/
|
|
223
|
+
bigTagNumber() {
|
|
224
|
+
this.assertHeader_();
|
|
225
|
+
const scratch = this.shared_.scratch;
|
|
226
|
+
return scratch.tagNumber === null
|
|
227
|
+
? scratch.hugeTagNumber
|
|
228
|
+
: BigInt(scratch.tagNumber);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Whether the current header has the constructed bit.
|
|
232
|
+
*
|
|
233
|
+
* @throws {TypeError} When none is current.
|
|
234
|
+
*/
|
|
235
|
+
get constructed() {
|
|
236
|
+
this.assertHeader_();
|
|
237
|
+
return (this.shared_.scratch.identifier & 0x20) !== 0;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Offset of the current element's contents.
|
|
241
|
+
*
|
|
242
|
+
* @throws {TypeError} When none is current.
|
|
243
|
+
*/
|
|
244
|
+
get contentsOffset() {
|
|
245
|
+
this.assertHeader_();
|
|
246
|
+
return this.shared_.scratch.contentsOffset;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Length of the current element's contents, or `null` for the indefinite
|
|
250
|
+
* form.
|
|
251
|
+
*
|
|
252
|
+
* @throws {TypeError} When none is current.
|
|
253
|
+
*/
|
|
254
|
+
get contentsLength() {
|
|
255
|
+
this.assertHeader_();
|
|
256
|
+
const length = this.shared_.scratch.contentsLength;
|
|
257
|
+
return length < 0 ? null : length;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Consumes the next element and returns its contents octets as a view,
|
|
261
|
+
* without the end-of-contents octets. O(1) for a definite length; for the
|
|
262
|
+
* indefinite form O(element size) time and O(1) memory, checking the framing
|
|
263
|
+
* of the indefinite-length elements nested in it (not of what lies inside
|
|
264
|
+
* nested definite-length ones).
|
|
265
|
+
*
|
|
266
|
+
* @throws {DecodingError} As {@link BerReader.peekHeader}, and for what the
|
|
267
|
+
* walk finds.
|
|
268
|
+
* @throws {TypeError} While a child is open, or after `finish()`.
|
|
269
|
+
*/
|
|
270
|
+
readContents() {
|
|
271
|
+
this.peekHeader();
|
|
272
|
+
const contentsOffset = this.shared_.scratch.contentsOffset;
|
|
273
|
+
const contentsEnd = this.advance_();
|
|
274
|
+
return this.shared_.bytes.subarray(contentsOffset, contentsEnd);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* As {@link BerReader.readContents}, returning the whole element: header,
|
|
278
|
+
* contents and end-of-contents octets.
|
|
279
|
+
*/
|
|
280
|
+
readElement() {
|
|
281
|
+
this.peekHeader();
|
|
282
|
+
const start = this.position_;
|
|
283
|
+
this.advance_();
|
|
284
|
+
return this.shared_.bytes.subarray(start, this.position_);
|
|
285
|
+
}
|
|
286
|
+
/** As {@link BerReader.readContents}, returning nothing. */
|
|
287
|
+
skip() {
|
|
288
|
+
this.peekHeader();
|
|
289
|
+
this.advance_();
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Consumes the next element, which must be constructed, and returns a reader
|
|
293
|
+
* over its contents. This reader then throws `TypeError` until the child's
|
|
294
|
+
* `finish()`, after which it continues past the element. O(1); allocates the
|
|
295
|
+
* child.
|
|
296
|
+
*
|
|
297
|
+
* @throws {DecodingError} As {@link BerReader.peekHeader};
|
|
298
|
+
* `unexpected-element` for a primitive element.
|
|
299
|
+
* @throws {TypeError} While a child is open, or after `finish()`.
|
|
300
|
+
*/
|
|
301
|
+
enter() {
|
|
302
|
+
this.peekHeader();
|
|
303
|
+
const scratch = this.shared_.scratch;
|
|
304
|
+
if ((scratch.identifier & 0x20) === 0) {
|
|
305
|
+
throw new DecodingError("A constructed element is required, got a primitive one", this.position_, "unexpected-element");
|
|
306
|
+
}
|
|
307
|
+
const length = scratch.contentsLength;
|
|
308
|
+
this.state_ = STATE_LOCKED;
|
|
309
|
+
return makeChild(this, this.shared_.bytes, scratch.contentsOffset, length < 0 ? this.bound_ : scratch.contentsOffset + length, length < 0, length < 0 ? this.inputEnd_ : false);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Ends this reader: checks no element is left, consumes the end-of-contents
|
|
313
|
+
* octets of an indefinite-length level, and lets the parent continue after
|
|
314
|
+
* the element. On a root reader, checks the whole view was read.
|
|
315
|
+
*
|
|
316
|
+
* @throws {DecodingError} `trailing-data` (an element is left, also when its
|
|
317
|
+
* header was peeked but not consumed); `truncated` or `overrun` (an
|
|
318
|
+
* indefinite-length level reaches its bound, or ends in a single `00`,
|
|
319
|
+
* without end-of-contents octets); `invalid-end-of-contents` (octets that
|
|
320
|
+
* begin like them but are not `00 00`).
|
|
321
|
+
* @throws {TypeError} While a child is open, after `finish()`, or from
|
|
322
|
+
* `onNonCanonical`.
|
|
323
|
+
*/
|
|
324
|
+
finish() {
|
|
325
|
+
this.assertOpen_();
|
|
326
|
+
if (this.state_ === STATE_HEADER) {
|
|
327
|
+
throw new DecodingError("An element is left where nothing may follow", this.position_, "trailing-data");
|
|
328
|
+
}
|
|
329
|
+
const position = this.position_;
|
|
330
|
+
const bound = this.bound_;
|
|
331
|
+
let resume = bound;
|
|
332
|
+
if (this.indefinite_) {
|
|
333
|
+
const bytes = this.shared_.bytes;
|
|
334
|
+
if (position + 2 <= bound &&
|
|
335
|
+
bytes[position] === 0 &&
|
|
336
|
+
bytes[position + 1] === 0) {
|
|
337
|
+
resume = position + 2;
|
|
338
|
+
}
|
|
339
|
+
else if (position >= bound) {
|
|
340
|
+
throw limitError("missing end-of-contents octets (X.690 §8.1.3.6)", bound, this.inputEnd_);
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
// End-of-contents octets cut short or malformed: the parser says which.
|
|
344
|
+
if ((bytes[position] & 0xdf) === 0) {
|
|
345
|
+
parseHeader(this.shared_, position, bound, this.inputEnd_);
|
|
346
|
+
}
|
|
347
|
+
throw new DecodingError("An element is left where the end-of-contents octets are required", position, "trailing-data");
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
else if (position < bound) {
|
|
351
|
+
throw new DecodingError("An element is left where nothing may follow", position, "trailing-data");
|
|
352
|
+
}
|
|
353
|
+
this.state_ = STATE_CLOSED;
|
|
354
|
+
const parent = this.parent_;
|
|
355
|
+
if (parent !== undefined) {
|
|
356
|
+
parent.position_ = resume;
|
|
357
|
+
parent.state_ = STATE_IDLE;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Consumes the next element as a string encoded like an OCTET STRING (OCTET
|
|
362
|
+
* STRING, the restricted character strings, UTCTime, GeneralizedTime)
|
|
363
|
+
* whatever its tag, and returns the contents of its primitive form: a view
|
|
364
|
+
* for a primitive element, a fresh array joining the segments of a
|
|
365
|
+
* constructed one (X.690 §8.7.3, §8.23). Each segment must be an OCTET STRING
|
|
366
|
+
* (UNIVERSAL 4); BER allows constructed segments, nested at most 512 levels
|
|
367
|
+
* deep. CER (§9.2): the primitive form if and only if 1000 octets or fewer,
|
|
368
|
+
* primitive segments of exactly 1000 octets but the last (1 to 1000). DER
|
|
369
|
+
* (§10.2): primitive only. O(element size).
|
|
370
|
+
*
|
|
371
|
+
* @throws {DecodingError} As {@link BerReader.readContents};
|
|
372
|
+
* `unexpected-element` for a segment that is not an OCTET STRING;
|
|
373
|
+
* `limit-exceeded` for segments nested deeper than 512 levels;
|
|
374
|
+
* `non-canonical` for a CER or DER violation (not with `onNonCanonical`).
|
|
375
|
+
*/
|
|
376
|
+
readOctetStringContents() {
|
|
377
|
+
return this.readString_(UNIVERSAL_OCTET_STRING);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* As {@link BerReader.readOctetStringContents} for a BIT STRING (X.690
|
|
381
|
+
* §8.6.4): segments are BIT STRINGs (UNIVERSAL 3) with at least the
|
|
382
|
+
* unused-bits octet, a segment with unused bits being the last one at every
|
|
383
|
+
* level (no segment, however empty, follows it), and the result is the
|
|
384
|
+
* primitive contents: the last segment's unused-bits octet, then every
|
|
385
|
+
* segment's bits (`00` for a constructed BIT STRING with no segment). CER
|
|
386
|
+
* segments hold exactly 1000 contents octets but the last. The unused-bits
|
|
387
|
+
* value and padding are the value decoder's to check.
|
|
388
|
+
*
|
|
389
|
+
* @throws {DecodingError} As {@link BerReader.readOctetStringContents};
|
|
390
|
+
* `invalid-contents` for a segment without its unused-bits octet or with
|
|
391
|
+
* unused bits before the last.
|
|
392
|
+
*/
|
|
393
|
+
readBitStringContents() {
|
|
394
|
+
return this.readString_(UNIVERSAL_BIT_STRING);
|
|
395
|
+
}
|
|
396
|
+
assertOpen_() {
|
|
397
|
+
if (this.state_ >= STATE_LOCKED) {
|
|
398
|
+
throw new TypeError(this.state_ === STATE_LOCKED
|
|
399
|
+
? "BerReader: a child reader is open"
|
|
400
|
+
: this.state_ === STATE_BUSY
|
|
401
|
+
? "BerReader: called from onNonCanonical"
|
|
402
|
+
: "BerReader: finished");
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Reports a violation met while this reader holds a current header, with the
|
|
407
|
+
* reader refusing calls from the caller's callback.
|
|
408
|
+
*/
|
|
409
|
+
report_(message, offset) {
|
|
410
|
+
const state = this.state_;
|
|
411
|
+
this.state_ = STATE_BUSY;
|
|
412
|
+
try {
|
|
413
|
+
reportNonCanonical(this.shared_, message, offset);
|
|
414
|
+
}
|
|
415
|
+
finally {
|
|
416
|
+
this.state_ = state;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
assertHeader_() {
|
|
420
|
+
if (this.state_ !== STATE_HEADER) {
|
|
421
|
+
this.assertOpen_();
|
|
422
|
+
throw new TypeError("BerReader: no current header");
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Consumes the current header's element and returns the offset where its
|
|
427
|
+
* contents end, before any end-of-contents octets.
|
|
428
|
+
*/
|
|
429
|
+
advance_() {
|
|
430
|
+
const scratch = this.shared_.scratch;
|
|
431
|
+
const length = scratch.contentsLength;
|
|
432
|
+
const contentsOffset = scratch.contentsOffset;
|
|
433
|
+
if (length >= 0) {
|
|
434
|
+
const end = contentsOffset + length;
|
|
435
|
+
this.position_ = end;
|
|
436
|
+
this.state_ = STATE_IDLE;
|
|
437
|
+
return end;
|
|
438
|
+
}
|
|
439
|
+
// The walk reuses the scratch: no header is current any more.
|
|
440
|
+
let contentsEnd;
|
|
441
|
+
if (this.shared_.onNonCanonical === undefined) {
|
|
442
|
+
this.state_ = STATE_IDLE;
|
|
443
|
+
contentsEnd = walkIndefinite(this.shared_, contentsOffset, this.bound_, this.inputEnd_);
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
this.state_ = STATE_BUSY;
|
|
447
|
+
try {
|
|
448
|
+
contentsEnd = walkIndefinite(this.shared_, contentsOffset, this.bound_, this.inputEnd_);
|
|
449
|
+
}
|
|
450
|
+
finally {
|
|
451
|
+
this.state_ = STATE_IDLE;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
this.position_ = contentsEnd + 2;
|
|
455
|
+
return contentsEnd;
|
|
456
|
+
}
|
|
457
|
+
readString_(universal) {
|
|
458
|
+
this.peekHeader();
|
|
459
|
+
const shared = this.shared_;
|
|
460
|
+
const scratch = shared.scratch;
|
|
461
|
+
const rules = shared.rules;
|
|
462
|
+
const start = this.position_;
|
|
463
|
+
if ((scratch.identifier & 0x20) === 0) {
|
|
464
|
+
const contentsOffset = scratch.contentsOffset;
|
|
465
|
+
const length = scratch.contentsLength;
|
|
466
|
+
if (rules === RULES_CER && length > CER_STRING_SEGMENT_OCTETS) {
|
|
467
|
+
this.report_(`CER: a string of more than ${CER_STRING_SEGMENT_OCTETS} octets is constructed (X.690 §9.2)`, start);
|
|
468
|
+
}
|
|
469
|
+
this.position_ = contentsOffset + length;
|
|
470
|
+
this.state_ = STATE_IDLE;
|
|
471
|
+
return shared.bytes.subarray(contentsOffset, contentsOffset + length);
|
|
472
|
+
}
|
|
473
|
+
if (rules === RULES_DER) {
|
|
474
|
+
this.report_("DER: constructed string encoding (X.690 §10.2)", start);
|
|
475
|
+
}
|
|
476
|
+
try {
|
|
477
|
+
return this.joinSegments_(universal, start);
|
|
478
|
+
}
|
|
479
|
+
catch (error) {
|
|
480
|
+
// Whatever went wrong, no child stays open and nothing is consumed.
|
|
481
|
+
this.state_ = STATE_IDLE;
|
|
482
|
+
this.position_ = start;
|
|
483
|
+
throw error;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Joins the segments of the constructed string whose header is current, at
|
|
488
|
+
* `start`.
|
|
489
|
+
*/
|
|
490
|
+
joinSegments_(universal, start) {
|
|
491
|
+
const shared = this.shared_;
|
|
492
|
+
const scratch = shared.scratch;
|
|
493
|
+
const rules = shared.rules;
|
|
494
|
+
const isBits = universal === UNIVERSAL_BIT_STRING;
|
|
495
|
+
const segments = [];
|
|
496
|
+
const stack = [this.enter()];
|
|
497
|
+
// The segment last read: how it is checked depends on whether another follows.
|
|
498
|
+
let lastOffset = -1;
|
|
499
|
+
let lastLength = 0;
|
|
500
|
+
let lastUnusedBits = 0;
|
|
501
|
+
// The BIT STRING segment whose unused bits no segment may follow.
|
|
502
|
+
let unusedBitsOffset = -1;
|
|
503
|
+
let total = isBits ? 1 : 0;
|
|
504
|
+
while (stack.length > 0) {
|
|
505
|
+
const top = stack[stack.length - 1];
|
|
506
|
+
if (top.atEnd) {
|
|
507
|
+
top.finish();
|
|
508
|
+
stack.pop();
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
top.peekHeader();
|
|
512
|
+
const segmentOffset = top.position_;
|
|
513
|
+
if ((scratch.identifier & 0xdf) !== universal) {
|
|
514
|
+
throw new DecodingError(`${isBits ? "BIT" : "OCTET"} STRING segment expected, got another tag (X.690 ${isBits ? "§8.6.4" : "§8.7.3"})`, segmentOffset, "unexpected-element");
|
|
515
|
+
}
|
|
516
|
+
if (unusedBitsOffset >= 0) {
|
|
517
|
+
throw new DecodingError("BIT STRING segment with unused bits before the last (X.690 §8.6.4)", unusedBitsOffset, "invalid-contents");
|
|
518
|
+
}
|
|
519
|
+
if ((scratch.identifier & 0x20) !== 0) {
|
|
520
|
+
if (rules === RULES_CER) {
|
|
521
|
+
reportNonCanonical(shared, "CER: constructed string segment (X.690 §9.2)", segmentOffset);
|
|
522
|
+
}
|
|
523
|
+
if (stack.length >= MAX_DECODE_DEPTH) {
|
|
524
|
+
throw new DecodingError(`Constructed string segments nested deeper than ${MAX_DECODE_DEPTH} levels`, segmentOffset, "limit-exceeded");
|
|
525
|
+
}
|
|
526
|
+
stack.push(top.enter());
|
|
527
|
+
continue;
|
|
528
|
+
}
|
|
529
|
+
const contents = top.readContents();
|
|
530
|
+
const length = contents.length;
|
|
531
|
+
if (isBits) {
|
|
532
|
+
if (length === 0) {
|
|
533
|
+
throw new DecodingError("BIT STRING segment without its initial octet (X.690 §8.6.2)", segmentOffset, "invalid-contents");
|
|
534
|
+
}
|
|
535
|
+
lastUnusedBits = contents[0];
|
|
536
|
+
if (lastUnusedBits !== 0)
|
|
537
|
+
unusedBitsOffset = segmentOffset;
|
|
538
|
+
segments.push(contents.subarray(1));
|
|
539
|
+
total += length - 1;
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
segments.push(contents);
|
|
543
|
+
total += length;
|
|
544
|
+
}
|
|
545
|
+
if (rules === RULES_CER &&
|
|
546
|
+
lastOffset >= 0 &&
|
|
547
|
+
lastLength !== CER_STRING_SEGMENT_OCTETS) {
|
|
548
|
+
reportNonCanonical(shared, `CER: string segment of ${lastLength} octets before the last, ${CER_STRING_SEGMENT_OCTETS} required (X.690 §9.2)`, lastOffset);
|
|
549
|
+
}
|
|
550
|
+
lastOffset = segmentOffset;
|
|
551
|
+
lastLength = length;
|
|
552
|
+
}
|
|
553
|
+
if (rules === RULES_CER) {
|
|
554
|
+
if (total <= CER_STRING_SEGMENT_OCTETS) {
|
|
555
|
+
this.report_(`CER: a string of ${CER_STRING_SEGMENT_OCTETS} octets or fewer is primitive (X.690 §9.2)`, start);
|
|
556
|
+
}
|
|
557
|
+
else if (lastLength === 0 || lastLength > CER_STRING_SEGMENT_OCTETS) {
|
|
558
|
+
this.report_(`CER: last string segment of ${lastLength} octets, 1 to ${CER_STRING_SEGMENT_OCTETS} required (X.690 §9.2)`, lastOffset);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
if (isBits) {
|
|
562
|
+
segments.unshift(Uint8Array.of(lastUnusedBits));
|
|
563
|
+
}
|
|
564
|
+
return concatBytes(segments);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
//# sourceMappingURL=ber-reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ber-reader.js","sourceRoot":"","sources":["../../src/reader/ber-reader.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,WAAW,EACX,aAAa,EACb,gBAAgB,GAEhB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACN,yBAAyB,EACzB,gBAAgB,GAChB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EACN,YAAY,EACZ,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,SAAS,EACT,SAAS,EACT,cAAc,GAEd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AA+B/E,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,qFAAqF;AACrF,MAAM,UAAU,GAAG,CAAC,CAAC;AAErB,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAClC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAEpC,2EAA2E;AAC3E,sEAAsE;AACtE,aAAa;AACb,IAAI,aAAqD,CAAC;AAC1D,IAAI,eAAe,GAAG,CAAC,CAAC;AACxB,IAAI,YAAY,GAAG,CAAC,CAAC;AACrB,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAC9B,IAAI,eAAe,GAAG,KAAK,CAAC;AAE5B,gEAAgE;AAChE,SAAS,SAAS,CACjB,MAA+B,EAC/B,KAA+B,EAC/B,QAAgB,EAChB,KAAa,EACb,UAAmB,EACnB,QAAiB;IAEjB,aAAa,GAAG,MAAM,CAAC;IACvB,eAAe,GAAG,QAAQ,CAAC;IAC3B,YAAY,GAAG,KAAK,CAAC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AC,QAAQ,CAAC,CAAC;IAC9B,CAAC;CACD"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { DecodingError } from "../errors.js";
|
|
2
|
+
import type { TagClass } from "../schema/metadata.js";
|
|
3
|
+
import { type BerIssue, type X690Rules } from "./ber-reader.js";
|
|
4
|
+
export type BerInspectOptions = {
|
|
5
|
+
/** Rules whose violations are reported as `issues`; reading continues as BER. */
|
|
6
|
+
readonly rules: X690Rules;
|
|
7
|
+
/** Deepest nesting read; a root has depth 1. Positive safe integer. */
|
|
8
|
+
readonly maxDepth: number;
|
|
9
|
+
/**
|
|
10
|
+
* Most elements read across all roots, end-of-contents octets not counted.
|
|
11
|
+
* Positive safe integer.
|
|
12
|
+
*/
|
|
13
|
+
readonly maxElements: number;
|
|
14
|
+
/** As `BerReaderOptions.maxTagOctets`; default 16. */
|
|
15
|
+
readonly maxTagOctets?: number;
|
|
16
|
+
};
|
|
17
|
+
/** One element. Offsets are relative to the inspected view. */
|
|
18
|
+
export type BerElement = {
|
|
19
|
+
tagClass: TagClass;
|
|
20
|
+
tagNumber: bigint;
|
|
21
|
+
constructed: boolean;
|
|
22
|
+
indefinite: boolean;
|
|
23
|
+
/** Inclusive identifier start. */
|
|
24
|
+
start: number;
|
|
25
|
+
/** Inclusive contents start, just after the header. */
|
|
26
|
+
contentsStart: number;
|
|
27
|
+
/**
|
|
28
|
+
* Exclusive contents end, before the end-of-contents octets; `undefined` only
|
|
29
|
+
* for an indefinite-length element still open when reading stopped.
|
|
30
|
+
*/
|
|
31
|
+
contentsEnd: number | undefined;
|
|
32
|
+
/** Exclusive element end; `undefined` in the same case as `contentsEnd`. */
|
|
33
|
+
end: number | undefined;
|
|
34
|
+
/** Immediate children in wire order; empty for a primitive element. */
|
|
35
|
+
children: BerElement[];
|
|
36
|
+
/**
|
|
37
|
+
* Violations of `rules` in this element's header, in wire order; usually
|
|
38
|
+
* empty (shared).
|
|
39
|
+
*/
|
|
40
|
+
issues: readonly BerIssue[];
|
|
41
|
+
};
|
|
42
|
+
export type BerInspection = {
|
|
43
|
+
/** Every root read, in wire order; after an error, what was read before it. */
|
|
44
|
+
roots: BerElement[];
|
|
45
|
+
/**
|
|
46
|
+
* Why reading stopped before the end of the view; `undefined` when it did
|
|
47
|
+
* not.
|
|
48
|
+
*/
|
|
49
|
+
error: DecodingError | undefined;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Reads the framing of BER, CER or DER bytes into a tree, without a schema:
|
|
53
|
+
* tags, forms, byte ranges, and the violations of `rules`, which do not stop
|
|
54
|
+
* reading. Primitive contents are not interpreted; types are not checked.
|
|
55
|
+
* Iterative: O(n) time, O(depth) memory beyond the tree.
|
|
56
|
+
*
|
|
57
|
+
* Never throws for the input: a framing error or an exceeded limit ends reading
|
|
58
|
+
* and is returned as `error`, with the elements read before it (an element
|
|
59
|
+
* still open keeps its declared end when it has a definite length).
|
|
60
|
+
*
|
|
61
|
+
* @param bytes - The entire view to inspect, not copied or retained. An empty
|
|
62
|
+
* view has no roots.
|
|
63
|
+
* @param options - The rules and the limits.
|
|
64
|
+
* @throws {RangeError} When a limit is not a positive safe integer, or `rules`
|
|
65
|
+
* is not one of the three.
|
|
66
|
+
*/
|
|
67
|
+
export declare function berInspect(bytes: Uint8Array, options: BerInspectOptions): BerInspection;
|
|
68
|
+
//# sourceMappingURL=inspect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspect.d.ts","sourceRoot":"","sources":["../../src/reader/inspect.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAa,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE3E,MAAM,MAAM,iBAAiB,GAAG;IAC/B,iFAAiF;IACjF,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC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