asn1-ts 9.0.2 → 9.0.3
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/README.md +7 -4
- package/dist/asn1.mjs +10 -7
- package/dist/codecs/ber.mjs +4 -4
- package/dist/codecs/cer.mjs +1 -2
- package/dist/codecs/der.mjs +1 -2
- package/dist/codecs/x690/decoders/decodeObjectIdentifier.mjs +2 -2
- package/dist/codecs/x690/decoders/decodeRelativeObjectIdentifier.mjs +2 -2
- package/dist/errors.mjs +0 -16
- package/dist/functional.mjs +0 -5
- package/dist/types/CharacterString.mjs +0 -2
- package/dist/types/EmbeddedPDV.mjs +0 -2
- package/dist/types/External.mjs +0 -4
- package/dist/types/ObjectIdentifier.mjs +0 -1
- package/dist/types/TypeIdentifier.mjs +0 -2
- package/dist/types/time/DATE-ENCODING.mjs +0 -3
- package/dist/types/time/DURATION-EQUIVALENT.mjs +0 -8
- package/dist/types/time/DURATION-INTERVAL-ENCODING.mjs +0 -8
- package/dist/types/time/HOURS-DIFF-ENCODING.mjs +0 -2
- package/dist/types/time/HOURS-ENCODING.mjs +0 -1
- package/dist/types/time/HOURS-MINUTES-DIFF-ENCODING.mjs +0 -3
- package/dist/types/time/HOURS-MINUTES-ENCODING.mjs +0 -2
- package/dist/types/time/TIME-OF-DAY-DIFF-ENCODING.mjs +0 -4
- package/dist/types/time/TIME-OF-DAY-ENCODING.mjs +0 -3
- package/dist/types/time/TIME-OF-DAY-FRACTION-DIFF-ENCODING.mjs +0 -5
- package/dist/types/time/TIME-OF-DAY-FRACTION-ENCODING.mjs +0 -4
- package/dist/types/time/YEAR-ENCODING.mjs +0 -1
- package/dist/types/time/YEAR-MONTH-ENCODING.mjs +0 -2
- package/dist/utils/bigint.mjs +2 -2
- package/dist/utils/dissectFloat.mjs +3 -3
- package/dist/utils/encodeX690BinaryRealNumber.mjs +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,8 +4,11 @@ Feature-complete, specification-compliant TypeScript library for encoding and
|
|
|
4
4
|
decoding ASN.1 data structures using the Basic Encoding Rules (BER),
|
|
5
5
|
Canonical Encoding Rules (CER), and Distinguished Encoding Rules (DER).
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
This library is published on both
|
|
8
|
+
[npmjs.com](https://www.npmjs.com/package/asn1-ts) and on
|
|
9
|
+
[jsr.io](https://jsr.io/@wildboar/asn1). You can install it via
|
|
10
|
+
`npm install asn1-ts` or `npx jsr add @wildboar/asn1`. As of version 9.0.0 and
|
|
11
|
+
above, this library is ESM only: no more CommonJS.
|
|
9
12
|
|
|
10
13
|
**Table of Contents**
|
|
11
14
|
|
|
@@ -294,8 +297,8 @@ NodeJS.
|
|
|
294
297
|
## See Also
|
|
295
298
|
|
|
296
299
|
- [Libraries that use `asn1-ts`](https://github.com/Wildboar-Software/asn1-typescript-libraries)
|
|
297
|
-
- [Meerkat DSA](https://wildboar-software.github.io/directory/), an
|
|
298
|
-
that uses `asn1-ts`.
|
|
300
|
+
- [Meerkat DSA](https://wildboar-software.github.io/directory/), an X.500
|
|
301
|
+
directory server that uses `asn1-ts`.
|
|
299
302
|
* [X.680 - Abstract Syntax Notation One (ASN.1)](https://www.itu.int/rec/T-REC-X.680/en)
|
|
300
303
|
* [X.690 - BER, CER, and DER](https://www.itu.int/rec/T-REC-X.690/en)
|
|
301
304
|
* [ASN.1: Communication Between Heterogeneous Systems](https://www.oss.com/asn1/resources/books-whitepapers-pubs/dubuisson-asn1-book.PDF) by Olivier Dubuisson
|
package/dist/asn1.mjs
CHANGED
|
@@ -2,13 +2,14 @@ import * as errors from "./errors.mjs";
|
|
|
2
2
|
import { ASN1Construction, ASN1TagClass, ASN1UniversalType } from "./values.mjs";
|
|
3
3
|
import packBits from "./utils/packBits.mjs";
|
|
4
4
|
import { Buffer } from "node:buffer";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
class ASN1Element {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.recursionCount = 0;
|
|
8
|
+
this.name = "";
|
|
9
|
+
this.tagClass = ASN1TagClass.universal;
|
|
10
|
+
this.construction = ASN1Construction.primitive;
|
|
11
|
+
this._tagNumber = 0;
|
|
12
|
+
}
|
|
12
13
|
get tagNumber() {
|
|
13
14
|
return this._tagNumber;
|
|
14
15
|
}
|
|
@@ -347,3 +348,5 @@ export default class ASN1Element {
|
|
|
347
348
|
}
|
|
348
349
|
}
|
|
349
350
|
}
|
|
351
|
+
ASN1Element.nestingRecursionLimit = 5;
|
|
352
|
+
export default ASN1Element;
|
package/dist/codecs/ber.mjs
CHANGED
|
@@ -40,10 +40,7 @@ import decodeDuration from "../codecs/ber/decoders/decodeDuration.mjs";
|
|
|
40
40
|
import { FALSE_BIT, } from "../macros.mjs";
|
|
41
41
|
import { isUniquelyTagged } from "../utils/index.mjs";
|
|
42
42
|
import { Buffer } from "node:buffer";
|
|
43
|
-
|
|
44
|
-
static lengthEncodingPreference = LengthEncodingPreference.definite;
|
|
45
|
-
_value = new Uint8Array(0);
|
|
46
|
-
_currentValueLength;
|
|
43
|
+
class BERElement extends X690Element {
|
|
47
44
|
get value() {
|
|
48
45
|
if (this._value instanceof Uint8Array) {
|
|
49
46
|
return this._value;
|
|
@@ -442,6 +439,7 @@ export default class BERElement extends X690Element {
|
|
|
442
439
|
}
|
|
443
440
|
constructor(tagClass = ASN1TagClass.universal, construction = ASN1Construction.primitive, tagNumber = ASN1UniversalType.endOfContent, value = undefined) {
|
|
444
441
|
super();
|
|
442
|
+
this._value = new Uint8Array(0);
|
|
445
443
|
this.encode(value);
|
|
446
444
|
this.tagClass = tagClass;
|
|
447
445
|
this.construction = construction;
|
|
@@ -707,3 +705,5 @@ export default class BERElement extends X690Element {
|
|
|
707
705
|
return encodedElements;
|
|
708
706
|
}
|
|
709
707
|
}
|
|
708
|
+
BERElement.lengthEncodingPreference = LengthEncodingPreference.definite;
|
|
709
|
+
export default BERElement;
|
package/dist/codecs/cer.mjs
CHANGED
|
@@ -43,8 +43,6 @@ import { FALSE_BIT, } from "../macros.mjs";
|
|
|
43
43
|
import { isUniquelyTagged } from "../utils/index.mjs";
|
|
44
44
|
import { Buffer } from "node:buffer";
|
|
45
45
|
export default class CERElement extends X690Element {
|
|
46
|
-
_value = new Uint8Array(0);
|
|
47
|
-
_currentValueLength;
|
|
48
46
|
get value() {
|
|
49
47
|
if (this._value instanceof Uint8Array) {
|
|
50
48
|
return this._value;
|
|
@@ -454,6 +452,7 @@ export default class CERElement extends X690Element {
|
|
|
454
452
|
}
|
|
455
453
|
constructor(tagClass = ASN1TagClass.universal, construction = ASN1Construction.primitive, tagNumber = ASN1UniversalType.endOfContent, value = undefined) {
|
|
456
454
|
super();
|
|
455
|
+
this._value = new Uint8Array(0);
|
|
457
456
|
this.encode(value);
|
|
458
457
|
this.tagClass = tagClass;
|
|
459
458
|
this.construction = construction;
|
package/dist/codecs/der.mjs
CHANGED
|
@@ -41,8 +41,6 @@ import X690Element from "../x690.mjs";
|
|
|
41
41
|
import { isUniquelyTagged } from "../utils/index.mjs";
|
|
42
42
|
import { Buffer } from "node:buffer";
|
|
43
43
|
export default class DERElement extends X690Element {
|
|
44
|
-
_value = new Uint8Array(0);
|
|
45
|
-
_currentValueLength;
|
|
46
44
|
get value() {
|
|
47
45
|
if (this._value instanceof Uint8Array) {
|
|
48
46
|
return this._value;
|
|
@@ -455,6 +453,7 @@ export default class DERElement extends X690Element {
|
|
|
455
453
|
}
|
|
456
454
|
constructor(tagClass = ASN1TagClass.universal, construction = ASN1Construction.primitive, tagNumber = ASN1UniversalType.endOfContent, value = undefined) {
|
|
457
455
|
super();
|
|
456
|
+
this._value = new Uint8Array(0);
|
|
458
457
|
this.encode(value);
|
|
459
458
|
this.tagClass = tagClass;
|
|
460
459
|
this.construction = construction;
|
|
@@ -36,8 +36,8 @@ export default function decodeObjectIdentifier(value) {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
current_node <<= 7;
|
|
39
|
-
current_node += (byte &
|
|
40
|
-
if ((byte &
|
|
39
|
+
current_node += (byte & 127);
|
|
40
|
+
if ((byte & 128) === 0) {
|
|
41
41
|
nodes.push(current_node);
|
|
42
42
|
current_node = 0;
|
|
43
43
|
}
|
|
@@ -14,8 +14,8 @@ export default function decodeRelativeObjectIdentifier(value) {
|
|
|
14
14
|
throw new errors.ASN1PaddingError("Prohibited padding on RELATIVE-OID node.");
|
|
15
15
|
}
|
|
16
16
|
current_node <<= 7;
|
|
17
|
-
current_node += (byte &
|
|
18
|
-
if ((byte &
|
|
17
|
+
current_node += (byte & 127);
|
|
18
|
+
if ((byte & 128) === 0) {
|
|
19
19
|
nodes.push(current_node);
|
|
20
20
|
current_node = 0;
|
|
21
21
|
}
|
package/dist/errors.mjs
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export class ASN1Error extends Error {
|
|
2
|
-
m;
|
|
3
|
-
element;
|
|
4
2
|
constructor(m, element) {
|
|
5
3
|
super(m);
|
|
6
4
|
this.m = m;
|
|
@@ -21,8 +19,6 @@ export class ASN1RecursionError extends ASN1Error {
|
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
21
|
export class ASN1TruncationError extends ASN1Error {
|
|
24
|
-
m;
|
|
25
|
-
element;
|
|
26
22
|
constructor(m, element) {
|
|
27
23
|
super(m, element);
|
|
28
24
|
this.m = m;
|
|
@@ -31,8 +27,6 @@ export class ASN1TruncationError extends ASN1Error {
|
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
29
|
export class ASN1OverflowError extends ASN1Error {
|
|
34
|
-
m;
|
|
35
|
-
element;
|
|
36
30
|
constructor(m, element) {
|
|
37
31
|
super(m, element);
|
|
38
32
|
this.m = m;
|
|
@@ -41,8 +35,6 @@ export class ASN1OverflowError extends ASN1Error {
|
|
|
41
35
|
}
|
|
42
36
|
}
|
|
43
37
|
export class ASN1SizeError extends ASN1Error {
|
|
44
|
-
m;
|
|
45
|
-
element;
|
|
46
38
|
constructor(m, element) {
|
|
47
39
|
super(m, element);
|
|
48
40
|
this.m = m;
|
|
@@ -51,8 +43,6 @@ export class ASN1SizeError extends ASN1Error {
|
|
|
51
43
|
}
|
|
52
44
|
}
|
|
53
45
|
export class ASN1PaddingError extends ASN1Error {
|
|
54
|
-
m;
|
|
55
|
-
element;
|
|
56
46
|
constructor(m, element) {
|
|
57
47
|
super(m, element);
|
|
58
48
|
this.m = m;
|
|
@@ -61,8 +51,6 @@ export class ASN1PaddingError extends ASN1Error {
|
|
|
61
51
|
}
|
|
62
52
|
}
|
|
63
53
|
export class ASN1UndefinedError extends ASN1Error {
|
|
64
|
-
m;
|
|
65
|
-
element;
|
|
66
54
|
constructor(m, element) {
|
|
67
55
|
super(m, element);
|
|
68
56
|
this.m = m;
|
|
@@ -71,8 +59,6 @@ export class ASN1UndefinedError extends ASN1Error {
|
|
|
71
59
|
}
|
|
72
60
|
}
|
|
73
61
|
export class ASN1CharactersError extends ASN1Error {
|
|
74
|
-
m;
|
|
75
|
-
element;
|
|
76
62
|
constructor(m, element) {
|
|
77
63
|
super(m, element);
|
|
78
64
|
this.m = m;
|
|
@@ -81,8 +67,6 @@ export class ASN1CharactersError extends ASN1Error {
|
|
|
81
67
|
}
|
|
82
68
|
}
|
|
83
69
|
export class ASN1ConstructionError extends ASN1Error {
|
|
84
|
-
m;
|
|
85
|
-
element;
|
|
86
70
|
constructor(m, element) {
|
|
87
71
|
super(m, element);
|
|
88
72
|
this.m = m;
|
package/dist/functional.mjs
CHANGED
|
@@ -504,11 +504,6 @@ export const _decodeAny = (el) => {
|
|
|
504
504
|
return el;
|
|
505
505
|
};
|
|
506
506
|
export class ComponentSpec {
|
|
507
|
-
name;
|
|
508
|
-
optional;
|
|
509
|
-
selector;
|
|
510
|
-
groupIndex;
|
|
511
|
-
versionNumber;
|
|
512
507
|
constructor(name, optional, selector, groupIndex, versionNumber) {
|
|
513
508
|
this.name = name;
|
|
514
509
|
this.optional = optional;
|
package/dist/types/External.mjs
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import packBits from "../utils/packBits.mjs";
|
|
2
2
|
export default class External {
|
|
3
|
-
directReference;
|
|
4
|
-
indirectReference;
|
|
5
|
-
dataValueDescriptor;
|
|
6
|
-
encoding;
|
|
7
3
|
constructor(directReference, indirectReference, dataValueDescriptor, encoding) {
|
|
8
4
|
this.directReference = directReference;
|
|
9
5
|
this.indirectReference = indirectReference;
|
|
@@ -2,7 +2,6 @@ import decodeObjectIdentifier from "../codecs/x690/decoders/decodeObjectIdentifi
|
|
|
2
2
|
import encodeObjectIdentifier from "../codecs/x690/encoders/encodeObjectIdentifier.mjs";
|
|
3
3
|
const PERIOD = ".".charCodeAt(0);
|
|
4
4
|
export default class ObjectIdentifier {
|
|
5
|
-
_nodes;
|
|
6
5
|
constructor(nodes, prefix) {
|
|
7
6
|
const _nodes = prefix
|
|
8
7
|
? typeof prefix === "number"
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import * as errors from "../../errors.mjs";
|
|
2
2
|
import datetimeComponentValidator from "../../validators/datetimeComponentValidator.mjs";
|
|
3
3
|
export default class DURATION_EQUIVALENT {
|
|
4
|
-
years;
|
|
5
|
-
months;
|
|
6
|
-
weeks;
|
|
7
|
-
days;
|
|
8
|
-
hours;
|
|
9
|
-
minutes;
|
|
10
|
-
seconds;
|
|
11
|
-
fractional_part;
|
|
12
4
|
constructor(years, months, weeks, days, hours, minutes, seconds, fractional_part) {
|
|
13
5
|
this.years = years;
|
|
14
6
|
this.months = months;
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import * as errors from "../../errors.mjs";
|
|
2
2
|
import datetimeComponentValidator from "../../validators/datetimeComponentValidator.mjs";
|
|
3
3
|
export default class DURATION_INTERVAL_ENCODING {
|
|
4
|
-
years;
|
|
5
|
-
months;
|
|
6
|
-
weeks;
|
|
7
|
-
days;
|
|
8
|
-
hours;
|
|
9
|
-
minutes;
|
|
10
|
-
seconds;
|
|
11
|
-
fractional_part;
|
|
12
4
|
constructor(years, months, weeks, days, hours, minutes, seconds, fractional_part) {
|
|
13
5
|
this.years = years;
|
|
14
6
|
this.months = months;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import datetimeComponentValidator from "../../validators/datetimeComponentValidator.mjs";
|
|
2
2
|
export default class HOURS_MINUTES_DIFF_ENCODING {
|
|
3
|
-
hours;
|
|
4
|
-
minutes;
|
|
5
|
-
minutes_diff;
|
|
6
3
|
constructor(hours, minutes, minutes_diff) {
|
|
7
4
|
this.hours = hours;
|
|
8
5
|
this.minutes = minutes;
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import datetimeComponentValidator from "../../validators/datetimeComponentValidator.mjs";
|
|
2
2
|
export default class TIME_OF_DAY_DIFF_ENCODING {
|
|
3
|
-
hours;
|
|
4
|
-
minutes;
|
|
5
|
-
seconds;
|
|
6
|
-
minutes_diff;
|
|
7
3
|
constructor(hours, minutes, seconds, minutes_diff) {
|
|
8
4
|
this.hours = hours;
|
|
9
5
|
this.minutes = minutes;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import datetimeComponentValidator from "../../validators/datetimeComponentValidator.mjs";
|
|
2
2
|
export default class TIME_OF_DAY_FRACTION_DIFF_ENCODING {
|
|
3
|
-
hours;
|
|
4
|
-
minutes;
|
|
5
|
-
seconds;
|
|
6
|
-
fractional_part;
|
|
7
|
-
minutes_diff;
|
|
8
3
|
constructor(hours, minutes, seconds, fractional_part, minutes_diff) {
|
|
9
4
|
this.hours = hours;
|
|
10
5
|
this.minutes = minutes;
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import datetimeComponentValidator from "../../validators/datetimeComponentValidator.mjs";
|
|
2
2
|
export default class TIME_OF_DAY_FRACTION_ENCODING {
|
|
3
|
-
hours;
|
|
4
|
-
minutes;
|
|
5
|
-
seconds;
|
|
6
|
-
fractional_part;
|
|
7
3
|
constructor(hours, minutes, seconds, fractional_part) {
|
|
8
4
|
this.hours = hours;
|
|
9
5
|
this.minutes = minutes;
|
package/dist/utils/bigint.mjs
CHANGED
|
@@ -79,7 +79,7 @@ export function integerToBuffer(int) {
|
|
|
79
79
|
else if (int >= 0) {
|
|
80
80
|
const hex = int.toString(16);
|
|
81
81
|
ret = Buffer.from(((hex.length % 2) ? `0${hex}` : hex), "hex");
|
|
82
|
-
if (ret[0] &
|
|
82
|
+
if (ret[0] & 128) {
|
|
83
83
|
ret = Buffer.concat([
|
|
84
84
|
Buffer.from([0x00]),
|
|
85
85
|
ret,
|
|
@@ -89,7 +89,7 @@ export function integerToBuffer(int) {
|
|
|
89
89
|
else {
|
|
90
90
|
const hex = BigInt.asUintN(100000000, int).toString(16);
|
|
91
91
|
ret = Buffer.from(((hex.length % 2) ? `0${hex}` : hex), "hex");
|
|
92
|
-
if (!(ret[0] &
|
|
92
|
+
if (!(ret[0] & 128)) {
|
|
93
93
|
ret = Buffer.concat([
|
|
94
94
|
Buffer.from([0xFF]),
|
|
95
95
|
ret,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const EXPONENT_BITMASK =
|
|
1
|
+
const EXPONENT_BITMASK = 2146435072;
|
|
2
2
|
export default function dissectFloat(value) {
|
|
3
3
|
const float = new Float64Array([value]);
|
|
4
4
|
const uints = new Uint32Array(float.buffer);
|
|
5
5
|
const exponent = (((uints[1] & EXPONENT_BITMASK) >>> 20) - 1023 - 31);
|
|
6
|
-
const mantissa =
|
|
7
|
-
| ((uints[0] &
|
|
6
|
+
const mantissa = 2147483648 + ((((uints[1] & 1048575) << 11)
|
|
7
|
+
| ((uints[0] & 4292870144) >>> 21)));
|
|
8
8
|
return {
|
|
9
9
|
negative: (value < 0),
|
|
10
10
|
exponent,
|
|
@@ -30,9 +30,9 @@ export default function encodeX690BinaryRealNumber(value) {
|
|
|
30
30
|
}
|
|
31
31
|
const singleByteExponent = ((floatComponents.exponent <= 127)
|
|
32
32
|
&& (floatComponents.exponent >= -128));
|
|
33
|
-
const firstByte = (
|
|
34
|
-
| (value >= 0 ?
|
|
35
|
-
| (singleByteExponent ?
|
|
33
|
+
const firstByte = (128
|
|
34
|
+
| (value >= 0 ? 0 : 64)
|
|
35
|
+
| (singleByteExponent ? 0 : 1));
|
|
36
36
|
const exponentBytes = encodeSignedBigEndianInteger(floatComponents.exponent);
|
|
37
37
|
const mantissaBytes = encodeUnsignedBigEndianInteger(floatComponents.mantissa);
|
|
38
38
|
const ret = new Uint8Array(1 + exponentBytes.length + mantissaBytes.length);
|
package/package.json
CHANGED