functionalscript 0.9.2 → 0.10.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/bnf/data/test.f.d.ts +2 -0
- package/bnf/data/test.f.js +39 -2
- package/bnf/module.f.d.ts +3 -2
- package/bnf/module.f.js +5 -4
- package/cas/module.f.d.ts +5 -0
- package/cas/module.f.js +5 -0
- package/ci/module.f.js +45 -35
- package/ci/module.js +3 -3
- package/crypto/hmac/test.f.js +1 -1
- package/crypto/sign/module.f.d.ts +5 -0
- package/crypto/sign/test.f.js +1 -1
- package/dev/index/module.js +2 -2
- package/dev/module.f.d.ts +5 -0
- package/dev/module.f.js +5 -0
- package/dev/tf/all.test.js +2 -2
- package/dev/tf/module.f.js +7 -2
- package/dev/version/module.f.js +5 -0
- package/djs/ast/module.f.d.ts +5 -0
- package/djs/module.f.d.ts +5 -0
- package/djs/parser/module.f.d.ts +5 -0
- package/djs/parser/module.f.js +5 -0
- package/djs/parser-new/module.f.js +6 -2
- package/djs/parser-new/test.f.js +2 -1
- package/djs/serializer/module.f.d.ts +5 -0
- package/djs/transpiler/module.f.d.ts +5 -0
- package/djs/transpiler/module.f.js +5 -0
- package/fjs/module.f.d.ts +5 -0
- package/fjs/module.f.js +5 -0
- package/fjs/module.js +2 -2
- package/fsc/module.f.js +5 -0
- package/fsm/module.f.d.ts +5 -0
- package/fsm/module.f.js +5 -0
- package/io/module.d.ts +3 -3
- package/io/module.f.d.ts +1 -1
- package/io/module.f.js +8 -1
- package/io/module.js +8 -7
- package/io/virtual/module.f.d.ts +5 -0
- package/json/parser/module.f.d.ts +5 -0
- package/json/parser/module.f.js +5 -0
- package/json/serializer/module.f.d.ts +5 -0
- package/json/serializer/module.f.js +5 -0
- package/json/tokenizer/module.f.js +5 -0
- package/package.json +1 -1
- package/path/module.f.d.ts +5 -0
- package/text/utf8/module.f.d.ts +1 -1
- package/types/asn.1/module.f.d.ts +62 -0
- package/types/asn.1/module.f.js +276 -0
- package/types/asn.1/test.f.d.ts +44 -0
- package/types/asn.1/test.f.js +312 -0
- package/types/base128/module.f.d.ts +20 -0
- package/types/base128/module.f.js +43 -0
- package/types/base128/test.f.d.ts +2 -0
- package/types/base128/test.f.js +26 -0
- package/types/bigfloat/module.f.js +5 -0
- package/types/bit_vec/module.f.d.ts +14 -3
- package/types/bit_vec/module.f.js +21 -2
- package/types/bit_vec/test.f.d.ts +1 -0
- package/types/bit_vec/test.f.js +28 -6
- package/types/btree/find/module.f.d.ts +5 -0
- package/types/btree/module.f.d.ts +5 -0
- package/types/btree/module.f.js +5 -0
- package/types/btree/remove/module.f.d.ts +5 -0
- package/types/btree/set/module.f.d.ts +5 -0
- package/types/btree/types/module.f.d.ts +5 -0
- package/types/byte_set/module.f.js +5 -0
- package/types/cbase32/module.f.d.ts +5 -0
- package/types/cbase32/module.f.js +5 -0
- package/types/effect/mock/module.f.d.ts +5 -0
- package/types/effect/module.f.d.ts +5 -0
- package/types/effect/node/module.f.d.ts +5 -1
- package/types/effect/node/module.f.js +1 -0
- package/types/effect/node/test.f.d.ts +1 -0
- package/types/effect/node/test.f.js +19 -1
- package/types/effect/node/virtual/module.f.d.ts +3 -0
- package/types/effect/node/virtual/module.f.js +10 -0
- package/types/function/compare/module.f.d.ts +5 -0
- package/types/function/operator/module.f.d.ts +5 -0
- package/types/list/module.f.js +5 -0
- package/types/map/module.f.js +5 -0
- package/types/nibble_set/module.f.d.ts +5 -0
- package/types/nominal/module.f.d.ts +5 -0
- package/types/nullable/module.f.d.ts +5 -0
- package/types/ordered_map/module.f.d.ts +5 -0
- package/types/range/module.f.d.ts +5 -0
- package/types/sorted_list/module.f.d.ts +5 -0
- package/website/module.f.js +5 -0
- package/website/module.js +3 -3
package/io/virtual/module.f.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Virtual I/O adapter implementations for deterministic testing.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
1
6
|
import type { Io } from '../module.f.ts';
|
|
2
7
|
import { type OrderedMap } from '../../types/ordered_map/module.f.ts';
|
|
3
8
|
export declare const createVirtualIo: (files: OrderedMap<Uint8Array>) => Io;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON parser that consumes tokenizer output into JSON values.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
1
6
|
import { type Result } from '../../types/result/module.f.ts';
|
|
2
7
|
import { type List } from '../../types/list/module.f.ts';
|
|
3
8
|
import { type JsonToken } from '../tokenizer/module.f.ts';
|
package/json/parser/module.f.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON parser that consumes tokenizer output into JSON values.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
1
6
|
import { error, ok } from "../../types/result/module.f.js";
|
|
2
7
|
import { fold, first, drop, toArray, concat } from "../../types/list/module.f.js";
|
|
3
8
|
import {} from "../../types/function/operator/module.f.js";
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON serializer for deterministic string output.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
1
6
|
import { type List } from '../../types/list/module.f.ts';
|
|
2
7
|
export declare const stringSerialize: (_: string) => List<string>;
|
|
3
8
|
export declare const numberSerialize: (_: number) => List<string>;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tokenizer for JSON lexical analysis.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
1
6
|
import {} from "../../types/function/operator/module.f.js";
|
|
2
7
|
import { concat, empty, flat, stateScan } from "../../types/list/module.f.js";
|
|
3
8
|
import { multiply } from "../../types/bigfloat/module.f.js";
|
package/package.json
CHANGED
package/path/module.f.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path parsing and normalization helpers for portable module paths.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
1
6
|
import type { Reduce, Unary } from "../types/function/operator/module.f.ts";
|
|
2
7
|
export declare const parse: (path: string) => readonly string[];
|
|
3
8
|
export declare const normalize: Unary<string, string>;
|
package/text/utf8/module.f.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type U8 = number;
|
|
|
9
9
|
*/
|
|
10
10
|
export type I32 = number;
|
|
11
11
|
/**
|
|
12
|
-
* Represents an
|
|
12
|
+
* Represents an unsigned 8-bit type - U8 or the end-of-file indicator.
|
|
13
13
|
* The U8 represents the byte itself, and null indicates that reading does not return anything else.
|
|
14
14
|
*/
|
|
15
15
|
export type ByteOrEof = U8 | null;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type Vec } from "../bit_vec/module.f.ts";
|
|
2
|
+
/** ASN.1 tag number. */
|
|
3
|
+
type Tag = bigint;
|
|
4
|
+
/** ASN.1 universal BOOLEAN tag. */
|
|
5
|
+
export declare const boolean = 1n;
|
|
6
|
+
/** ASN.1 universal INTEGER tag. */
|
|
7
|
+
export declare const integer = 2n;
|
|
8
|
+
/** ASN.1 universal OCTET STRING tag. */
|
|
9
|
+
export declare const octetString = 4n;
|
|
10
|
+
/** ASN.1 universal OBJECT IDENTIFIER tag. */
|
|
11
|
+
export declare const objectIdentifier = 6n;
|
|
12
|
+
export declare const constructedSequence = 48n;
|
|
13
|
+
export declare const constructedSet = 49n;
|
|
14
|
+
/** Raw ASN.1 TLV tuple. */
|
|
15
|
+
export type Raw = readonly [Tag, Vec];
|
|
16
|
+
/** Encodes a raw ASN.1 TLV tuple into a bit vector. */
|
|
17
|
+
export declare const encodeRaw: ([tag, value]: Raw) => Vec;
|
|
18
|
+
/** Decodes a raw ASN.1 TLV tuple and returns the remaining input. */
|
|
19
|
+
export declare const decodeRaw: (v: Vec) => readonly [Raw, Vec];
|
|
20
|
+
/** Encodes a JavaScript boolean as an ASN.1 BOOLEAN value. */
|
|
21
|
+
export declare const encodeBoolean: (b: boolean) => Vec;
|
|
22
|
+
/** Decodes an ASN.1 BOOLEAN value. */
|
|
23
|
+
export declare const decodeBoolean: (v: Vec) => boolean;
|
|
24
|
+
/** Encodes a signed bigint using ASN.1 INTEGER two's complement representation. */
|
|
25
|
+
export declare const encodeInteger: (uint: bigint) => Vec;
|
|
26
|
+
/** Decodes an ASN.1 INTEGER encoded in two's complement. */
|
|
27
|
+
export declare const decodeInteger: (v: Vec) => bigint;
|
|
28
|
+
/** Encodes an OCTET STRING value. */
|
|
29
|
+
export declare const encodeOctetString: (v: Vec) => Vec;
|
|
30
|
+
/** Decodes an OCTET STRING value. */
|
|
31
|
+
export declare const decodeOctetString: (v: Vec) => Vec;
|
|
32
|
+
/** ASN.1 OBJECT IDENTIFIER components. */
|
|
33
|
+
export type ObjectIdentifier = readonly bigint[];
|
|
34
|
+
/** Encodes an OBJECT IDENTIFIER value. */
|
|
35
|
+
export declare const encodeObjectIdentifier: (oid: ObjectIdentifier) => Vec;
|
|
36
|
+
/** Decodes an OBJECT IDENTIFIER value. */
|
|
37
|
+
export declare const decodeObjectIdentifier: (v: Vec) => ObjectIdentifier;
|
|
38
|
+
/** ASN.1 ordered collection of records. */
|
|
39
|
+
export type Sequence = readonly Record[];
|
|
40
|
+
/** Encodes a SEQUENCE payload from ordered records. */
|
|
41
|
+
export declare const encodeSequence: (...records: Sequence) => Vec;
|
|
42
|
+
/** Decodes a SEQUENCE payload into records. */
|
|
43
|
+
export declare const decodeSequence: (v: Vec) => Sequence;
|
|
44
|
+
/** ASN.1 SET represented as a sequence of records. */
|
|
45
|
+
export type Set = Sequence;
|
|
46
|
+
/** Encodes a SET payload with canonical byte ordering. */
|
|
47
|
+
export declare const encodeSet: (...records: Sequence) => Vec;
|
|
48
|
+
/** Decodes a SET payload. */
|
|
49
|
+
export declare const decodeSet: (v: Vec) => Sequence;
|
|
50
|
+
/** Supported ASN.1 record variants. */
|
|
51
|
+
export type SupportedRecord = readonly [typeof boolean, boolean] | readonly [typeof integer, bigint] | readonly [typeof octetString, Vec] | readonly [typeof objectIdentifier, ObjectIdentifier] | readonly [typeof constructedSequence, Sequence] | readonly [typeof constructedSet, Set];
|
|
52
|
+
/**
|
|
53
|
+
* For unsupported tags, we just store the raw value including the tag and length,
|
|
54
|
+
* so that it can be re-encoded without loss of information.
|
|
55
|
+
*/
|
|
56
|
+
export type UnsupportedRecord = Vec;
|
|
57
|
+
export type Record = SupportedRecord | UnsupportedRecord;
|
|
58
|
+
/** Encodes a supported ASN.1 record as TLV. */
|
|
59
|
+
export declare const encode: (record: Record) => Vec;
|
|
60
|
+
/** Decodes one supported ASN.1 record and returns the remaining input. */
|
|
61
|
+
export declare const decode: (v: Vec) => readonly [Record, Vec];
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { bitLength, max } from "../bigint/module.f.js";
|
|
2
|
+
import { empty, isVec, length, listToVec, msb, msbCmp, uint, unpack, vec, vec8 } from "../bit_vec/module.f.js";
|
|
3
|
+
import { identity } from "../function/module.f.js";
|
|
4
|
+
import { encode as b128encode, decode as b128decode } from "../base128/module.f.js";
|
|
5
|
+
const pop = msb.popFront;
|
|
6
|
+
const pop8 = pop(8n);
|
|
7
|
+
const concat = listToVec(msb);
|
|
8
|
+
const classPcMask = 224n;
|
|
9
|
+
const tagNumberMask = 31n;
|
|
10
|
+
const parsedTagEncode = ([classPc, number]) => {
|
|
11
|
+
const [firstByteNumber, rest] = number < tagNumberMask
|
|
12
|
+
? [number, empty]
|
|
13
|
+
: [tagNumberMask, b128encode(number)];
|
|
14
|
+
return concat([vec8(classPc | firstByteNumber), rest]);
|
|
15
|
+
};
|
|
16
|
+
const parsedTagDecode = (v) => {
|
|
17
|
+
const [firstByte, rest] = pop8(v);
|
|
18
|
+
const classPc = (firstByte & classPcMask);
|
|
19
|
+
const firstByteNumber = firstByte & tagNumberMask;
|
|
20
|
+
const [number, rest1] = firstByteNumber < tagNumberMask
|
|
21
|
+
? [firstByteNumber, rest]
|
|
22
|
+
: b128decode(rest);
|
|
23
|
+
return [[classPc, number], rest1];
|
|
24
|
+
};
|
|
25
|
+
const tagEncode = (tag) => vec(max((bitLength(tag) + 7n) >> 3n)(1n) << 3n)(tag);
|
|
26
|
+
const tagDecode = (v) => {
|
|
27
|
+
const [parsedTag, rest] = parsedTagDecode(v);
|
|
28
|
+
return [uint(parsedTagEncode(parsedTag)), rest];
|
|
29
|
+
};
|
|
30
|
+
//
|
|
31
|
+
const eoc = 0x00n;
|
|
32
|
+
/** ASN.1 universal BOOLEAN tag. */
|
|
33
|
+
export const boolean = 0x01n;
|
|
34
|
+
/** ASN.1 universal INTEGER tag. */
|
|
35
|
+
export const integer = 0x02n;
|
|
36
|
+
const bitString = 0x03n;
|
|
37
|
+
/** ASN.1 universal OCTET STRING tag. */
|
|
38
|
+
export const octetString = 0x04n;
|
|
39
|
+
const null_ = 0x05;
|
|
40
|
+
/** ASN.1 universal OBJECT IDENTIFIER tag. */
|
|
41
|
+
export const objectIdentifier = 0x06n;
|
|
42
|
+
const objectDescriptor = 0x07;
|
|
43
|
+
const external = 0x08;
|
|
44
|
+
const real = 0x09;
|
|
45
|
+
const enumerated = 0x0A;
|
|
46
|
+
const embeddedPdv = 0x0B;
|
|
47
|
+
const utf8string = 0x0C;
|
|
48
|
+
const relativeOid = 0x0D;
|
|
49
|
+
const time = 0x0E;
|
|
50
|
+
const sequence = 0x10;
|
|
51
|
+
const set = 0x11;
|
|
52
|
+
const numericString = 0x12;
|
|
53
|
+
const printableString = 0x13;
|
|
54
|
+
const t61String = 0x14;
|
|
55
|
+
const videotexString = 0x15;
|
|
56
|
+
const ia5String = 0x16;
|
|
57
|
+
const utcTime = 0x17;
|
|
58
|
+
const generalizedTime = 0x18;
|
|
59
|
+
const graphicString = 0x19;
|
|
60
|
+
const visibleString = 0x1A;
|
|
61
|
+
const generalString = 0x1B;
|
|
62
|
+
const universalString = 0x1C;
|
|
63
|
+
const characterString = 0x1D;
|
|
64
|
+
const bmpString = 0x1E;
|
|
65
|
+
const date = 0x1F;
|
|
66
|
+
const timeOfDay = 0x20;
|
|
67
|
+
const dateTime = 0x21;
|
|
68
|
+
const duration = 0x22;
|
|
69
|
+
const oidIri = 0x23;
|
|
70
|
+
const relativeOidIri = 0x24;
|
|
71
|
+
const constructed = 0x20;
|
|
72
|
+
export const constructedSequence = 0x30n; // constructed | sequence
|
|
73
|
+
export const constructedSet = 0x31n; // constructed | set
|
|
74
|
+
const round8 = ({ length, uint }) => {
|
|
75
|
+
const byteLen = (length + 7n) >> 3n;
|
|
76
|
+
return { byteLen, v: vec(byteLen << 3n)(uint) };
|
|
77
|
+
};
|
|
78
|
+
const lenEncode = (uint) => {
|
|
79
|
+
if (uint < 0x80n) {
|
|
80
|
+
return vec8(uint);
|
|
81
|
+
}
|
|
82
|
+
const { byteLen, v } = round8({ length: bitLength(uint), uint });
|
|
83
|
+
return concat([vec8(0x80n | byteLen), v]);
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Decodes the length field of an ASN.1 TLV and returns the length in bits and the remaining input.
|
|
87
|
+
*
|
|
88
|
+
* @param v - The input bit vector starting with the length field.
|
|
89
|
+
* @returns A tuple containing the length in bits and the remaining input after the length field.
|
|
90
|
+
*/
|
|
91
|
+
const lenDecode = (v) => {
|
|
92
|
+
const firstAndRest = pop8(v);
|
|
93
|
+
const [first, rest1] = firstAndRest;
|
|
94
|
+
const [byteLen, rest2] = first < 0x80n ? firstAndRest : pop((first & 0x7fn) << 3n)(rest1);
|
|
95
|
+
return [byteLen << 3n, rest2];
|
|
96
|
+
};
|
|
97
|
+
/** Encodes a raw ASN.1 TLV tuple into a bit vector. */
|
|
98
|
+
export const encodeRaw = ([tag, value]) => {
|
|
99
|
+
const tagVec = tagEncode(tag);
|
|
100
|
+
const { byteLen, v } = round8(unpack(value));
|
|
101
|
+
return concat([tagVec, lenEncode(byteLen), v]);
|
|
102
|
+
};
|
|
103
|
+
/** Decodes a raw ASN.1 TLV tuple and returns the remaining input. */
|
|
104
|
+
export const decodeRaw = (v) => {
|
|
105
|
+
const [tag, v1] = tagDecode(v);
|
|
106
|
+
const [len, v2] = lenDecode(v1);
|
|
107
|
+
const [result, next] = pop(len)(v2);
|
|
108
|
+
return [[tag, vec(len)(result)], next];
|
|
109
|
+
};
|
|
110
|
+
// boolean
|
|
111
|
+
/** Encodes a JavaScript boolean as an ASN.1 BOOLEAN value. */
|
|
112
|
+
export const encodeBoolean = (b) => vec8(b ? 0xffn : 0x00n);
|
|
113
|
+
/** Decodes an ASN.1 BOOLEAN value. */
|
|
114
|
+
export const decodeBoolean = (v) => uint(v) !== 0n;
|
|
115
|
+
// integer (two's compliment)
|
|
116
|
+
/** Encodes a signed bigint using ASN.1 INTEGER two's complement representation. */
|
|
117
|
+
export const encodeInteger = (uint) => {
|
|
118
|
+
const offset = uint < 0n ? 1n : 0n;
|
|
119
|
+
return round8({ length: bitLength(uint + offset) + 1n, uint }).v;
|
|
120
|
+
};
|
|
121
|
+
/** Decodes an ASN.1 INTEGER encoded in two's complement. */
|
|
122
|
+
export const decodeInteger = (v) => {
|
|
123
|
+
const { length, uint } = unpack(v);
|
|
124
|
+
const sign = uint >> (length - 1n);
|
|
125
|
+
return sign === 0n ? uint : uint - (1n << length);
|
|
126
|
+
};
|
|
127
|
+
// octet string
|
|
128
|
+
/** Encodes an OCTET STRING value. */
|
|
129
|
+
export const encodeOctetString = (v) => v;
|
|
130
|
+
/** Decodes an OCTET STRING value. */
|
|
131
|
+
export const decodeOctetString = (v) => v;
|
|
132
|
+
/** Encodes an OBJECT IDENTIFIER value. */
|
|
133
|
+
export const encodeObjectIdentifier = (oid) => {
|
|
134
|
+
const [first, second, ...rest] = oid;
|
|
135
|
+
const firstByte = first * 40n + second;
|
|
136
|
+
return concat([vec8(firstByte), ...rest.map(b128encode)]);
|
|
137
|
+
};
|
|
138
|
+
/** Decodes an OBJECT IDENTIFIER value. */
|
|
139
|
+
export const decodeObjectIdentifier = (v) => {
|
|
140
|
+
const [firstByte, rest] = pop8(v);
|
|
141
|
+
const first = firstByte / 40n;
|
|
142
|
+
const second = firstByte % 40n;
|
|
143
|
+
let result = [first, second];
|
|
144
|
+
let tail = rest;
|
|
145
|
+
while (length(tail) > 0n) {
|
|
146
|
+
const [value, next] = b128decode(tail);
|
|
147
|
+
result = [...result, value];
|
|
148
|
+
tail = next;
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
};
|
|
152
|
+
const genericEncodeSequence = (map) => (...records) => concat(map(records.map(encode)));
|
|
153
|
+
/** Encodes a SEQUENCE payload from ordered records. */
|
|
154
|
+
export const encodeSequence = genericEncodeSequence(identity);
|
|
155
|
+
/** Decodes a SEQUENCE payload into records. */
|
|
156
|
+
export const decodeSequence = (v) => {
|
|
157
|
+
let result = [];
|
|
158
|
+
while (length(v) !== 0n) {
|
|
159
|
+
const [record, rest] = decode(v);
|
|
160
|
+
result = [...result, record];
|
|
161
|
+
v = rest;
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
};
|
|
165
|
+
/** Encodes a SET payload with canonical byte ordering. */
|
|
166
|
+
export const encodeSet = genericEncodeSequence(v => v.toSorted((a, b) => msbCmp(a)(b)));
|
|
167
|
+
/** Decodes a SET payload. */
|
|
168
|
+
export const decodeSet = decodeSequence;
|
|
169
|
+
// encode
|
|
170
|
+
const recordToRaw = ([tag, value]) => {
|
|
171
|
+
switch (tag) {
|
|
172
|
+
case boolean: return encodeBoolean(value);
|
|
173
|
+
case integer: return encodeInteger(value);
|
|
174
|
+
case octetString: return encodeOctetString(value);
|
|
175
|
+
case objectIdentifier: return encodeObjectIdentifier(value);
|
|
176
|
+
case constructedSequence: return encodeSequence(...value);
|
|
177
|
+
case constructedSet: return encodeSet(...value);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
/** Encodes a supported ASN.1 record as TLV. */
|
|
181
|
+
export const encode = (record) => isVec(record) ? record : encodeRaw([record[0], recordToRaw(record)]);
|
|
182
|
+
// decode
|
|
183
|
+
const rawToRecord = (raw) => {
|
|
184
|
+
const [tag, value] = raw;
|
|
185
|
+
switch (tag) {
|
|
186
|
+
case boolean: return [boolean, decodeBoolean(value)];
|
|
187
|
+
case integer: return [integer, decodeInteger(value)];
|
|
188
|
+
case octetString: return [octetString, decodeOctetString(value)];
|
|
189
|
+
case objectIdentifier: return [objectIdentifier, decodeObjectIdentifier(value)];
|
|
190
|
+
case constructedSequence: return [constructedSequence, decodeSequence(value)];
|
|
191
|
+
case constructedSet: return [constructedSet, decodeSet(value)];
|
|
192
|
+
default: return encodeRaw(raw);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
/** Decodes one supported ASN.1 record and returns the remaining input. */
|
|
196
|
+
export const decode = (v) => {
|
|
197
|
+
const [raw, rest] = decodeRaw(v);
|
|
198
|
+
return [rawToRecord(raw), rest];
|
|
199
|
+
};
|
|
200
|
+
/*
|
|
201
|
+
TimeStampReq ::= SEQUENCE {
|
|
202
|
+
version INTEGER { v1(1) }, // [x]
|
|
203
|
+
messageImprint MessageImprint,
|
|
204
|
+
reqPolicy TSAPolicyId OPTIONAL,
|
|
205
|
+
nonce INTEGER OPTIONAL, // [X]
|
|
206
|
+
certReq BOOLEAN DEFAULT FALSE, // [X]
|
|
207
|
+
extensions [0] IMPLICIT Extensions OPTIONAL // [X]
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
MessageImprint ::= SEQUENCE {
|
|
211
|
+
hashAlgorithm AlgorithmIdentifier,
|
|
212
|
+
hashedMessage OCTET STRING // [X]
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
TSAPolicyId ::= OBJECT IDENTIFIER // [X]
|
|
216
|
+
*/
|
|
217
|
+
/*
|
|
218
|
+
TimeStampResp ::= SEQUENCE {
|
|
219
|
+
status PKIStatusInfo,
|
|
220
|
+
timeStampToken TimeStampToken OPTIONAL
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
PKIStatusInfo ::= SEQUENCE {
|
|
224
|
+
status PKIStatus,
|
|
225
|
+
statusString PKIFreeText OPTIONAL,
|
|
226
|
+
failInfo PKIFailureInfo OPTIONAL
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
PKIStatus ::= INTEGER { // [X]
|
|
230
|
+
granted (0),
|
|
231
|
+
grantedWithMods (1),
|
|
232
|
+
rejection (2),
|
|
233
|
+
waiting (3),
|
|
234
|
+
revocationWarning (4),
|
|
235
|
+
revocationNotification (5)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
TimeStampToken ::= ContentInfo
|
|
239
|
+
|
|
240
|
+
ContentInfo ::= SEQUENCE {
|
|
241
|
+
contentType ContentType,
|
|
242
|
+
content [0] EXPLICIT ANY DEFINED BY contentType
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
ContentType ::= OBJECT IDENTIFIER
|
|
246
|
+
|
|
247
|
+
SignedData ::= SEQUENCE {
|
|
248
|
+
version CMSVersion,
|
|
249
|
+
digestAlgorithms SET OF DigestAlgorithmIdentifier, // [X]
|
|
250
|
+
encapContentInfo EncapsulatedContentInfo,
|
|
251
|
+
certificates [0] IMPLICIT CertificateSet OPTIONAL,
|
|
252
|
+
crls [1] IMPLICIT RevocationInfoChoices OPTIONAL,
|
|
253
|
+
signerInfos SET OF SignerInfo // [X]
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
EncapsulatedContentInfo ::= SEQUENCE {
|
|
257
|
+
eContentType ContentType,
|
|
258
|
+
eContent [0] EXPLICIT OCTET STRING OPTIONAL
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
TSTInfo ::= SEQUENCE {
|
|
262
|
+
version INTEGER { v1(1) },
|
|
263
|
+
policy TSAPolicyId,
|
|
264
|
+
messageImprint MessageImprint,
|
|
265
|
+
serialNumber INTEGER,
|
|
266
|
+
genTime GeneralizedTime,
|
|
267
|
+
accuracy Accuracy OPTIONAL,
|
|
268
|
+
ordering BOOLEAN DEFAULT FALSE,
|
|
269
|
+
nonce INTEGER OPTIONAL,
|
|
270
|
+
tsa [0] GeneralName OPTIONAL,
|
|
271
|
+
extensions [1] IMPLICIT Extensions OPTIONAL
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
Bits: 8 7 | 6 | 5 4 3 2 1
|
|
275
|
+
Class | P/C | Tag number
|
|
276
|
+
*/
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
encodeSmall: () => void;
|
|
3
|
+
encode7F: () => void;
|
|
4
|
+
encode80: () => void;
|
|
5
|
+
encodeFF: () => void;
|
|
6
|
+
encode103: () => void;
|
|
7
|
+
ed: ((() => void) | {
|
|
8
|
+
x80: () => void;
|
|
9
|
+
x100: () => void;
|
|
10
|
+
x1000: () => void;
|
|
11
|
+
x10000: () => void;
|
|
12
|
+
x20000: () => void;
|
|
13
|
+
x40000: () => void;
|
|
14
|
+
x80000: () => void;
|
|
15
|
+
xC0000: () => void;
|
|
16
|
+
xE0000: () => void;
|
|
17
|
+
xF0000: () => void;
|
|
18
|
+
xFFF00: () => void;
|
|
19
|
+
xFFF80: () => void;
|
|
20
|
+
xFFFC0: () => void;
|
|
21
|
+
xFFFD0: () => void;
|
|
22
|
+
})[];
|
|
23
|
+
integerValue: {
|
|
24
|
+
zero: () => void;
|
|
25
|
+
one: () => void;
|
|
26
|
+
minusOne: () => void;
|
|
27
|
+
x7F: () => void;
|
|
28
|
+
x80: () => void;
|
|
29
|
+
xFF: () => void;
|
|
30
|
+
nx7F: () => void;
|
|
31
|
+
nx80: () => void;
|
|
32
|
+
nx81: () => void;
|
|
33
|
+
nx7FFF: () => void;
|
|
34
|
+
nx8000: () => void;
|
|
35
|
+
nx8001: () => void;
|
|
36
|
+
};
|
|
37
|
+
encodeDecode: {
|
|
38
|
+
integer: () => void;
|
|
39
|
+
sequence: () => void;
|
|
40
|
+
set: () => void;
|
|
41
|
+
};
|
|
42
|
+
raw: (() => void)[];
|
|
43
|
+
};
|
|
44
|
+
export default _default;
|