asn1-ts 11.0.4 → 11.0.6

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 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/macros.d.mts CHANGED
@@ -2,6 +2,7 @@ import type ObjectIdentifier from "./types/ObjectIdentifier.mjs";
2
2
  import type EmbeddedPDV from "./types/EmbeddedPDV.mjs";
3
3
  import type External from "./types/External.mjs";
4
4
  import type DURATION_EQUIVALENT from "./types/time/DURATION-EQUIVALENT.mjs";
5
+ import type { Buffer } from "node:buffer";
5
6
  export type SingleThreadUint8Array = ReturnType<Uint8Array['slice']>;
6
7
  export type SingleThreadBuffer = ReturnType<Buffer["filter"]>;
7
8
  export type COMPONENTS_OF<T> = T;
@@ -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
@@ -48,8 +48,15 @@
48
48
  "test": "node --test"
49
49
  },
50
50
  "types": "./dist/index.d.mts",
51
- "version": "11.0.4",
51
+ "version": "11.0.6",
52
52
  "exports": {
53
- "./functional": "./dist/functional.mjs"
53
+ ".": {
54
+ "import": "./dist/index.mjs",
55
+ "types": "./dist/index.d.mts"
56
+ },
57
+ "./functional": {
58
+ "import": "./dist/functional.mjs",
59
+ "types": "./dist/functional.d.mts"
60
+ }
54
61
  }
55
62
  }
@@ -1,11 +0,0 @@
1
- import type ASN1Element from "./asn1.mjs";
2
- import { ASN1TagClass, ASN1Construction, ASN1UniversalType } from "./values.mjs";
3
- export default interface ConstructedElementSpecification {
4
- name: string;
5
- optional?: boolean;
6
- tagClass?: ASN1TagClass;
7
- construction?: ASN1Construction;
8
- tagNumber?: ASN1UniversalType;
9
- choice?: ConstructedElementSpecification[];
10
- callback?: (el: ASN1Element) => void;
11
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import type ASN1Element from "../asn1.mjs";
2
- import type ConstructedElementSpecification from "../ConstructedElementSpecification.mjs";
3
- export default function validateConstruction(elements: ASN1Element[], specification: ConstructedElementSpecification[]): void;
@@ -1,37 +0,0 @@
1
- import * as errors from "../errors.mjs";
2
- export default function validateConstruction(elements, specification) {
3
- let i = 0;
4
- for (const spec of specification) {
5
- if ((i >= elements.length)
6
- || (spec.tagClass && spec.tagClass !== elements[i].tagClass)
7
- || (spec.construction && spec.construction !== elements[i].construction)
8
- || (spec.tagNumber && spec.tagNumber !== elements[i].tagNumber)) {
9
- if (!spec.optional) {
10
- throw new errors.ASN1ConstructionError(`Missing required element '${spec.name}'.`);
11
- }
12
- continue;
13
- }
14
- if (spec.choice && spec.choice.length > 0) {
15
- let matchingChoiceFound = false;
16
- for (let j = 0; j < spec.choice.length; j++) {
17
- const choice = spec.choice[j];
18
- if ((!(choice.tagClass) || (choice.tagClass === elements[i].tagClass))
19
- && (!(choice.construction) || (choice.construction === elements[i].construction))
20
- && (!(choice.tagNumber) || (choice.tagNumber === elements[i].tagNumber))) {
21
- if (choice.callback) {
22
- choice.callback(elements[i]);
23
- }
24
- matchingChoiceFound = true;
25
- break;
26
- }
27
- }
28
- if (!matchingChoiceFound && !spec.optional) {
29
- throw new errors.ASN1ConstructionError(`Missing required CHOICE '${spec.name}'.`);
30
- }
31
- }
32
- if (spec.callback) {
33
- spec.callback(elements[i]);
34
- }
35
- i++;
36
- }
37
- }