asn1-ts 9.0.2 → 10.0.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/README.md +9 -4
- package/dist/asn1.mjs +10 -7
- package/dist/classes/ABSTRACT-SYNTAX.d.mts +1 -1
- package/dist/classes/TYPE-IDENTIFIER.d.mts +1 -1
- package/dist/classes/index.d.mts +2 -2
- package/dist/codecs/ber/decoders/decodeBitString.d.mts +1 -1
- package/dist/codecs/ber/decoders/decodeBoolean.d.mts +1 -1
- package/dist/codecs/ber/decoders/decodeDuration.d.mts +1 -1
- package/dist/codecs/ber/decoders/decodeDuration.mjs +2 -2
- package/dist/codecs/ber/decoders/decodeGeneralizedTime.d.mts +1 -1
- package/dist/codecs/ber/decoders/decodeGeneralizedTime.mjs +10 -4
- package/dist/codecs/ber/decoders/decodeReal.d.mts +1 -1
- package/dist/codecs/ber/decoders/decodeSequence.d.mts +1 -1
- package/dist/codecs/ber/decoders/decodeUTCTime.d.mts +1 -1
- package/dist/codecs/ber/encoders/encodeGeneralString.d.mts +1 -1
- package/dist/codecs/ber/encoders/encodeGraphicString.d.mts +1 -1
- package/dist/codecs/ber/encoders/encodeNumericString.d.mts +1 -1
- package/dist/codecs/ber/encoders/encodeObjectDescriptor.d.mts +1 -1
- package/dist/codecs/ber/encoders/encodePrintableString.d.mts +1 -1
- package/dist/codecs/ber/encoders/encodeVisibleString.d.mts +1 -1
- package/dist/codecs/ber.d.mts +1 -1
- package/dist/codecs/ber.mjs +6 -5
- package/dist/codecs/cer/decoders/decodeSequence.d.mts +1 -1
- package/dist/codecs/cer.d.mts +1 -1
- package/dist/codecs/cer.mjs +3 -3
- package/dist/codecs/coer/decoders/decodeBoolean.d.mts +1 -1
- package/dist/codecs/der/decoders/decodeBitString.d.mts +1 -1
- package/dist/codecs/der/decoders/decodeBoolean.d.mts +1 -1
- package/dist/codecs/der/decoders/decodeDuration.d.mts +1 -1
- package/dist/codecs/der/decoders/decodeDuration.mjs +2 -2
- package/dist/codecs/der/decoders/decodeGeneralizedTime.d.mts +1 -1
- package/dist/codecs/der/decoders/decodeReal.d.mts +1 -1
- package/dist/codecs/der/decoders/decodeSequence.d.mts +1 -1
- package/dist/codecs/der/decoders/decodeUTCTime.d.mts +1 -1
- package/dist/codecs/der.d.mts +1 -1
- package/dist/codecs/der.mjs +2 -2
- package/dist/codecs/x690/decoders/decodeDate.d.mts +1 -1
- package/dist/codecs/x690/decoders/decodeDateTime.d.mts +1 -1
- package/dist/codecs/x690/decoders/decodeEmbeddedPDV.d.mts +1 -1
- package/dist/codecs/x690/decoders/decodeExternal.d.mts +1 -1
- package/dist/codecs/x690/decoders/decodeExternal.mjs +1 -0
- package/dist/codecs/x690/decoders/decodeGeneralString.d.mts +1 -1
- package/dist/codecs/x690/decoders/decodeGraphicString.d.mts +1 -1
- package/dist/codecs/x690/decoders/decodeInteger.d.mts +1 -1
- package/dist/codecs/x690/decoders/decodeNumericString.d.mts +1 -1
- package/dist/codecs/x690/decoders/decodeOIDIRI.d.mts +1 -1
- package/dist/codecs/x690/decoders/decodeObjectDescriptor.d.mts +1 -1
- package/dist/codecs/x690/decoders/decodeObjectIdentifier.d.mts +1 -1
- package/dist/codecs/x690/decoders/decodeObjectIdentifier.mjs +2 -2
- package/dist/codecs/x690/decoders/decodePrintableString.d.mts +1 -1
- package/dist/codecs/x690/decoders/decodeRelativeOIDIRI.d.mts +1 -1
- package/dist/codecs/x690/decoders/decodeRelativeObjectIdentifier.d.mts +1 -1
- package/dist/codecs/x690/decoders/decodeRelativeObjectIdentifier.mjs +2 -2
- package/dist/codecs/x690/decoders/decodeTime.d.mts +1 -1
- package/dist/codecs/x690/decoders/decodeTimeOfDay.d.mts +1 -1
- package/dist/codecs/x690/decoders/decodeVisibleString.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeBitString.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeBoolean.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeCharacterString.mjs +1 -0
- package/dist/codecs/x690/encoders/encodeDate.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeDateTime.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeDuration.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeEmbeddedPDV.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeExternal.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeGeneralizedTime.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeInteger.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeOIDIRI.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeObjectIdentifier.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeReal.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeRelativeOIDIRI.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeRelativeObjectIdentifier.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeSequence.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeSequence.mjs +1 -0
- package/dist/codecs/x690/encoders/encodeTime.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeTimeOfDay.d.mts +1 -1
- package/dist/codecs/x690/encoders/encodeUTCTime.d.mts +1 -1
- package/dist/errors.mjs +0 -16
- package/dist/functional.d.mts +40 -42
- package/dist/functional.mjs +118 -123
- package/dist/index.d.mts +0 -2
- package/dist/index.mjs +0 -1
- package/dist/interfaces/index.d.mts +12 -12
- package/dist/types/CharacterString.mjs +0 -2
- package/dist/types/EmbeddedPDV.mjs +0 -2
- package/dist/types/External.d.mts +1 -1
- package/dist/types/External.mjs +0 -4
- package/dist/types/ObjectIdentifier.mjs +0 -1
- package/dist/types/TypeIdentifier.mjs +1 -2
- package/dist/types/time/DATE-ENCODING.d.mts +1 -1
- package/dist/types/time/DATE-ENCODING.mjs +0 -3
- package/dist/types/time/DURATION-EQUIVALENT.d.mts +1 -1
- package/dist/types/time/DURATION-EQUIVALENT.mjs +0 -8
- package/dist/types/time/DURATION-INTERVAL-ENCODING.d.mts +1 -1
- package/dist/types/time/DURATION-INTERVAL-ENCODING.mjs +0 -8
- package/dist/types/time/HOURS-DIFF-ENCODING.d.mts +1 -1
- package/dist/types/time/HOURS-DIFF-ENCODING.mjs +0 -2
- package/dist/types/time/HOURS-ENCODING.d.mts +1 -1
- package/dist/types/time/HOURS-ENCODING.mjs +0 -1
- package/dist/types/time/HOURS-MINUTES-DIFF-ENCODING.d.mts +1 -1
- package/dist/types/time/HOURS-MINUTES-DIFF-ENCODING.mjs +0 -3
- package/dist/types/time/HOURS-MINUTES-ENCODING.d.mts +1 -1
- package/dist/types/time/HOURS-MINUTES-ENCODING.mjs +0 -2
- package/dist/types/time/TIME-OF-DAY-DIFF-ENCODING.d.mts +1 -1
- package/dist/types/time/TIME-OF-DAY-DIFF-ENCODING.mjs +0 -4
- package/dist/types/time/TIME-OF-DAY-ENCODING.d.mts +1 -1
- package/dist/types/time/TIME-OF-DAY-ENCODING.mjs +0 -3
- package/dist/types/time/TIME-OF-DAY-FRACTION-DIFF-ENCODING.d.mts +1 -1
- package/dist/types/time/TIME-OF-DAY-FRACTION-DIFF-ENCODING.mjs +0 -5
- package/dist/types/time/TIME-OF-DAY-FRACTION-ENCODING.d.mts +1 -1
- package/dist/types/time/TIME-OF-DAY-FRACTION-ENCODING.mjs +0 -4
- package/dist/types/time/YEAR-ENCODING.d.mts +1 -1
- package/dist/types/time/YEAR-ENCODING.mjs +0 -1
- package/dist/types/time/YEAR-MONTH-ENCODING.d.mts +1 -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/dist/utils/isInCanonicalOrder.mjs +1 -1
- package/dist/utils/packBits.d.mts +1 -1
- package/dist/utils/unpackBits.d.mts +1 -1
- package/dist/validators/datetimeComponentValidator.d.mts +1 -1
- package/dist/values.d.mts +1 -0
- package/dist/values.mjs +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
# ASN.1 TypeScript Library
|
|
2
2
|
|
|
3
|
+
[](https://jsr.io/@wildboar/asn1)
|
|
4
|
+
|
|
3
5
|
Feature-complete, specification-compliant TypeScript library for encoding and
|
|
4
6
|
decoding ASN.1 data structures using the Basic Encoding Rules (BER),
|
|
5
7
|
Canonical Encoding Rules (CER), and Distinguished Encoding Rules (DER).
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
This library is published on both
|
|
10
|
+
[npmjs.com](https://www.npmjs.com/package/asn1-ts) and on
|
|
11
|
+
[jsr.io](https://jsr.io/@wildboar/asn1). You can install it via
|
|
12
|
+
`npm install asn1-ts` or `npx jsr add @wildboar/asn1`. As of version 9.0.0 and
|
|
13
|
+
above, this library is ESM only: no more CommonJS.
|
|
9
14
|
|
|
10
15
|
**Table of Contents**
|
|
11
16
|
|
|
@@ -294,8 +299,8 @@ NodeJS.
|
|
|
294
299
|
## See Also
|
|
295
300
|
|
|
296
301
|
- [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`.
|
|
302
|
+
- [Meerkat DSA](https://wildboar-software.github.io/directory/), an X.500
|
|
303
|
+
directory server that uses `asn1-ts`.
|
|
299
304
|
* [X.680 - Abstract Syntax Notation One (ASN.1)](https://www.itu.int/rec/T-REC-X.680/en)
|
|
300
305
|
* [X.690 - BER, CER, and DER](https://www.itu.int/rec/T-REC-X.690/en)
|
|
301
306
|
* [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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ASN1Decoder, ASN1Encoder } from "../functional.mjs";
|
|
1
|
+
import type { ASN1Decoder, ASN1Encoder } from "../functional.mjs";
|
|
2
2
|
import type { OBJECT_IDENTIFIER, BIT_STRING } from "../macros.mjs";
|
|
3
3
|
export default interface ABSTRACT_SYNTAX<Type = any> {
|
|
4
4
|
class: string;
|
package/dist/classes/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default as ABSTRACT_SYNTAX } from "./ABSTRACT-SYNTAX.mjs";
|
|
2
|
-
export { default as TYPE_IDENTIFIER } from "./TYPE-IDENTIFIER.mjs";
|
|
1
|
+
export type { default as ABSTRACT_SYNTAX } from "./ABSTRACT-SYNTAX.mjs";
|
|
2
|
+
export type { default as TYPE_IDENTIFIER } from "./TYPE-IDENTIFIER.mjs";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BIT_STRING } from "../../../macros.mjs";
|
|
1
|
+
import type { BIT_STRING } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeBitString(value: Uint8Array): BIT_STRING;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BOOLEAN } from "../../../macros.mjs";
|
|
1
|
+
import type { BOOLEAN } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeBoolean(value: Uint8Array): BOOLEAN;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DURATION } from "../../../macros.mjs";
|
|
1
|
+
import type { DURATION } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeDuration(bytes: Uint8Array): DURATION;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import convertBytesToText from "../../../utils/convertBytesToText.mjs";
|
|
2
2
|
import * as errors from "../../../errors.mjs";
|
|
3
3
|
import { DURATION_EQUIVALENT } from "../../../types/index.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { durationRegex } from "../../../values.mjs";
|
|
5
5
|
export default function decodeDuration(bytes) {
|
|
6
6
|
const str = convertBytesToText(bytes).replace(/,/g, ".");
|
|
7
7
|
if (str.indexOf("W") === (str.length - 1)) {
|
|
@@ -27,7 +27,7 @@ export default function decodeDuration(bytes) {
|
|
|
27
27
|
}
|
|
28
28
|
return new DURATION_EQUIVALENT(undefined, undefined, weeks, undefined, undefined, undefined, undefined, fractional_part);
|
|
29
29
|
}
|
|
30
|
-
const match =
|
|
30
|
+
const match = durationRegex.exec(str);
|
|
31
31
|
if (!match) {
|
|
32
32
|
throw new errors.ASN1Error(`Malformed DURATION ${str}.`);
|
|
33
33
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { GeneralizedTime } from "../../../macros.mjs";
|
|
1
|
+
import type { GeneralizedTime } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeGeneralizedTime(value: Uint8Array): GeneralizedTime;
|
|
@@ -7,6 +7,12 @@ const COMMA = ",".charCodeAt(0);
|
|
|
7
7
|
const Z = "Z".charCodeAt(0);
|
|
8
8
|
const PLUS = "+".charCodeAt(0);
|
|
9
9
|
const MINUS = "-".charCodeAt(0);
|
|
10
|
+
var FractionalUnits;
|
|
11
|
+
(function (FractionalUnits) {
|
|
12
|
+
FractionalUnits[FractionalUnits["Hours"] = 0] = "Hours";
|
|
13
|
+
FractionalUnits[FractionalUnits["Minutes"] = 1] = "Minutes";
|
|
14
|
+
FractionalUnits[FractionalUnits["Seconds"] = 2] = "Seconds";
|
|
15
|
+
})(FractionalUnits || (FractionalUnits = {}));
|
|
10
16
|
;
|
|
11
17
|
function isStop(s, i) {
|
|
12
18
|
const char = s.charCodeAt(i);
|
|
@@ -34,7 +40,7 @@ export default function decodeGeneralizedTime(value) {
|
|
|
34
40
|
let minutes = 0;
|
|
35
41
|
let seconds = 0;
|
|
36
42
|
let milliseconds = 0;
|
|
37
|
-
let fractionUnits =
|
|
43
|
+
let fractionUnits = FractionalUnits.Hours;
|
|
38
44
|
if (i == 14) {
|
|
39
45
|
minutes = Number.parseInt(dateString.slice(10, 12), 10);
|
|
40
46
|
seconds = Number.parseInt(dateString.slice(12, 14), 10);
|
|
@@ -59,14 +65,14 @@ export default function decodeGeneralizedTime(value) {
|
|
|
59
65
|
const fractionString = `0.${dateString.slice(i, j)}`;
|
|
60
66
|
i = j;
|
|
61
67
|
const fraction = Number.parseFloat(fractionString);
|
|
62
|
-
if (fractionUnits ===
|
|
68
|
+
if (fractionUnits === FractionalUnits.Hours) {
|
|
63
69
|
minutes = Math.floor(60 * fraction);
|
|
64
70
|
seconds = Math.floor((60 * 60 * fraction) % 60);
|
|
65
71
|
}
|
|
66
|
-
else if (fractionUnits ===
|
|
72
|
+
else if (fractionUnits === FractionalUnits.Minutes) {
|
|
67
73
|
seconds = Math.floor(60 * fraction);
|
|
68
74
|
}
|
|
69
|
-
else if (fractionUnits ===
|
|
75
|
+
else if (fractionUnits === FractionalUnits.Seconds) {
|
|
70
76
|
milliseconds = Math.floor(1000 * fraction);
|
|
71
77
|
}
|
|
72
78
|
else {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { REAL } from "../../../macros.mjs";
|
|
1
|
+
import type { REAL } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeReal(value: Uint8Array): REAL;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { UTCTime } from "../../../macros.mjs";
|
|
1
|
+
import type { UTCTime } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeUTCTime(value: Uint8Array): UTCTime;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { GeneralString } from "../../../macros.mjs";
|
|
1
|
+
import type { GeneralString } from "../../../macros.mjs";
|
|
2
2
|
export default function encodeGeneralString(value: GeneralString): Uint8Array;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { GraphicString } from "../../../macros.mjs";
|
|
1
|
+
import type { GraphicString } from "../../../macros.mjs";
|
|
2
2
|
export default function encodeGraphicString(value: GraphicString): Uint8Array;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { NumericString } from "../../../macros.mjs";
|
|
1
|
+
import type { NumericString } from "../../../macros.mjs";
|
|
2
2
|
export default function encodeNumericString(value: NumericString): Uint8Array;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ObjectDescriptor } from "../../../macros.mjs";
|
|
1
|
+
import type { ObjectDescriptor } from "../../../macros.mjs";
|
|
2
2
|
export default function encodeObjectDescriptor(value: ObjectDescriptor): Uint8Array;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PrintableString } from "../../../macros.mjs";
|
|
1
|
+
import type { PrintableString } from "../../../macros.mjs";
|
|
2
2
|
export default function encodeNumericString(value: PrintableString): Uint8Array;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { VisibleString } from "../../../macros.mjs";
|
|
1
|
+
import type { VisibleString } from "../../../macros.mjs";
|
|
2
2
|
export default function encodeVisibleString(value: VisibleString): Uint8Array;
|
package/dist/codecs/ber.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import ASN1Element from "../asn1.mjs";
|
|
|
2
2
|
import { ASN1Construction, ASN1TagClass, LengthEncodingPreference } from "../values.mjs";
|
|
3
3
|
import X690Element from "../x690.mjs";
|
|
4
4
|
import CharacterString from "../types/CharacterString.mjs";
|
|
5
|
-
import { BOOLEAN, BIT_STRING, OCTET_STRING, ObjectDescriptor, EXTERNAL, REAL, EMBEDDED_PDV, UTF8String, SEQUENCE, SET, GraphicString, NumericString, VisibleString, PrintableString, TeletexString, GeneralString, UniversalString, VideotexString, BMPString, IA5String, UTCTime, GeneralizedTime, DURATION } from "../macros.mjs";
|
|
5
|
+
import type { BOOLEAN, BIT_STRING, OCTET_STRING, ObjectDescriptor, EXTERNAL, REAL, EMBEDDED_PDV, UTF8String, SEQUENCE, SET, GraphicString, NumericString, VisibleString, PrintableString, TeletexString, GeneralString, UniversalString, VideotexString, BMPString, IA5String, UTCTime, GeneralizedTime, DURATION } from "../macros.mjs";
|
|
6
6
|
export default class BERElement extends X690Element {
|
|
7
7
|
static lengthEncodingPreference: LengthEncodingPreference;
|
|
8
8
|
private _value;
|
package/dist/codecs/ber.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import ASN1Element from "../asn1.mjs";
|
|
|
2
2
|
import * as errors from "../errors.mjs";
|
|
3
3
|
import { ASN1Construction, ASN1TagClass, ASN1UniversalType, LengthEncodingPreference, } from "../values.mjs";
|
|
4
4
|
import X690Element from "../x690.mjs";
|
|
5
|
+
import CharacterString from "../types/CharacterString.mjs";
|
|
5
6
|
import convertBytesToText from "../utils/convertBytesToText.mjs";
|
|
6
7
|
import convertTextToBytes from "../utils/convertTextToBytes.mjs";
|
|
7
8
|
import ObjectIdentifier from "../types/ObjectIdentifier.mjs";
|
|
@@ -37,13 +38,10 @@ import decodeVisibleString from "../codecs/x690/decoders/decodeVisibleString.mjs
|
|
|
37
38
|
import decodeGeneralString from "../codecs/x690/decoders/decodeGeneralString.mjs";
|
|
38
39
|
import encodeDuration from "../codecs/x690/encoders/encodeDuration.mjs";
|
|
39
40
|
import decodeDuration from "../codecs/ber/decoders/decodeDuration.mjs";
|
|
40
|
-
import { FALSE_BIT
|
|
41
|
+
import { FALSE_BIT } from "../macros.mjs";
|
|
41
42
|
import { isUniquelyTagged } from "../utils/index.mjs";
|
|
42
43
|
import { Buffer } from "node:buffer";
|
|
43
|
-
|
|
44
|
-
static lengthEncodingPreference = LengthEncodingPreference.definite;
|
|
45
|
-
_value = new Uint8Array(0);
|
|
46
|
-
_currentValueLength;
|
|
44
|
+
class BERElement extends X690Element {
|
|
47
45
|
get value() {
|
|
48
46
|
if (this._value instanceof Uint8Array) {
|
|
49
47
|
return this._value;
|
|
@@ -442,6 +440,7 @@ export default class BERElement extends X690Element {
|
|
|
442
440
|
}
|
|
443
441
|
constructor(tagClass = ASN1TagClass.universal, construction = ASN1Construction.primitive, tagNumber = ASN1UniversalType.endOfContent, value = undefined) {
|
|
444
442
|
super();
|
|
443
|
+
this._value = new Uint8Array(0);
|
|
445
444
|
this.encode(value);
|
|
446
445
|
this.tagClass = tagClass;
|
|
447
446
|
this.construction = construction;
|
|
@@ -707,3 +706,5 @@ export default class BERElement extends X690Element {
|
|
|
707
706
|
return encodedElements;
|
|
708
707
|
}
|
|
709
708
|
}
|
|
709
|
+
BERElement.lengthEncodingPreference = LengthEncodingPreference.definite;
|
|
710
|
+
export default BERElement;
|
package/dist/codecs/cer.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import ASN1Element from "../asn1.mjs";
|
|
|
2
2
|
import { ASN1Construction, ASN1TagClass } from "../values.mjs";
|
|
3
3
|
import X690Element from "../x690.mjs";
|
|
4
4
|
import CharacterString from "../types/CharacterString.mjs";
|
|
5
|
-
import { BOOLEAN, BIT_STRING, OCTET_STRING, ObjectDescriptor, EXTERNAL, REAL, EMBEDDED_PDV, UTF8String, SEQUENCE, SET, GraphicString, NumericString, VisibleString, PrintableString, TeletexString, GeneralString, UniversalString, VideotexString, BMPString, IA5String, UTCTime, GeneralizedTime, DURATION } from "../macros.mjs";
|
|
5
|
+
import type { BOOLEAN, BIT_STRING, OCTET_STRING, ObjectDescriptor, EXTERNAL, REAL, EMBEDDED_PDV, UTF8String, SEQUENCE, SET, GraphicString, NumericString, VisibleString, PrintableString, TeletexString, GeneralString, UniversalString, VideotexString, BMPString, IA5String, UTCTime, GeneralizedTime, DURATION } from "../macros.mjs";
|
|
6
6
|
export default class CERElement extends X690Element {
|
|
7
7
|
private _value;
|
|
8
8
|
private _currentValueLength;
|
package/dist/codecs/cer.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import ASN1Element from "../asn1.mjs";
|
|
|
2
2
|
import * as errors from "../errors.mjs";
|
|
3
3
|
import { ASN1Construction, ASN1TagClass, ASN1UniversalType, } from "../values.mjs";
|
|
4
4
|
import X690Element from "../x690.mjs";
|
|
5
|
+
import CharacterString from "../types/CharacterString.mjs";
|
|
5
6
|
import convertBytesToText from "../utils/convertBytesToText.mjs";
|
|
6
7
|
import convertTextToBytes from "../utils/convertTextToBytes.mjs";
|
|
7
8
|
import sortCanonically from "../utils/sortCanonically.mjs";
|
|
@@ -39,12 +40,10 @@ import decodeVisibleString from "../codecs/x690/decoders/decodeVisibleString.mjs
|
|
|
39
40
|
import decodeGeneralString from "../codecs/x690/decoders/decodeGeneralString.mjs";
|
|
40
41
|
import encodeDuration from "../codecs/x690/encoders/encodeDuration.mjs";
|
|
41
42
|
import decodeDuration from "../codecs/der/decoders/decodeDuration.mjs";
|
|
42
|
-
import { FALSE_BIT
|
|
43
|
+
import { FALSE_BIT } from "../macros.mjs";
|
|
43
44
|
import { isUniquelyTagged } from "../utils/index.mjs";
|
|
44
45
|
import { Buffer } from "node:buffer";
|
|
45
46
|
export default class CERElement extends X690Element {
|
|
46
|
-
_value = new Uint8Array(0);
|
|
47
|
-
_currentValueLength;
|
|
48
47
|
get value() {
|
|
49
48
|
if (this._value instanceof Uint8Array) {
|
|
50
49
|
return this._value;
|
|
@@ -454,6 +453,7 @@ export default class CERElement extends X690Element {
|
|
|
454
453
|
}
|
|
455
454
|
constructor(tagClass = ASN1TagClass.universal, construction = ASN1Construction.primitive, tagNumber = ASN1UniversalType.endOfContent, value = undefined) {
|
|
456
455
|
super();
|
|
456
|
+
this._value = new Uint8Array(0);
|
|
457
457
|
this.encode(value);
|
|
458
458
|
this.tagClass = tagClass;
|
|
459
459
|
this.construction = construction;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BOOLEAN } from "../../../macros.mjs";
|
|
1
|
+
import type { BOOLEAN } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeBoolean(value: Uint8Array): BOOLEAN;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BIT_STRING } from "../../../macros.mjs";
|
|
1
|
+
import type { BIT_STRING } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeBitString(value: Uint8Array): BIT_STRING;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BOOLEAN } from "../../../macros.mjs";
|
|
1
|
+
import type { BOOLEAN } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeBoolean(value: Uint8Array): BOOLEAN;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DURATION } from "../../../macros.mjs";
|
|
1
|
+
import type { DURATION } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeDuration(bytes: Uint8Array): DURATION;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import convertBytesToText from "../../../utils/convertBytesToText.mjs";
|
|
2
2
|
import * as errors from "../../../errors.mjs";
|
|
3
3
|
import { DURATION_EQUIVALENT } from "../../../types/index.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { durationRegex } from "../../../values.mjs";
|
|
5
5
|
export default function decodeDuration(bytes) {
|
|
6
6
|
const str = convertBytesToText(bytes);
|
|
7
7
|
if (str.indexOf(",") !== -1) {
|
|
@@ -30,7 +30,7 @@ export default function decodeDuration(bytes) {
|
|
|
30
30
|
}
|
|
31
31
|
return new DURATION_EQUIVALENT(undefined, undefined, weeks, undefined, undefined, undefined, undefined, fractional_part);
|
|
32
32
|
}
|
|
33
|
-
const match =
|
|
33
|
+
const match = durationRegex.exec(str);
|
|
34
34
|
if (!match) {
|
|
35
35
|
throw new errors.ASN1Error(`Malformed DURATION ${str}.`);
|
|
36
36
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { GeneralizedTime } from "../../../macros.mjs";
|
|
1
|
+
import type { GeneralizedTime } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeGeneralizedTime(value: Uint8Array): GeneralizedTime;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { REAL } from "../../../macros.mjs";
|
|
1
|
+
import type { REAL } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeReal(value: Uint8Array): REAL;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { UTCTime } from "../../../macros.mjs";
|
|
1
|
+
import type { UTCTime } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeUTCTime(value: Uint8Array): UTCTime;
|
package/dist/codecs/der.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import ASN1Element from "../asn1.mjs";
|
|
|
2
2
|
import { ASN1Construction, ASN1TagClass } from "../values.mjs";
|
|
3
3
|
import CharacterString from "../types/CharacterString.mjs";
|
|
4
4
|
import X690Element from "../x690.mjs";
|
|
5
|
-
import { BOOLEAN, BIT_STRING, OCTET_STRING, ObjectDescriptor, EXTERNAL, REAL, EMBEDDED_PDV, UTF8String, SEQUENCE, SET, GraphicString, NumericString, VisibleString, PrintableString, TeletexString, GeneralString, UniversalString, VideotexString, BMPString, IA5String, UTCTime, GeneralizedTime, DURATION } from "../macros.mjs";
|
|
5
|
+
import type { BOOLEAN, BIT_STRING, OCTET_STRING, ObjectDescriptor, EXTERNAL, REAL, EMBEDDED_PDV, UTF8String, SEQUENCE, SET, GraphicString, NumericString, VisibleString, PrintableString, TeletexString, GeneralString, UniversalString, VideotexString, BMPString, IA5String, UTCTime, GeneralizedTime, DURATION } from "../macros.mjs";
|
|
6
6
|
export default class DERElement extends X690Element {
|
|
7
7
|
private _value;
|
|
8
8
|
private _currentValueLength;
|
package/dist/codecs/der.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ASN1Element from "../asn1.mjs";
|
|
2
2
|
import * as errors from "../errors.mjs";
|
|
3
3
|
import { ASN1Construction, ASN1TagClass, ASN1UniversalType, } from "../values.mjs";
|
|
4
|
+
import CharacterString from "../types/CharacterString.mjs";
|
|
4
5
|
import convertBytesToText from "../utils/convertBytesToText.mjs";
|
|
5
6
|
import convertTextToBytes from "../utils/convertTextToBytes.mjs";
|
|
6
7
|
import sortCanonically from "../utils/sortCanonically.mjs";
|
|
@@ -41,8 +42,6 @@ import X690Element from "../x690.mjs";
|
|
|
41
42
|
import { isUniquelyTagged } from "../utils/index.mjs";
|
|
42
43
|
import { Buffer } from "node:buffer";
|
|
43
44
|
export default class DERElement extends X690Element {
|
|
44
|
-
_value = new Uint8Array(0);
|
|
45
|
-
_currentValueLength;
|
|
46
45
|
get value() {
|
|
47
46
|
if (this._value instanceof Uint8Array) {
|
|
48
47
|
return this._value;
|
|
@@ -455,6 +454,7 @@ export default class DERElement extends X690Element {
|
|
|
455
454
|
}
|
|
456
455
|
constructor(tagClass = ASN1TagClass.universal, construction = ASN1Construction.primitive, tagNumber = ASN1UniversalType.endOfContent, value = undefined) {
|
|
457
456
|
super();
|
|
457
|
+
this._value = new Uint8Array(0);
|
|
458
458
|
this.encode(value);
|
|
459
459
|
this.tagClass = tagClass;
|
|
460
460
|
this.construction = construction;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DATE } from "../../../macros.mjs";
|
|
1
|
+
import type { DATE } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeDate(bytes: Uint8Array): DATE;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DATE_TIME } from "../../../macros.mjs";
|
|
1
|
+
import type { DATE_TIME } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeDateTime(bytes: Uint8Array): DATE_TIME;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EMBEDDED_PDV } from "../../../macros.mjs";
|
|
1
|
+
import type { EMBEDDED_PDV } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeEmbeddedPDV(value: Uint8Array): EMBEDDED_PDV;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EXTERNAL } from "../../../macros.mjs";
|
|
1
|
+
import type { EXTERNAL } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeExternal(value: Uint8Array): EXTERNAL;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import External from "../../../types/External.mjs";
|
|
2
2
|
import { ASN1TagClass, ASN1UniversalType } from "../../../values.mjs";
|
|
3
|
+
import ASN1Element from "../../../asn1.mjs";
|
|
3
4
|
import * as errors from "../../../errors.mjs";
|
|
4
5
|
import decodeSequence from "../../der/decoders/decodeSequence.mjs";
|
|
5
6
|
export default function decodeExternal(value) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { GeneralString } from "../../../macros.mjs";
|
|
1
|
+
import type { GeneralString } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeGeneralString(value: Uint8Array): GeneralString;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { GraphicString } from "../../../macros.mjs";
|
|
1
|
+
import type { GraphicString } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeGraphicString(value: Uint8Array): GraphicString;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { INTEGER } from "../../../macros.mjs";
|
|
1
|
+
import type { INTEGER } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeInteger(value: Uint8Array): INTEGER;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { NumericString } from "../../../macros.mjs";
|
|
1
|
+
import type { NumericString } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeNumericString(value: Uint8Array): NumericString;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { OID_IRI } from "../../../macros.mjs";
|
|
1
|
+
import type { OID_IRI } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeOIDIRI(bytes: Uint8Array): OID_IRI;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ObjectDescriptor } from "../../../macros.mjs";
|
|
1
|
+
import type { ObjectDescriptor } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeObjectDescriptor(value: Uint8Array): ObjectDescriptor;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { OBJECT_IDENTIFIER } from "../../../macros.mjs";
|
|
1
|
+
import type { OBJECT_IDENTIFIER } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeObjectIdentifier(value: Uint8Array): OBJECT_IDENTIFIER;
|
|
@@ -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
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PrintableString } from "../../../macros.mjs";
|
|
1
|
+
import type { PrintableString } from "../../../macros.mjs";
|
|
2
2
|
export default function decodePrintableString(value: Uint8Array): PrintableString;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RELATIVE_OID_IRI } from "../../../macros.mjs";
|
|
1
|
+
import type { RELATIVE_OID_IRI } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeRelativeOIDIRI(bytes: Uint8Array): RELATIVE_OID_IRI;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RELATIVE_OID } from "../../../macros.mjs";
|
|
1
|
+
import type { RELATIVE_OID } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeRelativeObjectIdentifier(value: Uint8Array): RELATIVE_OID;
|
|
@@ -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
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { TIME } from "../../../macros.mjs";
|
|
1
|
+
import type { TIME } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeTime(bytes: Uint8Array): TIME;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { TIME_OF_DAY } from "../../../macros.mjs";
|
|
1
|
+
import type { TIME_OF_DAY } from "../../../macros.mjs";
|
|
2
2
|
export default function decodeTimeOfDay(bytes: Uint8Array): TIME_OF_DAY;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PrintableString } from "../../../macros.mjs";
|
|
1
|
+
import type { PrintableString } from "../../../macros.mjs";
|
|
2
2
|
export default function decodePrintableString(value: Uint8Array): PrintableString;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BIT_STRING } from "../../../macros.mjs";
|
|
1
|
+
import type { BIT_STRING } from "../../../macros.mjs";
|
|
2
2
|
export default function encodeBitString(value: BIT_STRING): Uint8Array;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BOOLEAN } from "../../../macros.mjs";
|
|
1
|
+
import type { BOOLEAN } from "../../../macros.mjs";
|
|
2
2
|
export default function encodeBoolean(value: BOOLEAN): Uint8Array;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DATE } from "../../../macros.mjs";
|
|
1
|
+
import type { DATE } from "../../../macros.mjs";
|
|
2
2
|
export default function encodeDate(date: DATE): Uint8Array;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DATE_TIME } from "../../../macros.mjs";
|
|
1
|
+
import type { DATE_TIME } from "../../../macros.mjs";
|
|
2
2
|
export default function encodeDateTime(value: DATE_TIME): Uint8Array;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DURATION } from "../../../macros.mjs";
|
|
1
|
+
import type { DURATION } from "../../../macros.mjs";
|
|
2
2
|
export default function encodeDuration(value: DURATION): Uint8Array;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EMBEDDED_PDV } from "../../../macros.mjs";
|
|
1
|
+
import type { EMBEDDED_PDV } from "../../../macros.mjs";
|
|
2
2
|
export default function encodeEmbeddedPDV(value: EMBEDDED_PDV): Uint8Array;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EXTERNAL } from "../../../macros.mjs";
|
|
1
|
+
import type { EXTERNAL } from "../../../macros.mjs";
|
|
2
2
|
export default function encodeExternal(value: EXTERNAL): Uint8Array;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { GeneralizedTime } from "../../../macros.mjs";
|
|
1
|
+
import type { GeneralizedTime } from "../../../macros.mjs";
|
|
2
2
|
export default function encodeGeneralizedTime(value: GeneralizedTime): Uint8Array;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { INTEGER } from "../../../macros.mjs";
|
|
1
|
+
import type { INTEGER } from "../../../macros.mjs";
|
|
2
2
|
export default function encodeInteger(value: INTEGER): Uint8Array;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { OID_IRI } from "../../../macros.mjs";
|
|
1
|
+
import type { OID_IRI } from "../../../macros.mjs";
|
|
2
2
|
export default function encodeOIDIRI(value: OID_IRI): Uint8Array;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { REAL } from "../../../macros.mjs";
|
|
1
|
+
import type { REAL } from "../../../macros.mjs";
|
|
2
2
|
export default function encodeReal(value: REAL): Uint8Array;
|