asn1-ts 11.0.5 → 11.1.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/LICENSE.txt +1 -1
- package/README.md +4 -0
- package/dist/functional.mjs +7 -5
- package/dist/types/ObjectIdentifier.d.mts +3 -0
- package/dist/types/ObjectIdentifier.mjs +13 -1
- package/dist/utils/bigint.mjs +1 -1
- package/package.json +3 -3
package/LICENSE.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2020-
|
|
3
|
+
Copyright (c) 2020-2026 Jonathan M. Wilbur <jonathan@wilbur.space>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -12,6 +12,10 @@ This library is published on both
|
|
|
12
12
|
`npm install asn1-ts` or `npx jsr add @wildboar/asn1`. As of version 9.0.0 and
|
|
13
13
|
above, this library is ESM only: no more CommonJS.
|
|
14
14
|
|
|
15
|
+
This library should work on NodeJS, Bun, and Deno, and it should compile with
|
|
16
|
+
any reasonably new TypeScript version. If it does not work for you in these
|
|
17
|
+
cases, please let me know!
|
|
18
|
+
|
|
15
19
|
**Table of Contents**
|
|
16
20
|
|
|
17
21
|
- [Library Usage](#library-usage)
|
package/dist/functional.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { ASN1Element, BERElement, CERElement, DERElement, ASN1TagClass, ASN1Construction, ASN1UniversalType, ASN1ConstructionError, CharacterString, } from "./index.mjs";
|
|
1
|
+
import { ASN1Element, BERElement, CERElement, DERElement, ASN1TagClass, ASN1Construction, ASN1UniversalType, ASN1ConstructionError, CharacterString, ObjectIdentifier, } from "./index.mjs";
|
|
2
|
+
import decodeInteger from "./codecs/x690/decoders/decodeInteger.mjs";
|
|
3
|
+
import encodeInteger from "./codecs/x690/encoders/encodeInteger.mjs";
|
|
2
4
|
export function hasTag(tagClass, tagNumber) {
|
|
3
5
|
return function (index, elements) {
|
|
4
6
|
const el = elements[index];
|
|
@@ -219,13 +221,13 @@ export const _decodeInstanceOf = (el) => {
|
|
|
219
221
|
};
|
|
220
222
|
export const _encodeInteger = (value, elGetter) => {
|
|
221
223
|
const el = elGetter(value, elGetter);
|
|
222
|
-
el.
|
|
224
|
+
el.value = encodeInteger(value);
|
|
223
225
|
el.tagClass = ASN1TagClass.universal;
|
|
224
226
|
el.tagNumber = ASN1UniversalType.integer;
|
|
225
227
|
return el;
|
|
226
228
|
};
|
|
227
229
|
export const _decodeInteger = (el) => {
|
|
228
|
-
return el.
|
|
230
|
+
return decodeInteger(el.value);
|
|
229
231
|
};
|
|
230
232
|
export const _encodeIRI = (value, elGetter) => {
|
|
231
233
|
const el = elGetter(value, elGetter);
|
|
@@ -249,13 +251,13 @@ export const _decodeNull = () => {
|
|
|
249
251
|
};
|
|
250
252
|
export const _encodeObjectIdentifier = (value, elGetter) => {
|
|
251
253
|
const el = elGetter(value, elGetter);
|
|
252
|
-
el.
|
|
254
|
+
el.value = value.toBytes();
|
|
253
255
|
el.tagClass = ASN1TagClass.universal;
|
|
254
256
|
el.tagNumber = ASN1UniversalType.objectIdentifier;
|
|
255
257
|
return el;
|
|
256
258
|
};
|
|
257
259
|
export const _decodeObjectIdentifier = (el) => {
|
|
258
|
-
return el.
|
|
260
|
+
return ObjectIdentifier.fromBytes(el.value);
|
|
259
261
|
};
|
|
260
262
|
export const _encodeOctetString = (value, elGetter) => {
|
|
261
263
|
const el = elGetter(value, elGetter);
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { SingleThreadBuffer } from "../macros.mjs";
|
|
2
2
|
export default class ObjectIdentifier {
|
|
3
3
|
protected encoding: Uint8Array;
|
|
4
|
+
toBytesUnsafe(): Uint8Array;
|
|
5
|
+
byteLength(): number;
|
|
4
6
|
static fromParts(nodes: number[], prefix?: ObjectIdentifier | number): ObjectIdentifier;
|
|
5
7
|
get nodes(): number[];
|
|
8
|
+
private dotDelimitedNotationCached;
|
|
6
9
|
get dotDelimitedNotation(): string;
|
|
7
10
|
get asn1Notation(): string;
|
|
8
11
|
toString(): string;
|
|
@@ -6,6 +6,13 @@ const PERIOD = ".".charCodeAt(0);
|
|
|
6
6
|
export default class ObjectIdentifier {
|
|
7
7
|
constructor() {
|
|
8
8
|
this.encoding = new Uint8Array(0);
|
|
9
|
+
this.dotDelimitedNotationCached = null;
|
|
10
|
+
}
|
|
11
|
+
toBytesUnsafe() {
|
|
12
|
+
return this.encoding;
|
|
13
|
+
}
|
|
14
|
+
byteLength() {
|
|
15
|
+
return this.encoding.length;
|
|
9
16
|
}
|
|
10
17
|
static fromParts(nodes, prefix) {
|
|
11
18
|
let _nodes = typeof prefix === "number" ? [prefix, ...nodes] : nodes;
|
|
@@ -43,7 +50,12 @@ export default class ObjectIdentifier {
|
|
|
43
50
|
];
|
|
44
51
|
}
|
|
45
52
|
get dotDelimitedNotation() {
|
|
46
|
-
|
|
53
|
+
if (this.dotDelimitedNotationCached) {
|
|
54
|
+
return this.dotDelimitedNotationCached;
|
|
55
|
+
}
|
|
56
|
+
const ret = this.nodes.join(".");
|
|
57
|
+
this.dotDelimitedNotationCached = ret;
|
|
58
|
+
return ret;
|
|
47
59
|
}
|
|
48
60
|
get asn1Notation() {
|
|
49
61
|
return `{ ${Array.from(this.nodes).map((node) => node.toString()).join(" ")} }`;
|
package/dist/utils/bigint.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { Buffer } from "node:buffer";
|
|
|
3
3
|
export function bufferToInteger(input) {
|
|
4
4
|
const buf = (input instanceof Buffer)
|
|
5
5
|
? input
|
|
6
|
-
: Buffer.from(input.buffer);
|
|
6
|
+
: Buffer.from(input.buffer, input.byteOffset, input.byteLength);
|
|
7
7
|
switch (buf.length) {
|
|
8
8
|
case (0): return 0;
|
|
9
9
|
case (1): return buf.readInt8();
|
package/package.json
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
],
|
|
13
13
|
"description": "ASN.1 encoding and decoding, including BER, CER, and DER.",
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@types/node": "^
|
|
16
|
-
"typescript": "^
|
|
15
|
+
"@types/node": "^25.5.0",
|
|
16
|
+
"typescript": "^6.0.2"
|
|
17
17
|
},
|
|
18
18
|
"directories": {
|
|
19
19
|
"doc": "documentation",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"test": "node --test"
|
|
49
49
|
},
|
|
50
50
|
"types": "./dist/index.d.mts",
|
|
51
|
-
"version": "11.0
|
|
51
|
+
"version": "11.1.0",
|
|
52
52
|
"exports": {
|
|
53
53
|
".": {
|
|
54
54
|
"import": "./dist/index.mjs",
|