node-opcua-crypto 4.2.0 → 4.3.1

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.
Files changed (143) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/dist/chunk-5NV4OKIV.mjs +1 -0
  4. package/dist/chunk-KPKFYTZJ.mjs +173 -0
  5. package/dist/chunk-QSSIRHMR.mjs +6243 -0
  6. package/dist/index.js +6521 -0
  7. package/dist/index.mjs +224 -0
  8. package/dist/source/index.js +6346 -0
  9. package/dist/source/index.mjs +192 -0
  10. package/dist/source/index_web.js +6346 -0
  11. package/dist/source/index_web.mjs +191 -0
  12. package/dist/source_nodejs/index.js +4170 -0
  13. package/dist/source_nodejs/index.mjs +37 -0
  14. package/dist-types/index.d.ts +2 -0
  15. package/dist-types/source/common.d.ts +21 -1
  16. package/dist-types/source/crypto_utils2.d.ts +2 -3
  17. package/dist-types/source/make_private_key_from_pem.d.ts +1 -1
  18. package/dist-types/source/x509/coerce_private_key.d.ts +5 -3
  19. package/dist-types/source/x509/create_key_pair.d.ts +6 -0
  20. package/dist-types/source/x509/create_self_signed_certificate.d.ts +4 -0
  21. package/dist-types/source_nodejs/read.d.ts +1 -0
  22. package/node-opcua-crypto-4.2.0.tgz +0 -0
  23. package/package.json +84 -91
  24. package/dist-cjs/source/asn1.js +0 -304
  25. package/dist-cjs/source/asn1.js.map +0 -1
  26. package/dist-cjs/source/buffer_utils.js +0 -9
  27. package/dist-cjs/source/buffer_utils.js.map +0 -1
  28. package/dist-cjs/source/common.js +0 -11
  29. package/dist-cjs/source/common.js.map +0 -1
  30. package/dist-cjs/source/crypto_explore_certificate.js +0 -367
  31. package/dist-cjs/source/crypto_explore_certificate.js.map +0 -1
  32. package/dist-cjs/source/crypto_utils.js +0 -200
  33. package/dist-cjs/source/crypto_utils.js.map +0 -1
  34. package/dist-cjs/source/crypto_utils2.js +0 -71
  35. package/dist-cjs/source/crypto_utils2.js.map +0 -1
  36. package/dist-cjs/source/derived_keys.js +0 -133
  37. package/dist-cjs/source/derived_keys.js.map +0 -1
  38. package/dist-cjs/source/explore_certificate.js +0 -37
  39. package/dist-cjs/source/explore_certificate.js.map +0 -1
  40. package/dist-cjs/source/explore_certificate_revocation_list.js +0 -69
  41. package/dist-cjs/source/explore_certificate_revocation_list.js.map +0 -1
  42. package/dist-cjs/source/explore_certificate_signing_request.js +0 -45
  43. package/dist-cjs/source/explore_certificate_signing_request.js.map +0 -1
  44. package/dist-cjs/source/explore_private_key.js +0 -77
  45. package/dist-cjs/source/explore_private_key.js.map +0 -1
  46. package/dist-cjs/source/index.js +0 -38
  47. package/dist-cjs/source/index.js.map +0 -1
  48. package/dist-cjs/source/make_private_key_from_pem.js +0 -8
  49. package/dist-cjs/source/make_private_key_from_pem.js.map +0 -1
  50. package/dist-cjs/source/oid_map.js +0 -300
  51. package/dist-cjs/source/oid_map.js.map +0 -1
  52. package/dist-cjs/source/public_private_match.js +0 -32
  53. package/dist-cjs/source/public_private_match.js.map +0 -1
  54. package/dist-cjs/source/subject.js +0 -92
  55. package/dist-cjs/source/subject.js.map +0 -1
  56. package/dist-cjs/source/verify_certificate_signature.js +0 -117
  57. package/dist-cjs/source/verify_certificate_signature.js.map +0 -1
  58. package/dist-cjs/source/x509/_build_public_key.js +0 -69
  59. package/dist-cjs/source/x509/_build_public_key.js.map +0 -1
  60. package/dist-cjs/source/x509/_crypto.js +0 -52
  61. package/dist-cjs/source/x509/_crypto.js.map +0 -1
  62. package/dist-cjs/source/x509/_get_attributes.js +0 -39
  63. package/dist-cjs/source/x509/_get_attributes.js.map +0 -1
  64. package/dist-cjs/source/x509/coerce_private_key.js +0 -90
  65. package/dist-cjs/source/x509/coerce_private_key.js.map +0 -1
  66. package/dist-cjs/source/x509/create_certificate_signing_request.js +0 -92
  67. package/dist-cjs/source/x509/create_certificate_signing_request.js.map +0 -1
  68. package/dist-cjs/source/x509/create_key_pair.js +0 -123
  69. package/dist-cjs/source/x509/create_key_pair.js.map +0 -1
  70. package/dist-cjs/source/x509/create_self_signed_certificate.js +0 -103
  71. package/dist-cjs/source/x509/create_self_signed_certificate.js.map +0 -1
  72. package/dist-cjs/source_nodejs/generate_private_key_filename.js +0 -88
  73. package/dist-cjs/source_nodejs/generate_private_key_filename.js.map +0 -1
  74. package/dist-cjs/source_nodejs/index.js +0 -21
  75. package/dist-cjs/source_nodejs/index.js.map +0 -1
  76. package/dist-cjs/source_nodejs/read.js +0 -115
  77. package/dist-cjs/source_nodejs/read.js.map +0 -1
  78. package/dist-cjs/source_nodejs/read_certificate_revocation_list.js +0 -64
  79. package/dist-cjs/source_nodejs/read_certificate_revocation_list.js.map +0 -1
  80. package/dist-cjs/source_nodejs/read_certificate_signing_request.js +0 -64
  81. package/dist-cjs/source_nodejs/read_certificate_signing_request.js.map +0 -1
  82. package/dist-esm/source/asn1.js +0 -275
  83. package/dist-esm/source/asn1.js.map +0 -1
  84. package/dist-esm/source/buffer_utils.js +0 -6
  85. package/dist-esm/source/buffer_utils.js.map +0 -1
  86. package/dist-esm/source/common.js +0 -8
  87. package/dist-esm/source/common.js.map +0 -1
  88. package/dist-esm/source/crypto_explore_certificate.js +0 -356
  89. package/dist-esm/source/crypto_explore_certificate.js.map +0 -1
  90. package/dist-esm/source/crypto_utils.js +0 -179
  91. package/dist-esm/source/crypto_utils.js.map +0 -1
  92. package/dist-esm/source/crypto_utils2.js +0 -58
  93. package/dist-esm/source/crypto_utils2.js.map +0 -1
  94. package/dist-esm/source/derived_keys.js +0 -117
  95. package/dist-esm/source/derived_keys.js.map +0 -1
  96. package/dist-esm/source/explore_certificate.js +0 -29
  97. package/dist-esm/source/explore_certificate.js.map +0 -1
  98. package/dist-esm/source/explore_certificate_revocation_list.js +0 -64
  99. package/dist-esm/source/explore_certificate_revocation_list.js.map +0 -1
  100. package/dist-esm/source/explore_certificate_signing_request.js +0 -40
  101. package/dist-esm/source/explore_certificate_signing_request.js.map +0 -1
  102. package/dist-esm/source/explore_private_key.js +0 -73
  103. package/dist-esm/source/explore_private_key.js.map +0 -1
  104. package/dist-esm/source/index.js +0 -19
  105. package/dist-esm/source/index.js.map +0 -1
  106. package/dist-esm/source/make_private_key_from_pem.js +0 -4
  107. package/dist-esm/source/make_private_key_from_pem.js.map +0 -1
  108. package/dist-esm/source/oid_map.js +0 -297
  109. package/dist-esm/source/oid_map.js.map +0 -1
  110. package/dist-esm/source/public_private_match.js +0 -27
  111. package/dist-esm/source/public_private_match.js.map +0 -1
  112. package/dist-esm/source/subject.js +0 -89
  113. package/dist-esm/source/subject.js.map +0 -1
  114. package/dist-esm/source/verify_certificate_signature.js +0 -110
  115. package/dist-esm/source/verify_certificate_signature.js.map +0 -1
  116. package/dist-esm/source/x509/_build_public_key.js +0 -65
  117. package/dist-esm/source/x509/_build_public_key.js.map +0 -1
  118. package/dist-esm/source/x509/_crypto.js +0 -25
  119. package/dist-esm/source/x509/_crypto.js.map +0 -1
  120. package/dist-esm/source/x509/_get_attributes.js +0 -35
  121. package/dist-esm/source/x509/_get_attributes.js.map +0 -1
  122. package/dist-esm/source/x509/coerce_private_key.js +0 -85
  123. package/dist-esm/source/x509/coerce_private_key.js.map +0 -1
  124. package/dist-esm/source/x509/create_certificate_signing_request.js +0 -88
  125. package/dist-esm/source/x509/create_certificate_signing_request.js.map +0 -1
  126. package/dist-esm/source/x509/create_key_pair.js +0 -115
  127. package/dist-esm/source/x509/create_key_pair.js.map +0 -1
  128. package/dist-esm/source/x509/create_self_signed_certificate.js +0 -99
  129. package/dist-esm/source/x509/create_self_signed_certificate.js.map +0 -1
  130. package/dist-esm/source_nodejs/generate_private_key_filename.js +0 -80
  131. package/dist-esm/source_nodejs/generate_private_key_filename.js.map +0 -1
  132. package/dist-esm/source_nodejs/index.js +0 -5
  133. package/dist-esm/source_nodejs/index.js.map +0 -1
  134. package/dist-esm/source_nodejs/read.js +0 -99
  135. package/dist-esm/source_nodejs/read.js.map +0 -1
  136. package/dist-esm/source_nodejs/read_certificate_revocation_list.js +0 -57
  137. package/dist-esm/source_nodejs/read_certificate_revocation_list.js.map +0 -1
  138. package/dist-esm/source_nodejs/read_certificate_signing_request.js +0 -57
  139. package/dist-esm/source_nodejs/read_certificate_signing_request.js.map +0 -1
  140. package/index.d.ts +0 -2
  141. package/index.js +0 -4
  142. package/index_web.d.ts +0 -1
  143. package/index_web.js +0 -3
@@ -0,0 +1,4170 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // source_nodejs/index.ts
31
+ var source_nodejs_exports = {};
32
+ __export(source_nodejs_exports, {
33
+ generatePrivateKeyFile: () => generatePrivateKeyFile,
34
+ generatePrivateKeyFileAlternate: () => generatePrivateKeyFileAlternate,
35
+ getCertificateStore: () => getCertificateStore,
36
+ makePrivateKeyThumbPrint: () => makePrivateKeyThumbPrint,
37
+ readCertificate: () => readCertificate,
38
+ readCertificatePEM: () => readCertificatePEM,
39
+ readCertificateRevocationList: () => readCertificateRevocationList,
40
+ readCertificateSigningRequest: () => readCertificateSigningRequest,
41
+ readPrivateKey: () => readPrivateKey,
42
+ readPrivateKeyPEM: () => readPrivateKeyPEM,
43
+ readPrivateRsaKey: () => readPrivateRsaKey,
44
+ readPublicKey: () => readPublicKey,
45
+ readPublicKeyPEM: () => readPublicKeyPEM,
46
+ readPublicRsaKey: () => readPublicRsaKey,
47
+ setCertificateStore: () => setCertificateStore
48
+ });
49
+ module.exports = __toCommonJS(source_nodejs_exports);
50
+
51
+ // source_nodejs/read.ts
52
+ var import_assert4 = __toESM(require("assert"));
53
+ var import_fs = __toESM(require("fs"));
54
+ var import_path = __toESM(require("path"));
55
+ var import_crypto = require("crypto");
56
+
57
+ // source/crypto_utils.ts
58
+ var import_constants = __toESM(require("constants"));
59
+ var import_assert3 = __toESM(require("assert"));
60
+ var import_hexy = __toESM(require("hexy"));
61
+
62
+ // source/buffer_utils.ts
63
+ var createFastUninitializedBuffer = Buffer.allocUnsafe ? Buffer.allocUnsafe : (size) => {
64
+ return new Buffer(size);
65
+ };
66
+
67
+ // source/crypto_explore_certificate.ts
68
+ var import_assert2 = __toESM(require("assert"));
69
+
70
+ // source/asn1.ts
71
+ var import_assert = __toESM(require("assert"));
72
+ function readTag(buf, pos) {
73
+ (0, import_assert.default)(buf instanceof Buffer);
74
+ (0, import_assert.default)(Number.isFinite(pos) && pos >= 0);
75
+ if (buf.length <= pos) {
76
+ throw new Error("Invalid position : buf.length=" + buf.length + " pos =" + pos);
77
+ }
78
+ const tag = buf.readUInt8(pos);
79
+ pos += 1;
80
+ let length = buf.readUInt8(pos);
81
+ pos += 1;
82
+ if (length > 127) {
83
+ const nbBytes = length & 127;
84
+ length = 0;
85
+ for (let i = 0; i < nbBytes; i++) {
86
+ length = length * 256 + buf.readUInt8(pos);
87
+ pos += 1;
88
+ }
89
+ }
90
+ return { tag, position: pos, length };
91
+ }
92
+
93
+ // source/crypto_explore_certificate.ts
94
+ function split_der(certificateChain) {
95
+ const certificate_chain = [];
96
+ do {
97
+ const block_info = readTag(certificateChain, 0);
98
+ const length = block_info.position + block_info.length;
99
+ const der_certificate = certificateChain.subarray(0, length);
100
+ certificate_chain.push(der_certificate);
101
+ certificateChain = certificateChain.subarray(length);
102
+ } while (certificateChain.length > 0);
103
+ return certificate_chain;
104
+ }
105
+ function combine_der(certificates) {
106
+ for (const cert of certificates) {
107
+ const b = split_der(cert);
108
+ let sum = 0;
109
+ b.forEach((block) => {
110
+ const block_info = readTag(block, 0);
111
+ (0, import_assert2.default)(block_info.position + block_info.length === block.length);
112
+ sum += block.length;
113
+ });
114
+ (0, import_assert2.default)(sum === cert.length);
115
+ }
116
+ return Buffer.concat(certificates);
117
+ }
118
+
119
+ // source/crypto_utils.ts
120
+ var import_jsrsasign = __toESM(require("jsrsasign"));
121
+ var { hexy } = import_hexy.default;
122
+ var PEM_REGEX = /^(-----BEGIN (.*)-----\r?\n([/+=a-zA-Z0-9\r\n]*)\r?\n-----END \2-----\r?\n?)/gm;
123
+ var PEM_TYPE_REGEX = /^(-----BEGIN (.*)-----)/m;
124
+ function identifyPemType(rawKey) {
125
+ if (rawKey instanceof Buffer) {
126
+ rawKey = rawKey.toString("utf8");
127
+ }
128
+ const match = PEM_TYPE_REGEX.exec(rawKey);
129
+ return !match ? void 0 : match[2];
130
+ }
131
+ function removeTrailingLF(str) {
132
+ const tmp = str.replace(/(\r|\n)+$/m, "").replace(/\r\n/gm, "\n");
133
+ return tmp;
134
+ }
135
+ function toPem(raw_key, pem) {
136
+ (0, import_assert3.default)(raw_key, "expecting a key");
137
+ (0, import_assert3.default)(typeof pem === "string");
138
+ let pemType = identifyPemType(raw_key);
139
+ if (pemType) {
140
+ return raw_key instanceof Buffer ? removeTrailingLF(raw_key.toString("utf8")) : removeTrailingLF(raw_key);
141
+ } else {
142
+ pemType = pem;
143
+ (0, import_assert3.default)(["CERTIFICATE REQUEST", "CERTIFICATE", "RSA PRIVATE KEY", "PUBLIC KEY", "X509 CRL"].indexOf(pemType) >= 0);
144
+ let b = raw_key.toString("base64");
145
+ let str = "-----BEGIN " + pemType + "-----\n";
146
+ while (b.length) {
147
+ str += b.substring(0, 64) + "\n";
148
+ b = b.substring(64);
149
+ }
150
+ str += "-----END " + pemType + "-----";
151
+ return str;
152
+ }
153
+ }
154
+ function convertPEMtoDER(raw_key) {
155
+ let match;
156
+ let pemType;
157
+ let base64str;
158
+ const parts = [];
159
+ PEM_REGEX.lastIndex = 0;
160
+ while ((match = PEM_REGEX.exec(raw_key)) !== null) {
161
+ pemType = match[2];
162
+ base64str = match[3];
163
+ base64str = base64str.replace(/\r?\n/g, "");
164
+ parts.push(Buffer.from(base64str, "base64"));
165
+ }
166
+ return combine_der(parts);
167
+ }
168
+ var RSA_PKCS1_OAEP_PADDING = import_constants.default.RSA_PKCS1_OAEP_PADDING;
169
+ var RSA_PKCS1_PADDING = import_constants.default.RSA_PKCS1_PADDING;
170
+ (0, import_assert3.default)(4 /* RSA_PKCS1_OAEP_PADDING */ === import_constants.default.RSA_PKCS1_OAEP_PADDING);
171
+ (0, import_assert3.default)(1 /* RSA_PKCS1_PADDING */ === import_constants.default.RSA_PKCS1_PADDING);
172
+
173
+ // source_nodejs/read.ts
174
+ var import_sshpk = __toESM(require("sshpk"));
175
+ function _readPemFile(filename) {
176
+ (0, import_assert4.default)(typeof filename === "string");
177
+ return removeTrailingLF(import_fs.default.readFileSync(filename, "utf-8"));
178
+ }
179
+ function _readPemOrDerFileAsDER(filename) {
180
+ if (filename.match(/.*\.der/)) {
181
+ return import_fs.default.readFileSync(filename);
182
+ }
183
+ const raw_key = _readPemFile(filename);
184
+ return convertPEMtoDER(raw_key);
185
+ }
186
+ function readCertificate(filename) {
187
+ return _readPemOrDerFileAsDER(filename);
188
+ }
189
+ function readPublicKey(filename) {
190
+ if (filename.match(/.*\.der/)) {
191
+ const der = import_fs.default.readFileSync(filename);
192
+ return (0, import_crypto.createPublicKey)(der);
193
+ } else {
194
+ const raw_key = _readPemFile(filename);
195
+ return (0, import_crypto.createPublicKey)(raw_key);
196
+ }
197
+ }
198
+ function myCreatePrivateKey(rawKey) {
199
+ if (!import_crypto.createPrivateKey || process.env.NO_CREATE_PRIVATEKEY) {
200
+ if (rawKey instanceof Buffer) {
201
+ const pemKey = toPem(rawKey, "PRIVATE KEY");
202
+ (0, import_assert4.default)(["RSA PRIVATE KEY", "PRIVATE KEY"].indexOf(identifyPemType(pemKey)) >= 0);
203
+ return { hidden: pemKey };
204
+ }
205
+ return { hidden: ensureTrailingLF(rawKey) };
206
+ }
207
+ const backup = process.env.OPENSSL_CONF;
208
+ process.env.OPENSSL_CONF = "/dev/null";
209
+ const retValue = (0, import_crypto.createPrivateKey)(rawKey);
210
+ process.env.OPENSSL_CONF = backup;
211
+ return { hidden: retValue };
212
+ }
213
+ function makePrivateKeyThumbPrint(privateKey) {
214
+ return Buffer.alloc(0);
215
+ }
216
+ function ensureTrailingLF(str) {
217
+ return str.match(/\n$/) ? str : str + "\n";
218
+ }
219
+ function readPrivateKey(filename) {
220
+ if (filename.match(/.*\.der/)) {
221
+ const der = import_fs.default.readFileSync(filename);
222
+ return myCreatePrivateKey(der);
223
+ } else {
224
+ const raw_key = _readPemFile(filename);
225
+ return myCreatePrivateKey(raw_key);
226
+ }
227
+ }
228
+ function readCertificatePEM(filename) {
229
+ return _readPemFile(filename);
230
+ }
231
+ function readPublicKeyPEM(filename) {
232
+ return _readPemFile(filename);
233
+ }
234
+ function readPrivateKeyPEM(filename) {
235
+ return _readPemFile(filename);
236
+ }
237
+ var _g_certificate_store = "";
238
+ function setCertificateStore(store) {
239
+ const old_store = _g_certificate_store;
240
+ _g_certificate_store = store;
241
+ return old_store;
242
+ }
243
+ function getCertificateStore() {
244
+ if (!_g_certificate_store) {
245
+ _g_certificate_store = import_path.default.join(__dirname, "../../certificates/");
246
+ }
247
+ return _g_certificate_store;
248
+ }
249
+ function readPrivateRsaKey(filename) {
250
+ if (!import_crypto.createPrivateKey) {
251
+ throw new Error("createPrivateKey is not supported in this environment");
252
+ }
253
+ if (filename.substring(0, 1) !== "." && !import_fs.default.existsSync(filename)) {
254
+ filename = import_path.default.join(getCertificateStore(), filename);
255
+ }
256
+ const content = import_fs.default.readFileSync(filename, "utf8");
257
+ const sshKey = import_sshpk.default.parsePrivateKey(content, "auto");
258
+ const key = sshKey.toString("pkcs1");
259
+ const hidden = (0, import_crypto.createPrivateKey)({ format: "pem", type: "pkcs1", key });
260
+ return { hidden };
261
+ }
262
+ function readPublicRsaKey(filename) {
263
+ if (filename.substring(0, 1) !== "." && !import_fs.default.existsSync(filename)) {
264
+ filename = import_path.default.join(getCertificateStore(), filename);
265
+ }
266
+ const content = import_fs.default.readFileSync(filename, "utf-8");
267
+ const sshKey = import_sshpk.default.parseKey(content, "ssh");
268
+ const key = sshKey.toString("pkcs1");
269
+ return (0, import_crypto.createPublicKey)({ format: "pem", type: "pkcs1", key });
270
+ }
271
+
272
+ // source_nodejs/read_certificate_revocation_list.ts
273
+ var import_fs2 = __toESM(require("fs"));
274
+ var import_util = require("util");
275
+ async function readCertificateRevocationList(filename) {
276
+ const crl = await (0, import_util.promisify)(import_fs2.default.readFile)(filename);
277
+ if (crl[0] === 48 && crl[1] === 130) {
278
+ return crl;
279
+ }
280
+ const raw_crl = crl.toString();
281
+ return convertPEMtoDER(raw_crl);
282
+ }
283
+
284
+ // source_nodejs/read_certificate_signing_request.ts
285
+ var import_fs3 = __toESM(require("fs"));
286
+ var import_util2 = require("util");
287
+ async function readCertificateSigningRequest(filename) {
288
+ const csr = await (0, import_util2.promisify)(import_fs3.default.readFile)(filename);
289
+ if (csr[0] === 48 && csr[1] === 130) {
290
+ return csr;
291
+ }
292
+ const raw_crl = csr.toString();
293
+ return convertPEMtoDER(raw_crl);
294
+ }
295
+
296
+ // source_nodejs/generate_private_key_filename.ts
297
+ var import_fs4 = __toESM(require("fs"));
298
+
299
+ // source/common.ts
300
+ var import_crypto2 = __toESM(require("crypto"));
301
+ var { createPrivateKey: createPrivateKeyFromNodeJSCrypto } = import_crypto2.default;
302
+
303
+ // source/derived_keys.ts
304
+ var import_assert6 = __toESM(require("assert"));
305
+
306
+ // source/explore_certificate.ts
307
+ var import_assert5 = __toESM(require("assert"));
308
+
309
+ // source/crypto_utils2.ts
310
+ var import_assert7 = __toESM(require("assert"));
311
+ var import_jsrsasign2 = __toESM(require("jsrsasign"));
312
+
313
+ // source/explore_private_key.ts
314
+ var doDebug = !!process.env.DEBUG;
315
+
316
+ // source/x509/_crypto.ts
317
+ var x509 = __toESM(require("@peculiar/x509"));
318
+ var import_webcrypto = require("@peculiar/webcrypto");
319
+ var import_crypto3 = __toESM(require("crypto"));
320
+ var x5092 = __toESM(require("@peculiar/x509"));
321
+ var _crypto;
322
+ var ignoreCrypto = process.env.IGNORE_SUBTLE_FROM_CRYPTO;
323
+ if (typeof window === "undefined") {
324
+ _crypto = import_crypto3.default;
325
+ if (!_crypto?.subtle || ignoreCrypto) {
326
+ _crypto = new import_webcrypto.Crypto();
327
+ console.warn("using @peculiar/webcrypto");
328
+ } else {
329
+ console.warn("using nodejs crypto (native)");
330
+ }
331
+ x509.cryptoProvider.set(_crypto);
332
+ } else {
333
+ console.warn("using browser crypto (native)");
334
+ _crypto = crypto;
335
+ x509.cryptoProvider.set(crypto);
336
+ }
337
+ function getCrypto() {
338
+ return _crypto || crypto || require("crypto");
339
+ }
340
+
341
+ // source/x509/create_key_pair.ts
342
+ async function generateKeyPair(modulusLength = 2048) {
343
+ const crypto3 = getCrypto();
344
+ const alg = {
345
+ name: "RSASSA-PKCS1-v1_5",
346
+ hash: { name: "SHA-256" },
347
+ publicExponent: new Uint8Array([1, 0, 1]),
348
+ modulusLength
349
+ };
350
+ const keys = await crypto3.subtle.generateKey(alg, true, ["sign", "verify"]);
351
+ return keys;
352
+ }
353
+ async function privateKeyToPEM(privateKey) {
354
+ const crypto3 = getCrypto();
355
+ const privDer = await crypto3.subtle.exportKey("pkcs8", privateKey);
356
+ const privPem = x5092.PemConverter.encode(privDer, "PRIVATE KEY");
357
+ return { privPem, privDer };
358
+ }
359
+
360
+ // source/x509/_get_attributes.ts
361
+ var keyUsageApplication = x5092.KeyUsageFlags.keyEncipherment | x5092.KeyUsageFlags.nonRepudiation | x5092.KeyUsageFlags.dataEncipherment | x5092.KeyUsageFlags.keyCertSign | x5092.KeyUsageFlags.digitalSignature;
362
+ var keyUsageCA = x5092.KeyUsageFlags.keyCertSign | x5092.KeyUsageFlags.cRLSign;
363
+
364
+ // ../../node_modules/asn1js/build/index.es.js
365
+ var index_es_exports = {};
366
+ __export(index_es_exports, {
367
+ Any: () => Any,
368
+ BaseBlock: () => BaseBlock,
369
+ BaseStringBlock: () => BaseStringBlock,
370
+ BitString: () => BitString,
371
+ BmpString: () => BmpString,
372
+ Boolean: () => Boolean,
373
+ CharacterString: () => CharacterString,
374
+ Choice: () => Choice,
375
+ Constructed: () => Constructed,
376
+ DATE: () => DATE,
377
+ DateTime: () => DateTime,
378
+ Duration: () => Duration,
379
+ EndOfContent: () => EndOfContent,
380
+ Enumerated: () => Enumerated,
381
+ GeneralString: () => GeneralString,
382
+ GeneralizedTime: () => GeneralizedTime,
383
+ GraphicString: () => GraphicString,
384
+ HexBlock: () => HexBlock,
385
+ IA5String: () => IA5String,
386
+ Integer: () => Integer,
387
+ Null: () => Null,
388
+ NumericString: () => NumericString,
389
+ ObjectIdentifier: () => ObjectIdentifier,
390
+ OctetString: () => OctetString,
391
+ Primitive: () => Primitive,
392
+ PrintableString: () => PrintableString,
393
+ RawData: () => RawData,
394
+ RelativeObjectIdentifier: () => RelativeObjectIdentifier,
395
+ Repeated: () => Repeated,
396
+ Sequence: () => Sequence,
397
+ Set: () => Set,
398
+ TIME: () => TIME,
399
+ TeletexString: () => TeletexString,
400
+ TimeOfDay: () => TimeOfDay,
401
+ UTCTime: () => UTCTime,
402
+ UniversalString: () => UniversalString,
403
+ Utf8String: () => Utf8String,
404
+ ValueBlock: () => ValueBlock,
405
+ VideotexString: () => VideotexString,
406
+ ViewWriter: () => ViewWriter,
407
+ VisibleString: () => VisibleString,
408
+ compareSchema: () => compareSchema,
409
+ fromBER: () => fromBER,
410
+ verifySchema: () => verifySchema
411
+ });
412
+
413
+ // ../../node_modules/pvtsutils/build/index.es.js
414
+ var ARRAY_BUFFER_NAME = "[object ArrayBuffer]";
415
+ var BufferSourceConverter = class _BufferSourceConverter {
416
+ static isArrayBuffer(data) {
417
+ return Object.prototype.toString.call(data) === ARRAY_BUFFER_NAME;
418
+ }
419
+ static toArrayBuffer(data) {
420
+ if (this.isArrayBuffer(data)) {
421
+ return data;
422
+ }
423
+ if (data.byteLength === data.buffer.byteLength) {
424
+ return data.buffer;
425
+ }
426
+ if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
427
+ return data.buffer;
428
+ }
429
+ return this.toUint8Array(data.buffer).slice(data.byteOffset, data.byteOffset + data.byteLength).buffer;
430
+ }
431
+ static toUint8Array(data) {
432
+ return this.toView(data, Uint8Array);
433
+ }
434
+ static toView(data, type) {
435
+ if (data.constructor === type) {
436
+ return data;
437
+ }
438
+ if (this.isArrayBuffer(data)) {
439
+ return new type(data);
440
+ }
441
+ if (this.isArrayBufferView(data)) {
442
+ return new type(data.buffer, data.byteOffset, data.byteLength);
443
+ }
444
+ throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
445
+ }
446
+ static isBufferSource(data) {
447
+ return this.isArrayBufferView(data) || this.isArrayBuffer(data);
448
+ }
449
+ static isArrayBufferView(data) {
450
+ return ArrayBuffer.isView(data) || data && this.isArrayBuffer(data.buffer);
451
+ }
452
+ static isEqual(a, b) {
453
+ const aView = _BufferSourceConverter.toUint8Array(a);
454
+ const bView = _BufferSourceConverter.toUint8Array(b);
455
+ if (aView.length !== bView.byteLength) {
456
+ return false;
457
+ }
458
+ for (let i = 0; i < aView.length; i++) {
459
+ if (aView[i] !== bView[i]) {
460
+ return false;
461
+ }
462
+ }
463
+ return true;
464
+ }
465
+ static concat(...args) {
466
+ let buffers;
467
+ if (Array.isArray(args[0]) && !(args[1] instanceof Function)) {
468
+ buffers = args[0];
469
+ } else if (Array.isArray(args[0]) && args[1] instanceof Function) {
470
+ buffers = args[0];
471
+ } else {
472
+ if (args[args.length - 1] instanceof Function) {
473
+ buffers = args.slice(0, args.length - 1);
474
+ } else {
475
+ buffers = args;
476
+ }
477
+ }
478
+ let size = 0;
479
+ for (const buffer of buffers) {
480
+ size += buffer.byteLength;
481
+ }
482
+ const res = new Uint8Array(size);
483
+ let offset = 0;
484
+ for (const buffer of buffers) {
485
+ const view = this.toUint8Array(buffer);
486
+ res.set(view, offset);
487
+ offset += view.length;
488
+ }
489
+ if (args[args.length - 1] instanceof Function) {
490
+ return this.toView(res, args[args.length - 1]);
491
+ }
492
+ return res.buffer;
493
+ }
494
+ };
495
+ var STRING_TYPE = "string";
496
+ var HEX_REGEX = /^[0-9a-f]+$/i;
497
+ var BASE64_REGEX = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
498
+ var BASE64URL_REGEX = /^[a-zA-Z0-9-_]+$/;
499
+ var Utf8Converter = class {
500
+ static fromString(text) {
501
+ const s = unescape(encodeURIComponent(text));
502
+ const uintArray = new Uint8Array(s.length);
503
+ for (let i = 0; i < s.length; i++) {
504
+ uintArray[i] = s.charCodeAt(i);
505
+ }
506
+ return uintArray.buffer;
507
+ }
508
+ static toString(buffer) {
509
+ const buf = BufferSourceConverter.toUint8Array(buffer);
510
+ let encodedString = "";
511
+ for (let i = 0; i < buf.length; i++) {
512
+ encodedString += String.fromCharCode(buf[i]);
513
+ }
514
+ const decodedString = decodeURIComponent(escape(encodedString));
515
+ return decodedString;
516
+ }
517
+ };
518
+ var Utf16Converter = class {
519
+ static toString(buffer, littleEndian = false) {
520
+ const arrayBuffer = BufferSourceConverter.toArrayBuffer(buffer);
521
+ const dataView = new DataView(arrayBuffer);
522
+ let res = "";
523
+ for (let i = 0; i < arrayBuffer.byteLength; i += 2) {
524
+ const code = dataView.getUint16(i, littleEndian);
525
+ res += String.fromCharCode(code);
526
+ }
527
+ return res;
528
+ }
529
+ static fromString(text, littleEndian = false) {
530
+ const res = new ArrayBuffer(text.length * 2);
531
+ const dataView = new DataView(res);
532
+ for (let i = 0; i < text.length; i++) {
533
+ dataView.setUint16(i * 2, text.charCodeAt(i), littleEndian);
534
+ }
535
+ return res;
536
+ }
537
+ };
538
+ var Convert = class _Convert {
539
+ static isHex(data) {
540
+ return typeof data === STRING_TYPE && HEX_REGEX.test(data);
541
+ }
542
+ static isBase64(data) {
543
+ return typeof data === STRING_TYPE && BASE64_REGEX.test(data);
544
+ }
545
+ static isBase64Url(data) {
546
+ return typeof data === STRING_TYPE && BASE64URL_REGEX.test(data);
547
+ }
548
+ static ToString(buffer, enc = "utf8") {
549
+ const buf = BufferSourceConverter.toUint8Array(buffer);
550
+ switch (enc.toLowerCase()) {
551
+ case "utf8":
552
+ return this.ToUtf8String(buf);
553
+ case "binary":
554
+ return this.ToBinary(buf);
555
+ case "hex":
556
+ return this.ToHex(buf);
557
+ case "base64":
558
+ return this.ToBase64(buf);
559
+ case "base64url":
560
+ return this.ToBase64Url(buf);
561
+ case "utf16le":
562
+ return Utf16Converter.toString(buf, true);
563
+ case "utf16":
564
+ case "utf16be":
565
+ return Utf16Converter.toString(buf);
566
+ default:
567
+ throw new Error(`Unknown type of encoding '${enc}'`);
568
+ }
569
+ }
570
+ static FromString(str, enc = "utf8") {
571
+ if (!str) {
572
+ return new ArrayBuffer(0);
573
+ }
574
+ switch (enc.toLowerCase()) {
575
+ case "utf8":
576
+ return this.FromUtf8String(str);
577
+ case "binary":
578
+ return this.FromBinary(str);
579
+ case "hex":
580
+ return this.FromHex(str);
581
+ case "base64":
582
+ return this.FromBase64(str);
583
+ case "base64url":
584
+ return this.FromBase64Url(str);
585
+ case "utf16le":
586
+ return Utf16Converter.fromString(str, true);
587
+ case "utf16":
588
+ case "utf16be":
589
+ return Utf16Converter.fromString(str);
590
+ default:
591
+ throw new Error(`Unknown type of encoding '${enc}'`);
592
+ }
593
+ }
594
+ static ToBase64(buffer) {
595
+ const buf = BufferSourceConverter.toUint8Array(buffer);
596
+ if (typeof btoa !== "undefined") {
597
+ const binary = this.ToString(buf, "binary");
598
+ return btoa(binary);
599
+ } else {
600
+ return Buffer.from(buf).toString("base64");
601
+ }
602
+ }
603
+ static FromBase64(base64) {
604
+ const formatted = this.formatString(base64);
605
+ if (!formatted) {
606
+ return new ArrayBuffer(0);
607
+ }
608
+ if (!_Convert.isBase64(formatted)) {
609
+ throw new TypeError("Argument 'base64Text' is not Base64 encoded");
610
+ }
611
+ if (typeof atob !== "undefined") {
612
+ return this.FromBinary(atob(formatted));
613
+ } else {
614
+ return new Uint8Array(Buffer.from(formatted, "base64")).buffer;
615
+ }
616
+ }
617
+ static FromBase64Url(base64url) {
618
+ const formatted = this.formatString(base64url);
619
+ if (!formatted) {
620
+ return new ArrayBuffer(0);
621
+ }
622
+ if (!_Convert.isBase64Url(formatted)) {
623
+ throw new TypeError("Argument 'base64url' is not Base64Url encoded");
624
+ }
625
+ return this.FromBase64(this.Base64Padding(formatted.replace(/\-/g, "+").replace(/\_/g, "/")));
626
+ }
627
+ static ToBase64Url(data) {
628
+ return this.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
629
+ }
630
+ static FromUtf8String(text, encoding = _Convert.DEFAULT_UTF8_ENCODING) {
631
+ switch (encoding) {
632
+ case "ascii":
633
+ return this.FromBinary(text);
634
+ case "utf8":
635
+ return Utf8Converter.fromString(text);
636
+ case "utf16":
637
+ case "utf16be":
638
+ return Utf16Converter.fromString(text);
639
+ case "utf16le":
640
+ case "usc2":
641
+ return Utf16Converter.fromString(text, true);
642
+ default:
643
+ throw new Error(`Unknown type of encoding '${encoding}'`);
644
+ }
645
+ }
646
+ static ToUtf8String(buffer, encoding = _Convert.DEFAULT_UTF8_ENCODING) {
647
+ switch (encoding) {
648
+ case "ascii":
649
+ return this.ToBinary(buffer);
650
+ case "utf8":
651
+ return Utf8Converter.toString(buffer);
652
+ case "utf16":
653
+ case "utf16be":
654
+ return Utf16Converter.toString(buffer);
655
+ case "utf16le":
656
+ case "usc2":
657
+ return Utf16Converter.toString(buffer, true);
658
+ default:
659
+ throw new Error(`Unknown type of encoding '${encoding}'`);
660
+ }
661
+ }
662
+ static FromBinary(text) {
663
+ const stringLength = text.length;
664
+ const resultView = new Uint8Array(stringLength);
665
+ for (let i = 0; i < stringLength; i++) {
666
+ resultView[i] = text.charCodeAt(i);
667
+ }
668
+ return resultView.buffer;
669
+ }
670
+ static ToBinary(buffer) {
671
+ const buf = BufferSourceConverter.toUint8Array(buffer);
672
+ let res = "";
673
+ for (let i = 0; i < buf.length; i++) {
674
+ res += String.fromCharCode(buf[i]);
675
+ }
676
+ return res;
677
+ }
678
+ static ToHex(buffer) {
679
+ const buf = BufferSourceConverter.toUint8Array(buffer);
680
+ let result = "";
681
+ const len = buf.length;
682
+ for (let i = 0; i < len; i++) {
683
+ const byte = buf[i];
684
+ if (byte < 16) {
685
+ result += "0";
686
+ }
687
+ result += byte.toString(16);
688
+ }
689
+ return result;
690
+ }
691
+ static FromHex(hexString) {
692
+ let formatted = this.formatString(hexString);
693
+ if (!formatted) {
694
+ return new ArrayBuffer(0);
695
+ }
696
+ if (!_Convert.isHex(formatted)) {
697
+ throw new TypeError("Argument 'hexString' is not HEX encoded");
698
+ }
699
+ if (formatted.length % 2) {
700
+ formatted = `0${formatted}`;
701
+ }
702
+ const res = new Uint8Array(formatted.length / 2);
703
+ for (let i = 0; i < formatted.length; i = i + 2) {
704
+ const c = formatted.slice(i, i + 2);
705
+ res[i / 2] = parseInt(c, 16);
706
+ }
707
+ return res.buffer;
708
+ }
709
+ static ToUtf16String(buffer, littleEndian = false) {
710
+ return Utf16Converter.toString(buffer, littleEndian);
711
+ }
712
+ static FromUtf16String(text, littleEndian = false) {
713
+ return Utf16Converter.fromString(text, littleEndian);
714
+ }
715
+ static Base64Padding(base64) {
716
+ const padCount = 4 - base64.length % 4;
717
+ if (padCount < 4) {
718
+ for (let i = 0; i < padCount; i++) {
719
+ base64 += "=";
720
+ }
721
+ }
722
+ return base64;
723
+ }
724
+ static formatString(data) {
725
+ return (data === null || data === void 0 ? void 0 : data.replace(/[\n\r\t ]/g, "")) || "";
726
+ }
727
+ };
728
+ Convert.DEFAULT_UTF8_ENCODING = "utf8";
729
+
730
+ // ../../node_modules/pvutils/build/utils.es.js
731
+ function utilFromBase(inputBuffer, inputBase) {
732
+ let result = 0;
733
+ if (inputBuffer.length === 1) {
734
+ return inputBuffer[0];
735
+ }
736
+ for (let i = inputBuffer.length - 1; i >= 0; i--) {
737
+ result += inputBuffer[inputBuffer.length - 1 - i] * Math.pow(2, inputBase * i);
738
+ }
739
+ return result;
740
+ }
741
+ function utilToBase(value, base, reserved = -1) {
742
+ const internalReserved = reserved;
743
+ let internalValue = value;
744
+ let result = 0;
745
+ let biggest = Math.pow(2, base);
746
+ for (let i = 1; i < 8; i++) {
747
+ if (value < biggest) {
748
+ let retBuf;
749
+ if (internalReserved < 0) {
750
+ retBuf = new ArrayBuffer(i);
751
+ result = i;
752
+ } else {
753
+ if (internalReserved < i) {
754
+ return new ArrayBuffer(0);
755
+ }
756
+ retBuf = new ArrayBuffer(internalReserved);
757
+ result = internalReserved;
758
+ }
759
+ const retView = new Uint8Array(retBuf);
760
+ for (let j = i - 1; j >= 0; j--) {
761
+ const basis = Math.pow(2, j * base);
762
+ retView[result - j - 1] = Math.floor(internalValue / basis);
763
+ internalValue -= retView[result - j - 1] * basis;
764
+ }
765
+ return retBuf;
766
+ }
767
+ biggest *= Math.pow(2, base);
768
+ }
769
+ return new ArrayBuffer(0);
770
+ }
771
+ function utilConcatView(...views) {
772
+ let outputLength = 0;
773
+ let prevLength = 0;
774
+ for (const view of views) {
775
+ outputLength += view.length;
776
+ }
777
+ const retBuf = new ArrayBuffer(outputLength);
778
+ const retView = new Uint8Array(retBuf);
779
+ for (const view of views) {
780
+ retView.set(view, prevLength);
781
+ prevLength += view.length;
782
+ }
783
+ return retView;
784
+ }
785
+ function utilDecodeTC() {
786
+ const buf = new Uint8Array(this.valueHex);
787
+ if (this.valueHex.byteLength >= 2) {
788
+ const condition1 = buf[0] === 255 && buf[1] & 128;
789
+ const condition2 = buf[0] === 0 && (buf[1] & 128) === 0;
790
+ if (condition1 || condition2) {
791
+ this.warnings.push("Needlessly long format");
792
+ }
793
+ }
794
+ const bigIntBuffer = new ArrayBuffer(this.valueHex.byteLength);
795
+ const bigIntView = new Uint8Array(bigIntBuffer);
796
+ for (let i = 0; i < this.valueHex.byteLength; i++) {
797
+ bigIntView[i] = 0;
798
+ }
799
+ bigIntView[0] = buf[0] & 128;
800
+ const bigInt = utilFromBase(bigIntView, 8);
801
+ const smallIntBuffer = new ArrayBuffer(this.valueHex.byteLength);
802
+ const smallIntView = new Uint8Array(smallIntBuffer);
803
+ for (let j = 0; j < this.valueHex.byteLength; j++) {
804
+ smallIntView[j] = buf[j];
805
+ }
806
+ smallIntView[0] &= 127;
807
+ const smallInt = utilFromBase(smallIntView, 8);
808
+ return smallInt - bigInt;
809
+ }
810
+ function utilEncodeTC(value) {
811
+ const modValue = value < 0 ? value * -1 : value;
812
+ let bigInt = 128;
813
+ for (let i = 1; i < 8; i++) {
814
+ if (modValue <= bigInt) {
815
+ if (value < 0) {
816
+ const smallInt = bigInt - modValue;
817
+ const retBuf2 = utilToBase(smallInt, 8, i);
818
+ const retView2 = new Uint8Array(retBuf2);
819
+ retView2[0] |= 128;
820
+ return retBuf2;
821
+ }
822
+ let retBuf = utilToBase(modValue, 8, i);
823
+ let retView = new Uint8Array(retBuf);
824
+ if (retView[0] & 128) {
825
+ const tempBuf = retBuf.slice(0);
826
+ const tempView = new Uint8Array(tempBuf);
827
+ retBuf = new ArrayBuffer(retBuf.byteLength + 1);
828
+ retView = new Uint8Array(retBuf);
829
+ for (let k = 0; k < tempBuf.byteLength; k++) {
830
+ retView[k + 1] = tempView[k];
831
+ }
832
+ retView[0] = 0;
833
+ }
834
+ return retBuf;
835
+ }
836
+ bigInt *= Math.pow(2, 8);
837
+ }
838
+ return new ArrayBuffer(0);
839
+ }
840
+ function isEqualBuffer(inputBuffer1, inputBuffer2) {
841
+ if (inputBuffer1.byteLength !== inputBuffer2.byteLength) {
842
+ return false;
843
+ }
844
+ const view1 = new Uint8Array(inputBuffer1);
845
+ const view2 = new Uint8Array(inputBuffer2);
846
+ for (let i = 0; i < view1.length; i++) {
847
+ if (view1[i] !== view2[i]) {
848
+ return false;
849
+ }
850
+ }
851
+ return true;
852
+ }
853
+ function padNumber(inputNumber, fullLength) {
854
+ const str = inputNumber.toString(10);
855
+ if (fullLength < str.length) {
856
+ return "";
857
+ }
858
+ const dif = fullLength - str.length;
859
+ const padding = new Array(dif);
860
+ for (let i = 0; i < dif; i++) {
861
+ padding[i] = "0";
862
+ }
863
+ const paddingString = padding.join("");
864
+ return paddingString.concat(str);
865
+ }
866
+ var log2 = Math.log(2);
867
+
868
+ // ../../node_modules/asn1js/build/index.es.js
869
+ function assertBigInt() {
870
+ if (typeof BigInt === "undefined") {
871
+ throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.");
872
+ }
873
+ }
874
+ function concat(buffers) {
875
+ let outputLength = 0;
876
+ let prevLength = 0;
877
+ for (let i = 0; i < buffers.length; i++) {
878
+ const buffer = buffers[i];
879
+ outputLength += buffer.byteLength;
880
+ }
881
+ const retView = new Uint8Array(outputLength);
882
+ for (let i = 0; i < buffers.length; i++) {
883
+ const buffer = buffers[i];
884
+ retView.set(new Uint8Array(buffer), prevLength);
885
+ prevLength += buffer.byteLength;
886
+ }
887
+ return retView.buffer;
888
+ }
889
+ function checkBufferParams(baseBlock, inputBuffer, inputOffset, inputLength) {
890
+ if (!(inputBuffer instanceof Uint8Array)) {
891
+ baseBlock.error = "Wrong parameter: inputBuffer must be 'Uint8Array'";
892
+ return false;
893
+ }
894
+ if (!inputBuffer.byteLength) {
895
+ baseBlock.error = "Wrong parameter: inputBuffer has zero length";
896
+ return false;
897
+ }
898
+ if (inputOffset < 0) {
899
+ baseBlock.error = "Wrong parameter: inputOffset less than zero";
900
+ return false;
901
+ }
902
+ if (inputLength < 0) {
903
+ baseBlock.error = "Wrong parameter: inputLength less than zero";
904
+ return false;
905
+ }
906
+ if (inputBuffer.byteLength - inputOffset - inputLength < 0) {
907
+ baseBlock.error = "End of input reached before message was fully decoded (inconsistent offset and length values)";
908
+ return false;
909
+ }
910
+ return true;
911
+ }
912
+ var ViewWriter = class {
913
+ constructor() {
914
+ this.items = [];
915
+ }
916
+ write(buf) {
917
+ this.items.push(buf);
918
+ }
919
+ final() {
920
+ return concat(this.items);
921
+ }
922
+ };
923
+ var powers2 = [new Uint8Array([1])];
924
+ var digitsString = "0123456789";
925
+ var NAME = "name";
926
+ var VALUE_HEX_VIEW = "valueHexView";
927
+ var IS_HEX_ONLY = "isHexOnly";
928
+ var ID_BLOCK = "idBlock";
929
+ var TAG_CLASS = "tagClass";
930
+ var TAG_NUMBER = "tagNumber";
931
+ var IS_CONSTRUCTED = "isConstructed";
932
+ var FROM_BER = "fromBER";
933
+ var TO_BER = "toBER";
934
+ var LOCAL = "local";
935
+ var EMPTY_STRING = "";
936
+ var EMPTY_BUFFER = new ArrayBuffer(0);
937
+ var EMPTY_VIEW = new Uint8Array(0);
938
+ var END_OF_CONTENT_NAME = "EndOfContent";
939
+ var OCTET_STRING_NAME = "OCTET STRING";
940
+ var BIT_STRING_NAME = "BIT STRING";
941
+ function HexBlock(BaseClass) {
942
+ var _a2;
943
+ return _a2 = class Some extends BaseClass {
944
+ constructor(...args) {
945
+ var _a3;
946
+ super(...args);
947
+ const params = args[0] || {};
948
+ this.isHexOnly = (_a3 = params.isHexOnly) !== null && _a3 !== void 0 ? _a3 : false;
949
+ this.valueHexView = params.valueHex ? BufferSourceConverter.toUint8Array(params.valueHex) : EMPTY_VIEW;
950
+ }
951
+ get valueHex() {
952
+ return this.valueHexView.slice().buffer;
953
+ }
954
+ set valueHex(value) {
955
+ this.valueHexView = new Uint8Array(value);
956
+ }
957
+ fromBER(inputBuffer, inputOffset, inputLength) {
958
+ const view = inputBuffer instanceof ArrayBuffer ? new Uint8Array(inputBuffer) : inputBuffer;
959
+ if (!checkBufferParams(this, view, inputOffset, inputLength)) {
960
+ return -1;
961
+ }
962
+ const endLength = inputOffset + inputLength;
963
+ this.valueHexView = view.subarray(inputOffset, endLength);
964
+ if (!this.valueHexView.length) {
965
+ this.warnings.push("Zero buffer length");
966
+ return inputOffset;
967
+ }
968
+ this.blockLength = inputLength;
969
+ return endLength;
970
+ }
971
+ toBER(sizeOnly = false) {
972
+ if (!this.isHexOnly) {
973
+ this.error = "Flag 'isHexOnly' is not set, abort";
974
+ return EMPTY_BUFFER;
975
+ }
976
+ if (sizeOnly) {
977
+ return new ArrayBuffer(this.valueHexView.byteLength);
978
+ }
979
+ return this.valueHexView.byteLength === this.valueHexView.buffer.byteLength ? this.valueHexView.buffer : this.valueHexView.slice().buffer;
980
+ }
981
+ toJSON() {
982
+ return {
983
+ ...super.toJSON(),
984
+ isHexOnly: this.isHexOnly,
985
+ valueHex: Convert.ToHex(this.valueHexView)
986
+ };
987
+ }
988
+ }, _a2.NAME = "hexBlock", _a2;
989
+ }
990
+ var LocalBaseBlock = class {
991
+ constructor({ blockLength = 0, error = EMPTY_STRING, warnings = [], valueBeforeDecode = EMPTY_VIEW } = {}) {
992
+ this.blockLength = blockLength;
993
+ this.error = error;
994
+ this.warnings = warnings;
995
+ this.valueBeforeDecodeView = BufferSourceConverter.toUint8Array(valueBeforeDecode);
996
+ }
997
+ static blockName() {
998
+ return this.NAME;
999
+ }
1000
+ get valueBeforeDecode() {
1001
+ return this.valueBeforeDecodeView.slice().buffer;
1002
+ }
1003
+ set valueBeforeDecode(value) {
1004
+ this.valueBeforeDecodeView = new Uint8Array(value);
1005
+ }
1006
+ toJSON() {
1007
+ return {
1008
+ blockName: this.constructor.NAME,
1009
+ blockLength: this.blockLength,
1010
+ error: this.error,
1011
+ warnings: this.warnings,
1012
+ valueBeforeDecode: Convert.ToHex(this.valueBeforeDecodeView)
1013
+ };
1014
+ }
1015
+ };
1016
+ LocalBaseBlock.NAME = "baseBlock";
1017
+ var ValueBlock = class extends LocalBaseBlock {
1018
+ fromBER(inputBuffer, inputOffset, inputLength) {
1019
+ throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'");
1020
+ }
1021
+ toBER(sizeOnly, writer) {
1022
+ throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'");
1023
+ }
1024
+ };
1025
+ ValueBlock.NAME = "valueBlock";
1026
+ var LocalIdentificationBlock = class extends HexBlock(LocalBaseBlock) {
1027
+ constructor({ idBlock = {} } = {}) {
1028
+ var _a2, _b, _c, _d;
1029
+ super();
1030
+ if (idBlock) {
1031
+ this.isHexOnly = (_a2 = idBlock.isHexOnly) !== null && _a2 !== void 0 ? _a2 : false;
1032
+ this.valueHexView = idBlock.valueHex ? BufferSourceConverter.toUint8Array(idBlock.valueHex) : EMPTY_VIEW;
1033
+ this.tagClass = (_b = idBlock.tagClass) !== null && _b !== void 0 ? _b : -1;
1034
+ this.tagNumber = (_c = idBlock.tagNumber) !== null && _c !== void 0 ? _c : -1;
1035
+ this.isConstructed = (_d = idBlock.isConstructed) !== null && _d !== void 0 ? _d : false;
1036
+ } else {
1037
+ this.tagClass = -1;
1038
+ this.tagNumber = -1;
1039
+ this.isConstructed = false;
1040
+ }
1041
+ }
1042
+ toBER(sizeOnly = false) {
1043
+ let firstOctet = 0;
1044
+ switch (this.tagClass) {
1045
+ case 1:
1046
+ firstOctet |= 0;
1047
+ break;
1048
+ case 2:
1049
+ firstOctet |= 64;
1050
+ break;
1051
+ case 3:
1052
+ firstOctet |= 128;
1053
+ break;
1054
+ case 4:
1055
+ firstOctet |= 192;
1056
+ break;
1057
+ default:
1058
+ this.error = "Unknown tag class";
1059
+ return EMPTY_BUFFER;
1060
+ }
1061
+ if (this.isConstructed)
1062
+ firstOctet |= 32;
1063
+ if (this.tagNumber < 31 && !this.isHexOnly) {
1064
+ const retView2 = new Uint8Array(1);
1065
+ if (!sizeOnly) {
1066
+ let number = this.tagNumber;
1067
+ number &= 31;
1068
+ firstOctet |= number;
1069
+ retView2[0] = firstOctet;
1070
+ }
1071
+ return retView2.buffer;
1072
+ }
1073
+ if (!this.isHexOnly) {
1074
+ const encodedBuf = utilToBase(this.tagNumber, 7);
1075
+ const encodedView = new Uint8Array(encodedBuf);
1076
+ const size = encodedBuf.byteLength;
1077
+ const retView2 = new Uint8Array(size + 1);
1078
+ retView2[0] = firstOctet | 31;
1079
+ if (!sizeOnly) {
1080
+ for (let i = 0; i < size - 1; i++)
1081
+ retView2[i + 1] = encodedView[i] | 128;
1082
+ retView2[size] = encodedView[size - 1];
1083
+ }
1084
+ return retView2.buffer;
1085
+ }
1086
+ const retView = new Uint8Array(this.valueHexView.byteLength + 1);
1087
+ retView[0] = firstOctet | 31;
1088
+ if (!sizeOnly) {
1089
+ const curView = this.valueHexView;
1090
+ for (let i = 0; i < curView.length - 1; i++)
1091
+ retView[i + 1] = curView[i] | 128;
1092
+ retView[this.valueHexView.byteLength] = curView[curView.length - 1];
1093
+ }
1094
+ return retView.buffer;
1095
+ }
1096
+ fromBER(inputBuffer, inputOffset, inputLength) {
1097
+ const inputView = BufferSourceConverter.toUint8Array(inputBuffer);
1098
+ if (!checkBufferParams(this, inputView, inputOffset, inputLength)) {
1099
+ return -1;
1100
+ }
1101
+ const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength);
1102
+ if (intBuffer.length === 0) {
1103
+ this.error = "Zero buffer length";
1104
+ return -1;
1105
+ }
1106
+ const tagClassMask = intBuffer[0] & 192;
1107
+ switch (tagClassMask) {
1108
+ case 0:
1109
+ this.tagClass = 1;
1110
+ break;
1111
+ case 64:
1112
+ this.tagClass = 2;
1113
+ break;
1114
+ case 128:
1115
+ this.tagClass = 3;
1116
+ break;
1117
+ case 192:
1118
+ this.tagClass = 4;
1119
+ break;
1120
+ default:
1121
+ this.error = "Unknown tag class";
1122
+ return -1;
1123
+ }
1124
+ this.isConstructed = (intBuffer[0] & 32) === 32;
1125
+ this.isHexOnly = false;
1126
+ const tagNumberMask = intBuffer[0] & 31;
1127
+ if (tagNumberMask !== 31) {
1128
+ this.tagNumber = tagNumberMask;
1129
+ this.blockLength = 1;
1130
+ } else {
1131
+ let count = 1;
1132
+ let intTagNumberBuffer = this.valueHexView = new Uint8Array(255);
1133
+ let tagNumberBufferMaxLength = 255;
1134
+ while (intBuffer[count] & 128) {
1135
+ intTagNumberBuffer[count - 1] = intBuffer[count] & 127;
1136
+ count++;
1137
+ if (count >= intBuffer.length) {
1138
+ this.error = "End of input reached before message was fully decoded";
1139
+ return -1;
1140
+ }
1141
+ if (count === tagNumberBufferMaxLength) {
1142
+ tagNumberBufferMaxLength += 255;
1143
+ const tempBufferView2 = new Uint8Array(tagNumberBufferMaxLength);
1144
+ for (let i = 0; i < intTagNumberBuffer.length; i++)
1145
+ tempBufferView2[i] = intTagNumberBuffer[i];
1146
+ intTagNumberBuffer = this.valueHexView = new Uint8Array(tagNumberBufferMaxLength);
1147
+ }
1148
+ }
1149
+ this.blockLength = count + 1;
1150
+ intTagNumberBuffer[count - 1] = intBuffer[count] & 127;
1151
+ const tempBufferView = new Uint8Array(count);
1152
+ for (let i = 0; i < count; i++)
1153
+ tempBufferView[i] = intTagNumberBuffer[i];
1154
+ intTagNumberBuffer = this.valueHexView = new Uint8Array(count);
1155
+ intTagNumberBuffer.set(tempBufferView);
1156
+ if (this.blockLength <= 9)
1157
+ this.tagNumber = utilFromBase(intTagNumberBuffer, 7);
1158
+ else {
1159
+ this.isHexOnly = true;
1160
+ this.warnings.push("Tag too long, represented as hex-coded");
1161
+ }
1162
+ }
1163
+ if (this.tagClass === 1 && this.isConstructed) {
1164
+ switch (this.tagNumber) {
1165
+ case 1:
1166
+ case 2:
1167
+ case 5:
1168
+ case 6:
1169
+ case 9:
1170
+ case 13:
1171
+ case 14:
1172
+ case 23:
1173
+ case 24:
1174
+ case 31:
1175
+ case 32:
1176
+ case 33:
1177
+ case 34:
1178
+ this.error = "Constructed encoding used for primitive type";
1179
+ return -1;
1180
+ }
1181
+ }
1182
+ return inputOffset + this.blockLength;
1183
+ }
1184
+ toJSON() {
1185
+ return {
1186
+ ...super.toJSON(),
1187
+ tagClass: this.tagClass,
1188
+ tagNumber: this.tagNumber,
1189
+ isConstructed: this.isConstructed
1190
+ };
1191
+ }
1192
+ };
1193
+ LocalIdentificationBlock.NAME = "identificationBlock";
1194
+ var LocalLengthBlock = class extends LocalBaseBlock {
1195
+ constructor({ lenBlock = {} } = {}) {
1196
+ var _a2, _b, _c;
1197
+ super();
1198
+ this.isIndefiniteForm = (_a2 = lenBlock.isIndefiniteForm) !== null && _a2 !== void 0 ? _a2 : false;
1199
+ this.longFormUsed = (_b = lenBlock.longFormUsed) !== null && _b !== void 0 ? _b : false;
1200
+ this.length = (_c = lenBlock.length) !== null && _c !== void 0 ? _c : 0;
1201
+ }
1202
+ fromBER(inputBuffer, inputOffset, inputLength) {
1203
+ const view = BufferSourceConverter.toUint8Array(inputBuffer);
1204
+ if (!checkBufferParams(this, view, inputOffset, inputLength)) {
1205
+ return -1;
1206
+ }
1207
+ const intBuffer = view.subarray(inputOffset, inputOffset + inputLength);
1208
+ if (intBuffer.length === 0) {
1209
+ this.error = "Zero buffer length";
1210
+ return -1;
1211
+ }
1212
+ if (intBuffer[0] === 255) {
1213
+ this.error = "Length block 0xFF is reserved by standard";
1214
+ return -1;
1215
+ }
1216
+ this.isIndefiniteForm = intBuffer[0] === 128;
1217
+ if (this.isIndefiniteForm) {
1218
+ this.blockLength = 1;
1219
+ return inputOffset + this.blockLength;
1220
+ }
1221
+ this.longFormUsed = !!(intBuffer[0] & 128);
1222
+ if (this.longFormUsed === false) {
1223
+ this.length = intBuffer[0];
1224
+ this.blockLength = 1;
1225
+ return inputOffset + this.blockLength;
1226
+ }
1227
+ const count = intBuffer[0] & 127;
1228
+ if (count > 8) {
1229
+ this.error = "Too big integer";
1230
+ return -1;
1231
+ }
1232
+ if (count + 1 > intBuffer.length) {
1233
+ this.error = "End of input reached before message was fully decoded";
1234
+ return -1;
1235
+ }
1236
+ const lenOffset = inputOffset + 1;
1237
+ const lengthBufferView = view.subarray(lenOffset, lenOffset + count);
1238
+ if (lengthBufferView[count - 1] === 0)
1239
+ this.warnings.push("Needlessly long encoded length");
1240
+ this.length = utilFromBase(lengthBufferView, 8);
1241
+ if (this.longFormUsed && this.length <= 127)
1242
+ this.warnings.push("Unnecessary usage of long length form");
1243
+ this.blockLength = count + 1;
1244
+ return inputOffset + this.blockLength;
1245
+ }
1246
+ toBER(sizeOnly = false) {
1247
+ let retBuf;
1248
+ let retView;
1249
+ if (this.length > 127)
1250
+ this.longFormUsed = true;
1251
+ if (this.isIndefiniteForm) {
1252
+ retBuf = new ArrayBuffer(1);
1253
+ if (sizeOnly === false) {
1254
+ retView = new Uint8Array(retBuf);
1255
+ retView[0] = 128;
1256
+ }
1257
+ return retBuf;
1258
+ }
1259
+ if (this.longFormUsed) {
1260
+ const encodedBuf = utilToBase(this.length, 8);
1261
+ if (encodedBuf.byteLength > 127) {
1262
+ this.error = "Too big length";
1263
+ return EMPTY_BUFFER;
1264
+ }
1265
+ retBuf = new ArrayBuffer(encodedBuf.byteLength + 1);
1266
+ if (sizeOnly)
1267
+ return retBuf;
1268
+ const encodedView = new Uint8Array(encodedBuf);
1269
+ retView = new Uint8Array(retBuf);
1270
+ retView[0] = encodedBuf.byteLength | 128;
1271
+ for (let i = 0; i < encodedBuf.byteLength; i++)
1272
+ retView[i + 1] = encodedView[i];
1273
+ return retBuf;
1274
+ }
1275
+ retBuf = new ArrayBuffer(1);
1276
+ if (sizeOnly === false) {
1277
+ retView = new Uint8Array(retBuf);
1278
+ retView[0] = this.length;
1279
+ }
1280
+ return retBuf;
1281
+ }
1282
+ toJSON() {
1283
+ return {
1284
+ ...super.toJSON(),
1285
+ isIndefiniteForm: this.isIndefiniteForm,
1286
+ longFormUsed: this.longFormUsed,
1287
+ length: this.length
1288
+ };
1289
+ }
1290
+ };
1291
+ LocalLengthBlock.NAME = "lengthBlock";
1292
+ var typeStore = {};
1293
+ var BaseBlock = class extends LocalBaseBlock {
1294
+ constructor({ name = EMPTY_STRING, optional = false, primitiveSchema, ...parameters } = {}, valueBlockType) {
1295
+ super(parameters);
1296
+ this.name = name;
1297
+ this.optional = optional;
1298
+ if (primitiveSchema) {
1299
+ this.primitiveSchema = primitiveSchema;
1300
+ }
1301
+ this.idBlock = new LocalIdentificationBlock(parameters);
1302
+ this.lenBlock = new LocalLengthBlock(parameters);
1303
+ this.valueBlock = valueBlockType ? new valueBlockType(parameters) : new ValueBlock(parameters);
1304
+ }
1305
+ fromBER(inputBuffer, inputOffset, inputLength) {
1306
+ const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length);
1307
+ if (resultOffset === -1) {
1308
+ this.error = this.valueBlock.error;
1309
+ return resultOffset;
1310
+ }
1311
+ if (!this.idBlock.error.length)
1312
+ this.blockLength += this.idBlock.blockLength;
1313
+ if (!this.lenBlock.error.length)
1314
+ this.blockLength += this.lenBlock.blockLength;
1315
+ if (!this.valueBlock.error.length)
1316
+ this.blockLength += this.valueBlock.blockLength;
1317
+ return resultOffset;
1318
+ }
1319
+ toBER(sizeOnly, writer) {
1320
+ const _writer = writer || new ViewWriter();
1321
+ if (!writer) {
1322
+ prepareIndefiniteForm(this);
1323
+ }
1324
+ const idBlockBuf = this.idBlock.toBER(sizeOnly);
1325
+ _writer.write(idBlockBuf);
1326
+ if (this.lenBlock.isIndefiniteForm) {
1327
+ _writer.write(new Uint8Array([128]).buffer);
1328
+ this.valueBlock.toBER(sizeOnly, _writer);
1329
+ _writer.write(new ArrayBuffer(2));
1330
+ } else {
1331
+ const valueBlockBuf = this.valueBlock.toBER(sizeOnly);
1332
+ this.lenBlock.length = valueBlockBuf.byteLength;
1333
+ const lenBlockBuf = this.lenBlock.toBER(sizeOnly);
1334
+ _writer.write(lenBlockBuf);
1335
+ _writer.write(valueBlockBuf);
1336
+ }
1337
+ if (!writer) {
1338
+ return _writer.final();
1339
+ }
1340
+ return EMPTY_BUFFER;
1341
+ }
1342
+ toJSON() {
1343
+ const object = {
1344
+ ...super.toJSON(),
1345
+ idBlock: this.idBlock.toJSON(),
1346
+ lenBlock: this.lenBlock.toJSON(),
1347
+ valueBlock: this.valueBlock.toJSON(),
1348
+ name: this.name,
1349
+ optional: this.optional
1350
+ };
1351
+ if (this.primitiveSchema)
1352
+ object.primitiveSchema = this.primitiveSchema.toJSON();
1353
+ return object;
1354
+ }
1355
+ toString(encoding = "ascii") {
1356
+ if (encoding === "ascii") {
1357
+ return this.onAsciiEncoding();
1358
+ }
1359
+ return Convert.ToHex(this.toBER());
1360
+ }
1361
+ onAsciiEncoding() {
1362
+ return `${this.constructor.NAME} : ${Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`;
1363
+ }
1364
+ isEqual(other) {
1365
+ if (this === other) {
1366
+ return true;
1367
+ }
1368
+ if (!(other instanceof this.constructor)) {
1369
+ return false;
1370
+ }
1371
+ const thisRaw = this.toBER();
1372
+ const otherRaw = other.toBER();
1373
+ return isEqualBuffer(thisRaw, otherRaw);
1374
+ }
1375
+ };
1376
+ BaseBlock.NAME = "BaseBlock";
1377
+ function prepareIndefiniteForm(baseBlock) {
1378
+ if (baseBlock instanceof typeStore.Constructed) {
1379
+ for (const value of baseBlock.valueBlock.value) {
1380
+ if (prepareIndefiniteForm(value)) {
1381
+ baseBlock.lenBlock.isIndefiniteForm = true;
1382
+ }
1383
+ }
1384
+ }
1385
+ return !!baseBlock.lenBlock.isIndefiniteForm;
1386
+ }
1387
+ var BaseStringBlock = class extends BaseBlock {
1388
+ constructor({ value = EMPTY_STRING, ...parameters } = {}, stringValueBlockType) {
1389
+ super(parameters, stringValueBlockType);
1390
+ if (value) {
1391
+ this.fromString(value);
1392
+ }
1393
+ }
1394
+ getValue() {
1395
+ return this.valueBlock.value;
1396
+ }
1397
+ setValue(value) {
1398
+ this.valueBlock.value = value;
1399
+ }
1400
+ fromBER(inputBuffer, inputOffset, inputLength) {
1401
+ const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length);
1402
+ if (resultOffset === -1) {
1403
+ this.error = this.valueBlock.error;
1404
+ return resultOffset;
1405
+ }
1406
+ this.fromBuffer(this.valueBlock.valueHexView);
1407
+ if (!this.idBlock.error.length)
1408
+ this.blockLength += this.idBlock.blockLength;
1409
+ if (!this.lenBlock.error.length)
1410
+ this.blockLength += this.lenBlock.blockLength;
1411
+ if (!this.valueBlock.error.length)
1412
+ this.blockLength += this.valueBlock.blockLength;
1413
+ return resultOffset;
1414
+ }
1415
+ onAsciiEncoding() {
1416
+ return `${this.constructor.NAME} : '${this.valueBlock.value}'`;
1417
+ }
1418
+ };
1419
+ BaseStringBlock.NAME = "BaseStringBlock";
1420
+ var LocalPrimitiveValueBlock = class extends HexBlock(ValueBlock) {
1421
+ constructor({ isHexOnly = true, ...parameters } = {}) {
1422
+ super(parameters);
1423
+ this.isHexOnly = isHexOnly;
1424
+ }
1425
+ };
1426
+ LocalPrimitiveValueBlock.NAME = "PrimitiveValueBlock";
1427
+ var _a$w;
1428
+ var Primitive = class extends BaseBlock {
1429
+ constructor(parameters = {}) {
1430
+ super(parameters, LocalPrimitiveValueBlock);
1431
+ this.idBlock.isConstructed = false;
1432
+ }
1433
+ };
1434
+ _a$w = Primitive;
1435
+ (() => {
1436
+ typeStore.Primitive = _a$w;
1437
+ })();
1438
+ Primitive.NAME = "PRIMITIVE";
1439
+ function localChangeType(inputObject, newType) {
1440
+ if (inputObject instanceof newType) {
1441
+ return inputObject;
1442
+ }
1443
+ const newObject = new newType();
1444
+ newObject.idBlock = inputObject.idBlock;
1445
+ newObject.lenBlock = inputObject.lenBlock;
1446
+ newObject.warnings = inputObject.warnings;
1447
+ newObject.valueBeforeDecodeView = inputObject.valueBeforeDecodeView;
1448
+ return newObject;
1449
+ }
1450
+ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.length) {
1451
+ const incomingOffset = inputOffset;
1452
+ let returnObject = new BaseBlock({}, ValueBlock);
1453
+ const baseBlock = new LocalBaseBlock();
1454
+ if (!checkBufferParams(baseBlock, inputBuffer, inputOffset, inputLength)) {
1455
+ returnObject.error = baseBlock.error;
1456
+ return {
1457
+ offset: -1,
1458
+ result: returnObject
1459
+ };
1460
+ }
1461
+ const intBuffer = inputBuffer.subarray(inputOffset, inputOffset + inputLength);
1462
+ if (!intBuffer.length) {
1463
+ returnObject.error = "Zero buffer length";
1464
+ return {
1465
+ offset: -1,
1466
+ result: returnObject
1467
+ };
1468
+ }
1469
+ let resultOffset = returnObject.idBlock.fromBER(inputBuffer, inputOffset, inputLength);
1470
+ if (returnObject.idBlock.warnings.length) {
1471
+ returnObject.warnings.concat(returnObject.idBlock.warnings);
1472
+ }
1473
+ if (resultOffset === -1) {
1474
+ returnObject.error = returnObject.idBlock.error;
1475
+ return {
1476
+ offset: -1,
1477
+ result: returnObject
1478
+ };
1479
+ }
1480
+ inputOffset = resultOffset;
1481
+ inputLength -= returnObject.idBlock.blockLength;
1482
+ resultOffset = returnObject.lenBlock.fromBER(inputBuffer, inputOffset, inputLength);
1483
+ if (returnObject.lenBlock.warnings.length) {
1484
+ returnObject.warnings.concat(returnObject.lenBlock.warnings);
1485
+ }
1486
+ if (resultOffset === -1) {
1487
+ returnObject.error = returnObject.lenBlock.error;
1488
+ return {
1489
+ offset: -1,
1490
+ result: returnObject
1491
+ };
1492
+ }
1493
+ inputOffset = resultOffset;
1494
+ inputLength -= returnObject.lenBlock.blockLength;
1495
+ if (!returnObject.idBlock.isConstructed && returnObject.lenBlock.isIndefiniteForm) {
1496
+ returnObject.error = "Indefinite length form used for primitive encoding form";
1497
+ return {
1498
+ offset: -1,
1499
+ result: returnObject
1500
+ };
1501
+ }
1502
+ let newASN1Type = BaseBlock;
1503
+ switch (returnObject.idBlock.tagClass) {
1504
+ case 1:
1505
+ if (returnObject.idBlock.tagNumber >= 37 && returnObject.idBlock.isHexOnly === false) {
1506
+ returnObject.error = "UNIVERSAL 37 and upper tags are reserved by ASN.1 standard";
1507
+ return {
1508
+ offset: -1,
1509
+ result: returnObject
1510
+ };
1511
+ }
1512
+ switch (returnObject.idBlock.tagNumber) {
1513
+ case 0:
1514
+ if (returnObject.idBlock.isConstructed && returnObject.lenBlock.length > 0) {
1515
+ returnObject.error = "Type [UNIVERSAL 0] is reserved";
1516
+ return {
1517
+ offset: -1,
1518
+ result: returnObject
1519
+ };
1520
+ }
1521
+ newASN1Type = typeStore.EndOfContent;
1522
+ break;
1523
+ case 1:
1524
+ newASN1Type = typeStore.Boolean;
1525
+ break;
1526
+ case 2:
1527
+ newASN1Type = typeStore.Integer;
1528
+ break;
1529
+ case 3:
1530
+ newASN1Type = typeStore.BitString;
1531
+ break;
1532
+ case 4:
1533
+ newASN1Type = typeStore.OctetString;
1534
+ break;
1535
+ case 5:
1536
+ newASN1Type = typeStore.Null;
1537
+ break;
1538
+ case 6:
1539
+ newASN1Type = typeStore.ObjectIdentifier;
1540
+ break;
1541
+ case 10:
1542
+ newASN1Type = typeStore.Enumerated;
1543
+ break;
1544
+ case 12:
1545
+ newASN1Type = typeStore.Utf8String;
1546
+ break;
1547
+ case 13:
1548
+ newASN1Type = typeStore.RelativeObjectIdentifier;
1549
+ break;
1550
+ case 14:
1551
+ newASN1Type = typeStore.TIME;
1552
+ break;
1553
+ case 15:
1554
+ returnObject.error = "[UNIVERSAL 15] is reserved by ASN.1 standard";
1555
+ return {
1556
+ offset: -1,
1557
+ result: returnObject
1558
+ };
1559
+ case 16:
1560
+ newASN1Type = typeStore.Sequence;
1561
+ break;
1562
+ case 17:
1563
+ newASN1Type = typeStore.Set;
1564
+ break;
1565
+ case 18:
1566
+ newASN1Type = typeStore.NumericString;
1567
+ break;
1568
+ case 19:
1569
+ newASN1Type = typeStore.PrintableString;
1570
+ break;
1571
+ case 20:
1572
+ newASN1Type = typeStore.TeletexString;
1573
+ break;
1574
+ case 21:
1575
+ newASN1Type = typeStore.VideotexString;
1576
+ break;
1577
+ case 22:
1578
+ newASN1Type = typeStore.IA5String;
1579
+ break;
1580
+ case 23:
1581
+ newASN1Type = typeStore.UTCTime;
1582
+ break;
1583
+ case 24:
1584
+ newASN1Type = typeStore.GeneralizedTime;
1585
+ break;
1586
+ case 25:
1587
+ newASN1Type = typeStore.GraphicString;
1588
+ break;
1589
+ case 26:
1590
+ newASN1Type = typeStore.VisibleString;
1591
+ break;
1592
+ case 27:
1593
+ newASN1Type = typeStore.GeneralString;
1594
+ break;
1595
+ case 28:
1596
+ newASN1Type = typeStore.UniversalString;
1597
+ break;
1598
+ case 29:
1599
+ newASN1Type = typeStore.CharacterString;
1600
+ break;
1601
+ case 30:
1602
+ newASN1Type = typeStore.BmpString;
1603
+ break;
1604
+ case 31:
1605
+ newASN1Type = typeStore.DATE;
1606
+ break;
1607
+ case 32:
1608
+ newASN1Type = typeStore.TimeOfDay;
1609
+ break;
1610
+ case 33:
1611
+ newASN1Type = typeStore.DateTime;
1612
+ break;
1613
+ case 34:
1614
+ newASN1Type = typeStore.Duration;
1615
+ break;
1616
+ default: {
1617
+ const newObject = returnObject.idBlock.isConstructed ? new typeStore.Constructed() : new typeStore.Primitive();
1618
+ newObject.idBlock = returnObject.idBlock;
1619
+ newObject.lenBlock = returnObject.lenBlock;
1620
+ newObject.warnings = returnObject.warnings;
1621
+ returnObject = newObject;
1622
+ }
1623
+ }
1624
+ break;
1625
+ case 2:
1626
+ case 3:
1627
+ case 4:
1628
+ default: {
1629
+ newASN1Type = returnObject.idBlock.isConstructed ? typeStore.Constructed : typeStore.Primitive;
1630
+ }
1631
+ }
1632
+ returnObject = localChangeType(returnObject, newASN1Type);
1633
+ resultOffset = returnObject.fromBER(inputBuffer, inputOffset, returnObject.lenBlock.isIndefiniteForm ? inputLength : returnObject.lenBlock.length);
1634
+ returnObject.valueBeforeDecodeView = inputBuffer.subarray(incomingOffset, incomingOffset + returnObject.blockLength);
1635
+ return {
1636
+ offset: resultOffset,
1637
+ result: returnObject
1638
+ };
1639
+ }
1640
+ function fromBER(inputBuffer) {
1641
+ if (!inputBuffer.byteLength) {
1642
+ const result = new BaseBlock({}, ValueBlock);
1643
+ result.error = "Input buffer has zero length";
1644
+ return {
1645
+ offset: -1,
1646
+ result
1647
+ };
1648
+ }
1649
+ return localFromBER(BufferSourceConverter.toUint8Array(inputBuffer).slice(), 0, inputBuffer.byteLength);
1650
+ }
1651
+ function checkLen(indefiniteLength, length) {
1652
+ if (indefiniteLength) {
1653
+ return 1;
1654
+ }
1655
+ return length;
1656
+ }
1657
+ var LocalConstructedValueBlock = class extends ValueBlock {
1658
+ constructor({ value = [], isIndefiniteForm = false, ...parameters } = {}) {
1659
+ super(parameters);
1660
+ this.value = value;
1661
+ this.isIndefiniteForm = isIndefiniteForm;
1662
+ }
1663
+ fromBER(inputBuffer, inputOffset, inputLength) {
1664
+ const view = BufferSourceConverter.toUint8Array(inputBuffer);
1665
+ if (!checkBufferParams(this, view, inputOffset, inputLength)) {
1666
+ return -1;
1667
+ }
1668
+ this.valueBeforeDecodeView = view.subarray(inputOffset, inputOffset + inputLength);
1669
+ if (this.valueBeforeDecodeView.length === 0) {
1670
+ this.warnings.push("Zero buffer length");
1671
+ return inputOffset;
1672
+ }
1673
+ let currentOffset = inputOffset;
1674
+ while (checkLen(this.isIndefiniteForm, inputLength) > 0) {
1675
+ const returnObject = localFromBER(view, currentOffset, inputLength);
1676
+ if (returnObject.offset === -1) {
1677
+ this.error = returnObject.result.error;
1678
+ this.warnings.concat(returnObject.result.warnings);
1679
+ return -1;
1680
+ }
1681
+ currentOffset = returnObject.offset;
1682
+ this.blockLength += returnObject.result.blockLength;
1683
+ inputLength -= returnObject.result.blockLength;
1684
+ this.value.push(returnObject.result);
1685
+ if (this.isIndefiniteForm && returnObject.result.constructor.NAME === END_OF_CONTENT_NAME) {
1686
+ break;
1687
+ }
1688
+ }
1689
+ if (this.isIndefiniteForm) {
1690
+ if (this.value[this.value.length - 1].constructor.NAME === END_OF_CONTENT_NAME) {
1691
+ this.value.pop();
1692
+ } else {
1693
+ this.warnings.push("No EndOfContent block encoded");
1694
+ }
1695
+ }
1696
+ return currentOffset;
1697
+ }
1698
+ toBER(sizeOnly, writer) {
1699
+ const _writer = writer || new ViewWriter();
1700
+ for (let i = 0; i < this.value.length; i++) {
1701
+ this.value[i].toBER(sizeOnly, _writer);
1702
+ }
1703
+ if (!writer) {
1704
+ return _writer.final();
1705
+ }
1706
+ return EMPTY_BUFFER;
1707
+ }
1708
+ toJSON() {
1709
+ const object = {
1710
+ ...super.toJSON(),
1711
+ isIndefiniteForm: this.isIndefiniteForm,
1712
+ value: []
1713
+ };
1714
+ for (const value of this.value) {
1715
+ object.value.push(value.toJSON());
1716
+ }
1717
+ return object;
1718
+ }
1719
+ };
1720
+ LocalConstructedValueBlock.NAME = "ConstructedValueBlock";
1721
+ var _a$v;
1722
+ var Constructed = class extends BaseBlock {
1723
+ constructor(parameters = {}) {
1724
+ super(parameters, LocalConstructedValueBlock);
1725
+ this.idBlock.isConstructed = true;
1726
+ }
1727
+ fromBER(inputBuffer, inputOffset, inputLength) {
1728
+ this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
1729
+ const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length);
1730
+ if (resultOffset === -1) {
1731
+ this.error = this.valueBlock.error;
1732
+ return resultOffset;
1733
+ }
1734
+ if (!this.idBlock.error.length)
1735
+ this.blockLength += this.idBlock.blockLength;
1736
+ if (!this.lenBlock.error.length)
1737
+ this.blockLength += this.lenBlock.blockLength;
1738
+ if (!this.valueBlock.error.length)
1739
+ this.blockLength += this.valueBlock.blockLength;
1740
+ return resultOffset;
1741
+ }
1742
+ onAsciiEncoding() {
1743
+ const values = [];
1744
+ for (const value of this.valueBlock.value) {
1745
+ values.push(value.toString("ascii").split("\n").map((o) => ` ${o}`).join("\n"));
1746
+ }
1747
+ const blockName = this.idBlock.tagClass === 3 ? `[${this.idBlock.tagNumber}]` : this.constructor.NAME;
1748
+ return values.length ? `${blockName} :
1749
+ ${values.join("\n")}` : `${blockName} :`;
1750
+ }
1751
+ };
1752
+ _a$v = Constructed;
1753
+ (() => {
1754
+ typeStore.Constructed = _a$v;
1755
+ })();
1756
+ Constructed.NAME = "CONSTRUCTED";
1757
+ var LocalEndOfContentValueBlock = class extends ValueBlock {
1758
+ fromBER(inputBuffer, inputOffset, inputLength) {
1759
+ return inputOffset;
1760
+ }
1761
+ toBER(sizeOnly) {
1762
+ return EMPTY_BUFFER;
1763
+ }
1764
+ };
1765
+ LocalEndOfContentValueBlock.override = "EndOfContentValueBlock";
1766
+ var _a$u;
1767
+ var EndOfContent = class extends BaseBlock {
1768
+ constructor(parameters = {}) {
1769
+ super(parameters, LocalEndOfContentValueBlock);
1770
+ this.idBlock.tagClass = 1;
1771
+ this.idBlock.tagNumber = 0;
1772
+ }
1773
+ };
1774
+ _a$u = EndOfContent;
1775
+ (() => {
1776
+ typeStore.EndOfContent = _a$u;
1777
+ })();
1778
+ EndOfContent.NAME = END_OF_CONTENT_NAME;
1779
+ var _a$t;
1780
+ var Null = class extends BaseBlock {
1781
+ constructor(parameters = {}) {
1782
+ super(parameters, ValueBlock);
1783
+ this.idBlock.tagClass = 1;
1784
+ this.idBlock.tagNumber = 5;
1785
+ }
1786
+ fromBER(inputBuffer, inputOffset, inputLength) {
1787
+ if (this.lenBlock.length > 0)
1788
+ this.warnings.push("Non-zero length of value block for Null type");
1789
+ if (!this.idBlock.error.length)
1790
+ this.blockLength += this.idBlock.blockLength;
1791
+ if (!this.lenBlock.error.length)
1792
+ this.blockLength += this.lenBlock.blockLength;
1793
+ this.blockLength += inputLength;
1794
+ if (inputOffset + inputLength > inputBuffer.byteLength) {
1795
+ this.error = "End of input reached before message was fully decoded (inconsistent offset and length values)";
1796
+ return -1;
1797
+ }
1798
+ return inputOffset + inputLength;
1799
+ }
1800
+ toBER(sizeOnly, writer) {
1801
+ const retBuf = new ArrayBuffer(2);
1802
+ if (!sizeOnly) {
1803
+ const retView = new Uint8Array(retBuf);
1804
+ retView[0] = 5;
1805
+ retView[1] = 0;
1806
+ }
1807
+ if (writer) {
1808
+ writer.write(retBuf);
1809
+ }
1810
+ return retBuf;
1811
+ }
1812
+ onAsciiEncoding() {
1813
+ return `${this.constructor.NAME}`;
1814
+ }
1815
+ };
1816
+ _a$t = Null;
1817
+ (() => {
1818
+ typeStore.Null = _a$t;
1819
+ })();
1820
+ Null.NAME = "NULL";
1821
+ var LocalBooleanValueBlock = class extends HexBlock(ValueBlock) {
1822
+ constructor({ value, ...parameters } = {}) {
1823
+ super(parameters);
1824
+ if (parameters.valueHex) {
1825
+ this.valueHexView = BufferSourceConverter.toUint8Array(parameters.valueHex);
1826
+ } else {
1827
+ this.valueHexView = new Uint8Array(1);
1828
+ }
1829
+ if (value) {
1830
+ this.value = value;
1831
+ }
1832
+ }
1833
+ get value() {
1834
+ for (const octet of this.valueHexView) {
1835
+ if (octet > 0) {
1836
+ return true;
1837
+ }
1838
+ }
1839
+ return false;
1840
+ }
1841
+ set value(value) {
1842
+ this.valueHexView[0] = value ? 255 : 0;
1843
+ }
1844
+ fromBER(inputBuffer, inputOffset, inputLength) {
1845
+ const inputView = BufferSourceConverter.toUint8Array(inputBuffer);
1846
+ if (!checkBufferParams(this, inputView, inputOffset, inputLength)) {
1847
+ return -1;
1848
+ }
1849
+ this.valueHexView = inputView.subarray(inputOffset, inputOffset + inputLength);
1850
+ if (inputLength > 1)
1851
+ this.warnings.push("Boolean value encoded in more then 1 octet");
1852
+ this.isHexOnly = true;
1853
+ utilDecodeTC.call(this);
1854
+ this.blockLength = inputLength;
1855
+ return inputOffset + inputLength;
1856
+ }
1857
+ toBER() {
1858
+ return this.valueHexView.slice();
1859
+ }
1860
+ toJSON() {
1861
+ return {
1862
+ ...super.toJSON(),
1863
+ value: this.value
1864
+ };
1865
+ }
1866
+ };
1867
+ LocalBooleanValueBlock.NAME = "BooleanValueBlock";
1868
+ var _a$s;
1869
+ var Boolean = class extends BaseBlock {
1870
+ constructor(parameters = {}) {
1871
+ super(parameters, LocalBooleanValueBlock);
1872
+ this.idBlock.tagClass = 1;
1873
+ this.idBlock.tagNumber = 1;
1874
+ }
1875
+ getValue() {
1876
+ return this.valueBlock.value;
1877
+ }
1878
+ setValue(value) {
1879
+ this.valueBlock.value = value;
1880
+ }
1881
+ onAsciiEncoding() {
1882
+ return `${this.constructor.NAME} : ${this.getValue}`;
1883
+ }
1884
+ };
1885
+ _a$s = Boolean;
1886
+ (() => {
1887
+ typeStore.Boolean = _a$s;
1888
+ })();
1889
+ Boolean.NAME = "BOOLEAN";
1890
+ var LocalOctetStringValueBlock = class extends HexBlock(LocalConstructedValueBlock) {
1891
+ constructor({ isConstructed = false, ...parameters } = {}) {
1892
+ super(parameters);
1893
+ this.isConstructed = isConstructed;
1894
+ }
1895
+ fromBER(inputBuffer, inputOffset, inputLength) {
1896
+ let resultOffset = 0;
1897
+ if (this.isConstructed) {
1898
+ this.isHexOnly = false;
1899
+ resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength);
1900
+ if (resultOffset === -1)
1901
+ return resultOffset;
1902
+ for (let i = 0; i < this.value.length; i++) {
1903
+ const currentBlockName = this.value[i].constructor.NAME;
1904
+ if (currentBlockName === END_OF_CONTENT_NAME) {
1905
+ if (this.isIndefiniteForm)
1906
+ break;
1907
+ else {
1908
+ this.error = "EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only";
1909
+ return -1;
1910
+ }
1911
+ }
1912
+ if (currentBlockName !== OCTET_STRING_NAME) {
1913
+ this.error = "OCTET STRING may consists of OCTET STRINGs only";
1914
+ return -1;
1915
+ }
1916
+ }
1917
+ } else {
1918
+ this.isHexOnly = true;
1919
+ resultOffset = super.fromBER(inputBuffer, inputOffset, inputLength);
1920
+ this.blockLength = inputLength;
1921
+ }
1922
+ return resultOffset;
1923
+ }
1924
+ toBER(sizeOnly, writer) {
1925
+ if (this.isConstructed)
1926
+ return LocalConstructedValueBlock.prototype.toBER.call(this, sizeOnly, writer);
1927
+ return sizeOnly ? new ArrayBuffer(this.valueHexView.byteLength) : this.valueHexView.slice().buffer;
1928
+ }
1929
+ toJSON() {
1930
+ return {
1931
+ ...super.toJSON(),
1932
+ isConstructed: this.isConstructed
1933
+ };
1934
+ }
1935
+ };
1936
+ LocalOctetStringValueBlock.NAME = "OctetStringValueBlock";
1937
+ var _a$r;
1938
+ var OctetString = class _OctetString extends BaseBlock {
1939
+ constructor({ idBlock = {}, lenBlock = {}, ...parameters } = {}) {
1940
+ var _b, _c;
1941
+ (_b = parameters.isConstructed) !== null && _b !== void 0 ? _b : parameters.isConstructed = !!((_c = parameters.value) === null || _c === void 0 ? void 0 : _c.length);
1942
+ super({
1943
+ idBlock: {
1944
+ isConstructed: parameters.isConstructed,
1945
+ ...idBlock
1946
+ },
1947
+ lenBlock: {
1948
+ ...lenBlock,
1949
+ isIndefiniteForm: !!parameters.isIndefiniteForm
1950
+ },
1951
+ ...parameters
1952
+ }, LocalOctetStringValueBlock);
1953
+ this.idBlock.tagClass = 1;
1954
+ this.idBlock.tagNumber = 4;
1955
+ }
1956
+ fromBER(inputBuffer, inputOffset, inputLength) {
1957
+ this.valueBlock.isConstructed = this.idBlock.isConstructed;
1958
+ this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
1959
+ if (inputLength === 0) {
1960
+ if (this.idBlock.error.length === 0)
1961
+ this.blockLength += this.idBlock.blockLength;
1962
+ if (this.lenBlock.error.length === 0)
1963
+ this.blockLength += this.lenBlock.blockLength;
1964
+ return inputOffset;
1965
+ }
1966
+ if (!this.valueBlock.isConstructed) {
1967
+ const view = inputBuffer instanceof ArrayBuffer ? new Uint8Array(inputBuffer) : inputBuffer;
1968
+ const buf = view.subarray(inputOffset, inputOffset + inputLength);
1969
+ try {
1970
+ if (buf.byteLength) {
1971
+ const asn = localFromBER(buf, 0, buf.byteLength);
1972
+ if (asn.offset !== -1 && asn.offset === inputLength) {
1973
+ this.valueBlock.value = [asn.result];
1974
+ }
1975
+ }
1976
+ } catch (e) {
1977
+ }
1978
+ }
1979
+ return super.fromBER(inputBuffer, inputOffset, inputLength);
1980
+ }
1981
+ onAsciiEncoding() {
1982
+ if (this.valueBlock.isConstructed || this.valueBlock.value && this.valueBlock.value.length) {
1983
+ return Constructed.prototype.onAsciiEncoding.call(this);
1984
+ }
1985
+ return `${this.constructor.NAME} : ${Convert.ToHex(this.valueBlock.valueHexView)}`;
1986
+ }
1987
+ getValue() {
1988
+ if (!this.idBlock.isConstructed) {
1989
+ return this.valueBlock.valueHexView.slice().buffer;
1990
+ }
1991
+ const array = [];
1992
+ for (const content of this.valueBlock.value) {
1993
+ if (content instanceof _OctetString) {
1994
+ array.push(content.valueBlock.valueHexView);
1995
+ }
1996
+ }
1997
+ return BufferSourceConverter.concat(array);
1998
+ }
1999
+ };
2000
+ _a$r = OctetString;
2001
+ (() => {
2002
+ typeStore.OctetString = _a$r;
2003
+ })();
2004
+ OctetString.NAME = OCTET_STRING_NAME;
2005
+ var LocalBitStringValueBlock = class extends HexBlock(LocalConstructedValueBlock) {
2006
+ constructor({ unusedBits = 0, isConstructed = false, ...parameters } = {}) {
2007
+ super(parameters);
2008
+ this.unusedBits = unusedBits;
2009
+ this.isConstructed = isConstructed;
2010
+ this.blockLength = this.valueHexView.byteLength;
2011
+ }
2012
+ fromBER(inputBuffer, inputOffset, inputLength) {
2013
+ if (!inputLength) {
2014
+ return inputOffset;
2015
+ }
2016
+ let resultOffset = -1;
2017
+ if (this.isConstructed) {
2018
+ resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength);
2019
+ if (resultOffset === -1)
2020
+ return resultOffset;
2021
+ for (const value of this.value) {
2022
+ const currentBlockName = value.constructor.NAME;
2023
+ if (currentBlockName === END_OF_CONTENT_NAME) {
2024
+ if (this.isIndefiniteForm)
2025
+ break;
2026
+ else {
2027
+ this.error = "EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only";
2028
+ return -1;
2029
+ }
2030
+ }
2031
+ if (currentBlockName !== BIT_STRING_NAME) {
2032
+ this.error = "BIT STRING may consists of BIT STRINGs only";
2033
+ return -1;
2034
+ }
2035
+ const valueBlock = value.valueBlock;
2036
+ if (this.unusedBits > 0 && valueBlock.unusedBits > 0) {
2037
+ this.error = 'Using of "unused bits" inside constructive BIT STRING allowed for least one only';
2038
+ return -1;
2039
+ }
2040
+ this.unusedBits = valueBlock.unusedBits;
2041
+ }
2042
+ return resultOffset;
2043
+ }
2044
+ const inputView = BufferSourceConverter.toUint8Array(inputBuffer);
2045
+ if (!checkBufferParams(this, inputView, inputOffset, inputLength)) {
2046
+ return -1;
2047
+ }
2048
+ const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength);
2049
+ this.unusedBits = intBuffer[0];
2050
+ if (this.unusedBits > 7) {
2051
+ this.error = "Unused bits for BitString must be in range 0-7";
2052
+ return -1;
2053
+ }
2054
+ if (!this.unusedBits) {
2055
+ const buf = intBuffer.subarray(1);
2056
+ try {
2057
+ if (buf.byteLength) {
2058
+ const asn = localFromBER(buf, 0, buf.byteLength);
2059
+ if (asn.offset !== -1 && asn.offset === inputLength - 1) {
2060
+ this.value = [asn.result];
2061
+ }
2062
+ }
2063
+ } catch (e) {
2064
+ }
2065
+ }
2066
+ this.valueHexView = intBuffer.subarray(1);
2067
+ this.blockLength = intBuffer.length;
2068
+ return inputOffset + inputLength;
2069
+ }
2070
+ toBER(sizeOnly, writer) {
2071
+ if (this.isConstructed) {
2072
+ return LocalConstructedValueBlock.prototype.toBER.call(this, sizeOnly, writer);
2073
+ }
2074
+ if (sizeOnly) {
2075
+ return new ArrayBuffer(this.valueHexView.byteLength + 1);
2076
+ }
2077
+ if (!this.valueHexView.byteLength) {
2078
+ return EMPTY_BUFFER;
2079
+ }
2080
+ const retView = new Uint8Array(this.valueHexView.length + 1);
2081
+ retView[0] = this.unusedBits;
2082
+ retView.set(this.valueHexView, 1);
2083
+ return retView.buffer;
2084
+ }
2085
+ toJSON() {
2086
+ return {
2087
+ ...super.toJSON(),
2088
+ unusedBits: this.unusedBits,
2089
+ isConstructed: this.isConstructed
2090
+ };
2091
+ }
2092
+ };
2093
+ LocalBitStringValueBlock.NAME = "BitStringValueBlock";
2094
+ var _a$q;
2095
+ var BitString = class extends BaseBlock {
2096
+ constructor({ idBlock = {}, lenBlock = {}, ...parameters } = {}) {
2097
+ var _b, _c;
2098
+ (_b = parameters.isConstructed) !== null && _b !== void 0 ? _b : parameters.isConstructed = !!((_c = parameters.value) === null || _c === void 0 ? void 0 : _c.length);
2099
+ super({
2100
+ idBlock: {
2101
+ isConstructed: parameters.isConstructed,
2102
+ ...idBlock
2103
+ },
2104
+ lenBlock: {
2105
+ ...lenBlock,
2106
+ isIndefiniteForm: !!parameters.isIndefiniteForm
2107
+ },
2108
+ ...parameters
2109
+ }, LocalBitStringValueBlock);
2110
+ this.idBlock.tagClass = 1;
2111
+ this.idBlock.tagNumber = 3;
2112
+ }
2113
+ fromBER(inputBuffer, inputOffset, inputLength) {
2114
+ this.valueBlock.isConstructed = this.idBlock.isConstructed;
2115
+ this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
2116
+ return super.fromBER(inputBuffer, inputOffset, inputLength);
2117
+ }
2118
+ onAsciiEncoding() {
2119
+ if (this.valueBlock.isConstructed || this.valueBlock.value && this.valueBlock.value.length) {
2120
+ return Constructed.prototype.onAsciiEncoding.call(this);
2121
+ } else {
2122
+ const bits = [];
2123
+ const valueHex = this.valueBlock.valueHexView;
2124
+ for (const byte of valueHex) {
2125
+ bits.push(byte.toString(2).padStart(8, "0"));
2126
+ }
2127
+ const bitsStr = bits.join("");
2128
+ return `${this.constructor.NAME} : ${bitsStr.substring(0, bitsStr.length - this.valueBlock.unusedBits)}`;
2129
+ }
2130
+ }
2131
+ };
2132
+ _a$q = BitString;
2133
+ (() => {
2134
+ typeStore.BitString = _a$q;
2135
+ })();
2136
+ BitString.NAME = BIT_STRING_NAME;
2137
+ var _a$p;
2138
+ function viewAdd(first, second) {
2139
+ const c = new Uint8Array([0]);
2140
+ const firstView = new Uint8Array(first);
2141
+ const secondView = new Uint8Array(second);
2142
+ let firstViewCopy = firstView.slice(0);
2143
+ const firstViewCopyLength = firstViewCopy.length - 1;
2144
+ const secondViewCopy = secondView.slice(0);
2145
+ const secondViewCopyLength = secondViewCopy.length - 1;
2146
+ let value = 0;
2147
+ const max = secondViewCopyLength < firstViewCopyLength ? firstViewCopyLength : secondViewCopyLength;
2148
+ let counter = 0;
2149
+ for (let i = max; i >= 0; i--, counter++) {
2150
+ switch (true) {
2151
+ case counter < secondViewCopy.length:
2152
+ value = firstViewCopy[firstViewCopyLength - counter] + secondViewCopy[secondViewCopyLength - counter] + c[0];
2153
+ break;
2154
+ default:
2155
+ value = firstViewCopy[firstViewCopyLength - counter] + c[0];
2156
+ }
2157
+ c[0] = value / 10;
2158
+ switch (true) {
2159
+ case counter >= firstViewCopy.length:
2160
+ firstViewCopy = utilConcatView(new Uint8Array([value % 10]), firstViewCopy);
2161
+ break;
2162
+ default:
2163
+ firstViewCopy[firstViewCopyLength - counter] = value % 10;
2164
+ }
2165
+ }
2166
+ if (c[0] > 0)
2167
+ firstViewCopy = utilConcatView(c, firstViewCopy);
2168
+ return firstViewCopy;
2169
+ }
2170
+ function power2(n) {
2171
+ if (n >= powers2.length) {
2172
+ for (let p = powers2.length; p <= n; p++) {
2173
+ const c = new Uint8Array([0]);
2174
+ let digits = powers2[p - 1].slice(0);
2175
+ for (let i = digits.length - 1; i >= 0; i--) {
2176
+ const newValue = new Uint8Array([(digits[i] << 1) + c[0]]);
2177
+ c[0] = newValue[0] / 10;
2178
+ digits[i] = newValue[0] % 10;
2179
+ }
2180
+ if (c[0] > 0)
2181
+ digits = utilConcatView(c, digits);
2182
+ powers2.push(digits);
2183
+ }
2184
+ }
2185
+ return powers2[n];
2186
+ }
2187
+ function viewSub(first, second) {
2188
+ let b = 0;
2189
+ const firstView = new Uint8Array(first);
2190
+ const secondView = new Uint8Array(second);
2191
+ const firstViewCopy = firstView.slice(0);
2192
+ const firstViewCopyLength = firstViewCopy.length - 1;
2193
+ const secondViewCopy = secondView.slice(0);
2194
+ const secondViewCopyLength = secondViewCopy.length - 1;
2195
+ let value;
2196
+ let counter = 0;
2197
+ for (let i = secondViewCopyLength; i >= 0; i--, counter++) {
2198
+ value = firstViewCopy[firstViewCopyLength - counter] - secondViewCopy[secondViewCopyLength - counter] - b;
2199
+ switch (true) {
2200
+ case value < 0:
2201
+ b = 1;
2202
+ firstViewCopy[firstViewCopyLength - counter] = value + 10;
2203
+ break;
2204
+ default:
2205
+ b = 0;
2206
+ firstViewCopy[firstViewCopyLength - counter] = value;
2207
+ }
2208
+ }
2209
+ if (b > 0) {
2210
+ for (let i = firstViewCopyLength - secondViewCopyLength + 1; i >= 0; i--, counter++) {
2211
+ value = firstViewCopy[firstViewCopyLength - counter] - b;
2212
+ if (value < 0) {
2213
+ b = 1;
2214
+ firstViewCopy[firstViewCopyLength - counter] = value + 10;
2215
+ } else {
2216
+ b = 0;
2217
+ firstViewCopy[firstViewCopyLength - counter] = value;
2218
+ break;
2219
+ }
2220
+ }
2221
+ }
2222
+ return firstViewCopy.slice();
2223
+ }
2224
+ var LocalIntegerValueBlock = class extends HexBlock(ValueBlock) {
2225
+ constructor({ value, ...parameters } = {}) {
2226
+ super(parameters);
2227
+ this._valueDec = 0;
2228
+ if (parameters.valueHex) {
2229
+ this.setValueHex();
2230
+ }
2231
+ if (value !== void 0) {
2232
+ this.valueDec = value;
2233
+ }
2234
+ }
2235
+ setValueHex() {
2236
+ if (this.valueHexView.length >= 4) {
2237
+ this.warnings.push("Too big Integer for decoding, hex only");
2238
+ this.isHexOnly = true;
2239
+ this._valueDec = 0;
2240
+ } else {
2241
+ this.isHexOnly = false;
2242
+ if (this.valueHexView.length > 0) {
2243
+ this._valueDec = utilDecodeTC.call(this);
2244
+ }
2245
+ }
2246
+ }
2247
+ set valueDec(v) {
2248
+ this._valueDec = v;
2249
+ this.isHexOnly = false;
2250
+ this.valueHexView = new Uint8Array(utilEncodeTC(v));
2251
+ }
2252
+ get valueDec() {
2253
+ return this._valueDec;
2254
+ }
2255
+ fromDER(inputBuffer, inputOffset, inputLength, expectedLength = 0) {
2256
+ const offset = this.fromBER(inputBuffer, inputOffset, inputLength);
2257
+ if (offset === -1)
2258
+ return offset;
2259
+ const view = this.valueHexView;
2260
+ if (view[0] === 0 && (view[1] & 128) !== 0) {
2261
+ this.valueHexView = view.subarray(1);
2262
+ } else {
2263
+ if (expectedLength !== 0) {
2264
+ if (view.length < expectedLength) {
2265
+ if (expectedLength - view.length > 1)
2266
+ expectedLength = view.length + 1;
2267
+ this.valueHexView = view.subarray(expectedLength - view.length);
2268
+ }
2269
+ }
2270
+ }
2271
+ return offset;
2272
+ }
2273
+ toDER(sizeOnly = false) {
2274
+ const view = this.valueHexView;
2275
+ switch (true) {
2276
+ case (view[0] & 128) !== 0:
2277
+ {
2278
+ const updatedView = new Uint8Array(this.valueHexView.length + 1);
2279
+ updatedView[0] = 0;
2280
+ updatedView.set(view, 1);
2281
+ this.valueHexView = updatedView;
2282
+ }
2283
+ break;
2284
+ case (view[0] === 0 && (view[1] & 128) === 0):
2285
+ {
2286
+ this.valueHexView = this.valueHexView.subarray(1);
2287
+ }
2288
+ break;
2289
+ }
2290
+ return this.toBER(sizeOnly);
2291
+ }
2292
+ fromBER(inputBuffer, inputOffset, inputLength) {
2293
+ const resultOffset = super.fromBER(inputBuffer, inputOffset, inputLength);
2294
+ if (resultOffset === -1) {
2295
+ return resultOffset;
2296
+ }
2297
+ this.setValueHex();
2298
+ return resultOffset;
2299
+ }
2300
+ toBER(sizeOnly) {
2301
+ return sizeOnly ? new ArrayBuffer(this.valueHexView.length) : this.valueHexView.slice().buffer;
2302
+ }
2303
+ toJSON() {
2304
+ return {
2305
+ ...super.toJSON(),
2306
+ valueDec: this.valueDec
2307
+ };
2308
+ }
2309
+ toString() {
2310
+ const firstBit = this.valueHexView.length * 8 - 1;
2311
+ let digits = new Uint8Array(this.valueHexView.length * 8 / 3);
2312
+ let bitNumber = 0;
2313
+ let currentByte;
2314
+ const asn1View = this.valueHexView;
2315
+ let result = "";
2316
+ let flag = false;
2317
+ for (let byteNumber = asn1View.byteLength - 1; byteNumber >= 0; byteNumber--) {
2318
+ currentByte = asn1View[byteNumber];
2319
+ for (let i = 0; i < 8; i++) {
2320
+ if ((currentByte & 1) === 1) {
2321
+ switch (bitNumber) {
2322
+ case firstBit:
2323
+ digits = viewSub(power2(bitNumber), digits);
2324
+ result = "-";
2325
+ break;
2326
+ default:
2327
+ digits = viewAdd(digits, power2(bitNumber));
2328
+ }
2329
+ }
2330
+ bitNumber++;
2331
+ currentByte >>= 1;
2332
+ }
2333
+ }
2334
+ for (let i = 0; i < digits.length; i++) {
2335
+ if (digits[i])
2336
+ flag = true;
2337
+ if (flag)
2338
+ result += digitsString.charAt(digits[i]);
2339
+ }
2340
+ if (flag === false)
2341
+ result += digitsString.charAt(0);
2342
+ return result;
2343
+ }
2344
+ };
2345
+ _a$p = LocalIntegerValueBlock;
2346
+ LocalIntegerValueBlock.NAME = "IntegerValueBlock";
2347
+ (() => {
2348
+ Object.defineProperty(_a$p.prototype, "valueHex", {
2349
+ set: function(v) {
2350
+ this.valueHexView = new Uint8Array(v);
2351
+ this.setValueHex();
2352
+ },
2353
+ get: function() {
2354
+ return this.valueHexView.slice().buffer;
2355
+ }
2356
+ });
2357
+ })();
2358
+ var _a$o;
2359
+ var Integer = class _Integer extends BaseBlock {
2360
+ constructor(parameters = {}) {
2361
+ super(parameters, LocalIntegerValueBlock);
2362
+ this.idBlock.tagClass = 1;
2363
+ this.idBlock.tagNumber = 2;
2364
+ }
2365
+ toBigInt() {
2366
+ assertBigInt();
2367
+ return BigInt(this.valueBlock.toString());
2368
+ }
2369
+ static fromBigInt(value) {
2370
+ assertBigInt();
2371
+ const bigIntValue = BigInt(value);
2372
+ const writer = new ViewWriter();
2373
+ const hex = bigIntValue.toString(16).replace(/^-/, "");
2374
+ const view = new Uint8Array(Convert.FromHex(hex));
2375
+ if (bigIntValue < 0) {
2376
+ const first = new Uint8Array(view.length + (view[0] & 128 ? 1 : 0));
2377
+ first[0] |= 128;
2378
+ const firstInt = BigInt(`0x${Convert.ToHex(first)}`);
2379
+ const secondInt = firstInt + bigIntValue;
2380
+ const second = BufferSourceConverter.toUint8Array(Convert.FromHex(secondInt.toString(16)));
2381
+ second[0] |= 128;
2382
+ writer.write(second);
2383
+ } else {
2384
+ if (view[0] & 128) {
2385
+ writer.write(new Uint8Array([0]));
2386
+ }
2387
+ writer.write(view);
2388
+ }
2389
+ const res = new _Integer({
2390
+ valueHex: writer.final()
2391
+ });
2392
+ return res;
2393
+ }
2394
+ convertToDER() {
2395
+ const integer = new _Integer({ valueHex: this.valueBlock.valueHexView });
2396
+ integer.valueBlock.toDER();
2397
+ return integer;
2398
+ }
2399
+ convertFromDER() {
2400
+ return new _Integer({
2401
+ valueHex: this.valueBlock.valueHexView[0] === 0 ? this.valueBlock.valueHexView.subarray(1) : this.valueBlock.valueHexView
2402
+ });
2403
+ }
2404
+ onAsciiEncoding() {
2405
+ return `${this.constructor.NAME} : ${this.valueBlock.toString()}`;
2406
+ }
2407
+ };
2408
+ _a$o = Integer;
2409
+ (() => {
2410
+ typeStore.Integer = _a$o;
2411
+ })();
2412
+ Integer.NAME = "INTEGER";
2413
+ var _a$n;
2414
+ var Enumerated = class extends Integer {
2415
+ constructor(parameters = {}) {
2416
+ super(parameters);
2417
+ this.idBlock.tagClass = 1;
2418
+ this.idBlock.tagNumber = 10;
2419
+ }
2420
+ };
2421
+ _a$n = Enumerated;
2422
+ (() => {
2423
+ typeStore.Enumerated = _a$n;
2424
+ })();
2425
+ Enumerated.NAME = "ENUMERATED";
2426
+ var LocalSidValueBlock = class extends HexBlock(ValueBlock) {
2427
+ constructor({ valueDec = -1, isFirstSid = false, ...parameters } = {}) {
2428
+ super(parameters);
2429
+ this.valueDec = valueDec;
2430
+ this.isFirstSid = isFirstSid;
2431
+ }
2432
+ fromBER(inputBuffer, inputOffset, inputLength) {
2433
+ if (!inputLength) {
2434
+ return inputOffset;
2435
+ }
2436
+ const inputView = BufferSourceConverter.toUint8Array(inputBuffer);
2437
+ if (!checkBufferParams(this, inputView, inputOffset, inputLength)) {
2438
+ return -1;
2439
+ }
2440
+ const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength);
2441
+ this.valueHexView = new Uint8Array(inputLength);
2442
+ for (let i = 0; i < inputLength; i++) {
2443
+ this.valueHexView[i] = intBuffer[i] & 127;
2444
+ this.blockLength++;
2445
+ if ((intBuffer[i] & 128) === 0)
2446
+ break;
2447
+ }
2448
+ const tempView = new Uint8Array(this.blockLength);
2449
+ for (let i = 0; i < this.blockLength; i++) {
2450
+ tempView[i] = this.valueHexView[i];
2451
+ }
2452
+ this.valueHexView = tempView;
2453
+ if ((intBuffer[this.blockLength - 1] & 128) !== 0) {
2454
+ this.error = "End of input reached before message was fully decoded";
2455
+ return -1;
2456
+ }
2457
+ if (this.valueHexView[0] === 0)
2458
+ this.warnings.push("Needlessly long format of SID encoding");
2459
+ if (this.blockLength <= 8)
2460
+ this.valueDec = utilFromBase(this.valueHexView, 7);
2461
+ else {
2462
+ this.isHexOnly = true;
2463
+ this.warnings.push("Too big SID for decoding, hex only");
2464
+ }
2465
+ return inputOffset + this.blockLength;
2466
+ }
2467
+ set valueBigInt(value) {
2468
+ assertBigInt();
2469
+ let bits = BigInt(value).toString(2);
2470
+ while (bits.length % 7) {
2471
+ bits = "0" + bits;
2472
+ }
2473
+ const bytes = new Uint8Array(bits.length / 7);
2474
+ for (let i = 0; i < bytes.length; i++) {
2475
+ bytes[i] = parseInt(bits.slice(i * 7, i * 7 + 7), 2) + (i + 1 < bytes.length ? 128 : 0);
2476
+ }
2477
+ this.fromBER(bytes.buffer, 0, bytes.length);
2478
+ }
2479
+ toBER(sizeOnly) {
2480
+ if (this.isHexOnly) {
2481
+ if (sizeOnly)
2482
+ return new ArrayBuffer(this.valueHexView.byteLength);
2483
+ const curView = this.valueHexView;
2484
+ const retView2 = new Uint8Array(this.blockLength);
2485
+ for (let i = 0; i < this.blockLength - 1; i++)
2486
+ retView2[i] = curView[i] | 128;
2487
+ retView2[this.blockLength - 1] = curView[this.blockLength - 1];
2488
+ return retView2.buffer;
2489
+ }
2490
+ const encodedBuf = utilToBase(this.valueDec, 7);
2491
+ if (encodedBuf.byteLength === 0) {
2492
+ this.error = "Error during encoding SID value";
2493
+ return EMPTY_BUFFER;
2494
+ }
2495
+ const retView = new Uint8Array(encodedBuf.byteLength);
2496
+ if (!sizeOnly) {
2497
+ const encodedView = new Uint8Array(encodedBuf);
2498
+ const len = encodedBuf.byteLength - 1;
2499
+ for (let i = 0; i < len; i++)
2500
+ retView[i] = encodedView[i] | 128;
2501
+ retView[len] = encodedView[len];
2502
+ }
2503
+ return retView;
2504
+ }
2505
+ toString() {
2506
+ let result = "";
2507
+ if (this.isHexOnly)
2508
+ result = Convert.ToHex(this.valueHexView);
2509
+ else {
2510
+ if (this.isFirstSid) {
2511
+ let sidValue = this.valueDec;
2512
+ if (this.valueDec <= 39)
2513
+ result = "0.";
2514
+ else {
2515
+ if (this.valueDec <= 79) {
2516
+ result = "1.";
2517
+ sidValue -= 40;
2518
+ } else {
2519
+ result = "2.";
2520
+ sidValue -= 80;
2521
+ }
2522
+ }
2523
+ result += sidValue.toString();
2524
+ } else
2525
+ result = this.valueDec.toString();
2526
+ }
2527
+ return result;
2528
+ }
2529
+ toJSON() {
2530
+ return {
2531
+ ...super.toJSON(),
2532
+ valueDec: this.valueDec,
2533
+ isFirstSid: this.isFirstSid
2534
+ };
2535
+ }
2536
+ };
2537
+ LocalSidValueBlock.NAME = "sidBlock";
2538
+ var LocalObjectIdentifierValueBlock = class extends ValueBlock {
2539
+ constructor({ value = EMPTY_STRING, ...parameters } = {}) {
2540
+ super(parameters);
2541
+ this.value = [];
2542
+ if (value) {
2543
+ this.fromString(value);
2544
+ }
2545
+ }
2546
+ fromBER(inputBuffer, inputOffset, inputLength) {
2547
+ let resultOffset = inputOffset;
2548
+ while (inputLength > 0) {
2549
+ const sidBlock = new LocalSidValueBlock();
2550
+ resultOffset = sidBlock.fromBER(inputBuffer, resultOffset, inputLength);
2551
+ if (resultOffset === -1) {
2552
+ this.blockLength = 0;
2553
+ this.error = sidBlock.error;
2554
+ return resultOffset;
2555
+ }
2556
+ if (this.value.length === 0)
2557
+ sidBlock.isFirstSid = true;
2558
+ this.blockLength += sidBlock.blockLength;
2559
+ inputLength -= sidBlock.blockLength;
2560
+ this.value.push(sidBlock);
2561
+ }
2562
+ return resultOffset;
2563
+ }
2564
+ toBER(sizeOnly) {
2565
+ const retBuffers = [];
2566
+ for (let i = 0; i < this.value.length; i++) {
2567
+ const valueBuf = this.value[i].toBER(sizeOnly);
2568
+ if (valueBuf.byteLength === 0) {
2569
+ this.error = this.value[i].error;
2570
+ return EMPTY_BUFFER;
2571
+ }
2572
+ retBuffers.push(valueBuf);
2573
+ }
2574
+ return concat(retBuffers);
2575
+ }
2576
+ fromString(string) {
2577
+ this.value = [];
2578
+ let pos1 = 0;
2579
+ let pos2 = 0;
2580
+ let sid = "";
2581
+ let flag = false;
2582
+ do {
2583
+ pos2 = string.indexOf(".", pos1);
2584
+ if (pos2 === -1)
2585
+ sid = string.substring(pos1);
2586
+ else
2587
+ sid = string.substring(pos1, pos2);
2588
+ pos1 = pos2 + 1;
2589
+ if (flag) {
2590
+ const sidBlock = this.value[0];
2591
+ let plus = 0;
2592
+ switch (sidBlock.valueDec) {
2593
+ case 0:
2594
+ break;
2595
+ case 1:
2596
+ plus = 40;
2597
+ break;
2598
+ case 2:
2599
+ plus = 80;
2600
+ break;
2601
+ default:
2602
+ this.value = [];
2603
+ return;
2604
+ }
2605
+ const parsedSID = parseInt(sid, 10);
2606
+ if (isNaN(parsedSID))
2607
+ return;
2608
+ sidBlock.valueDec = parsedSID + plus;
2609
+ flag = false;
2610
+ } else {
2611
+ const sidBlock = new LocalSidValueBlock();
2612
+ if (sid > Number.MAX_SAFE_INTEGER) {
2613
+ assertBigInt();
2614
+ const sidValue = BigInt(sid);
2615
+ sidBlock.valueBigInt = sidValue;
2616
+ } else {
2617
+ sidBlock.valueDec = parseInt(sid, 10);
2618
+ if (isNaN(sidBlock.valueDec))
2619
+ return;
2620
+ }
2621
+ if (!this.value.length) {
2622
+ sidBlock.isFirstSid = true;
2623
+ flag = true;
2624
+ }
2625
+ this.value.push(sidBlock);
2626
+ }
2627
+ } while (pos2 !== -1);
2628
+ }
2629
+ toString() {
2630
+ let result = "";
2631
+ let isHexOnly = false;
2632
+ for (let i = 0; i < this.value.length; i++) {
2633
+ isHexOnly = this.value[i].isHexOnly;
2634
+ let sidStr = this.value[i].toString();
2635
+ if (i !== 0)
2636
+ result = `${result}.`;
2637
+ if (isHexOnly) {
2638
+ sidStr = `{${sidStr}}`;
2639
+ if (this.value[i].isFirstSid)
2640
+ result = `2.{${sidStr} - 80}`;
2641
+ else
2642
+ result += sidStr;
2643
+ } else
2644
+ result += sidStr;
2645
+ }
2646
+ return result;
2647
+ }
2648
+ toJSON() {
2649
+ const object = {
2650
+ ...super.toJSON(),
2651
+ value: this.toString(),
2652
+ sidArray: []
2653
+ };
2654
+ for (let i = 0; i < this.value.length; i++) {
2655
+ object.sidArray.push(this.value[i].toJSON());
2656
+ }
2657
+ return object;
2658
+ }
2659
+ };
2660
+ LocalObjectIdentifierValueBlock.NAME = "ObjectIdentifierValueBlock";
2661
+ var _a$m;
2662
+ var ObjectIdentifier = class extends BaseBlock {
2663
+ constructor(parameters = {}) {
2664
+ super(parameters, LocalObjectIdentifierValueBlock);
2665
+ this.idBlock.tagClass = 1;
2666
+ this.idBlock.tagNumber = 6;
2667
+ }
2668
+ getValue() {
2669
+ return this.valueBlock.toString();
2670
+ }
2671
+ setValue(value) {
2672
+ this.valueBlock.fromString(value);
2673
+ }
2674
+ onAsciiEncoding() {
2675
+ return `${this.constructor.NAME} : ${this.valueBlock.toString() || "empty"}`;
2676
+ }
2677
+ toJSON() {
2678
+ return {
2679
+ ...super.toJSON(),
2680
+ value: this.getValue()
2681
+ };
2682
+ }
2683
+ };
2684
+ _a$m = ObjectIdentifier;
2685
+ (() => {
2686
+ typeStore.ObjectIdentifier = _a$m;
2687
+ })();
2688
+ ObjectIdentifier.NAME = "OBJECT IDENTIFIER";
2689
+ var LocalRelativeSidValueBlock = class extends HexBlock(LocalBaseBlock) {
2690
+ constructor({ valueDec = 0, ...parameters } = {}) {
2691
+ super(parameters);
2692
+ this.valueDec = valueDec;
2693
+ }
2694
+ fromBER(inputBuffer, inputOffset, inputLength) {
2695
+ if (inputLength === 0)
2696
+ return inputOffset;
2697
+ const inputView = BufferSourceConverter.toUint8Array(inputBuffer);
2698
+ if (!checkBufferParams(this, inputView, inputOffset, inputLength))
2699
+ return -1;
2700
+ const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength);
2701
+ this.valueHexView = new Uint8Array(inputLength);
2702
+ for (let i = 0; i < inputLength; i++) {
2703
+ this.valueHexView[i] = intBuffer[i] & 127;
2704
+ this.blockLength++;
2705
+ if ((intBuffer[i] & 128) === 0)
2706
+ break;
2707
+ }
2708
+ const tempView = new Uint8Array(this.blockLength);
2709
+ for (let i = 0; i < this.blockLength; i++)
2710
+ tempView[i] = this.valueHexView[i];
2711
+ this.valueHexView = tempView;
2712
+ if ((intBuffer[this.blockLength - 1] & 128) !== 0) {
2713
+ this.error = "End of input reached before message was fully decoded";
2714
+ return -1;
2715
+ }
2716
+ if (this.valueHexView[0] === 0)
2717
+ this.warnings.push("Needlessly long format of SID encoding");
2718
+ if (this.blockLength <= 8)
2719
+ this.valueDec = utilFromBase(this.valueHexView, 7);
2720
+ else {
2721
+ this.isHexOnly = true;
2722
+ this.warnings.push("Too big SID for decoding, hex only");
2723
+ }
2724
+ return inputOffset + this.blockLength;
2725
+ }
2726
+ toBER(sizeOnly) {
2727
+ if (this.isHexOnly) {
2728
+ if (sizeOnly)
2729
+ return new ArrayBuffer(this.valueHexView.byteLength);
2730
+ const curView = this.valueHexView;
2731
+ const retView2 = new Uint8Array(this.blockLength);
2732
+ for (let i = 0; i < this.blockLength - 1; i++)
2733
+ retView2[i] = curView[i] | 128;
2734
+ retView2[this.blockLength - 1] = curView[this.blockLength - 1];
2735
+ return retView2.buffer;
2736
+ }
2737
+ const encodedBuf = utilToBase(this.valueDec, 7);
2738
+ if (encodedBuf.byteLength === 0) {
2739
+ this.error = "Error during encoding SID value";
2740
+ return EMPTY_BUFFER;
2741
+ }
2742
+ const retView = new Uint8Array(encodedBuf.byteLength);
2743
+ if (!sizeOnly) {
2744
+ const encodedView = new Uint8Array(encodedBuf);
2745
+ const len = encodedBuf.byteLength - 1;
2746
+ for (let i = 0; i < len; i++)
2747
+ retView[i] = encodedView[i] | 128;
2748
+ retView[len] = encodedView[len];
2749
+ }
2750
+ return retView.buffer;
2751
+ }
2752
+ toString() {
2753
+ let result = "";
2754
+ if (this.isHexOnly)
2755
+ result = Convert.ToHex(this.valueHexView);
2756
+ else {
2757
+ result = this.valueDec.toString();
2758
+ }
2759
+ return result;
2760
+ }
2761
+ toJSON() {
2762
+ return {
2763
+ ...super.toJSON(),
2764
+ valueDec: this.valueDec
2765
+ };
2766
+ }
2767
+ };
2768
+ LocalRelativeSidValueBlock.NAME = "relativeSidBlock";
2769
+ var LocalRelativeObjectIdentifierValueBlock = class extends ValueBlock {
2770
+ constructor({ value = EMPTY_STRING, ...parameters } = {}) {
2771
+ super(parameters);
2772
+ this.value = [];
2773
+ if (value) {
2774
+ this.fromString(value);
2775
+ }
2776
+ }
2777
+ fromBER(inputBuffer, inputOffset, inputLength) {
2778
+ let resultOffset = inputOffset;
2779
+ while (inputLength > 0) {
2780
+ const sidBlock = new LocalRelativeSidValueBlock();
2781
+ resultOffset = sidBlock.fromBER(inputBuffer, resultOffset, inputLength);
2782
+ if (resultOffset === -1) {
2783
+ this.blockLength = 0;
2784
+ this.error = sidBlock.error;
2785
+ return resultOffset;
2786
+ }
2787
+ this.blockLength += sidBlock.blockLength;
2788
+ inputLength -= sidBlock.blockLength;
2789
+ this.value.push(sidBlock);
2790
+ }
2791
+ return resultOffset;
2792
+ }
2793
+ toBER(sizeOnly, writer) {
2794
+ const retBuffers = [];
2795
+ for (let i = 0; i < this.value.length; i++) {
2796
+ const valueBuf = this.value[i].toBER(sizeOnly);
2797
+ if (valueBuf.byteLength === 0) {
2798
+ this.error = this.value[i].error;
2799
+ return EMPTY_BUFFER;
2800
+ }
2801
+ retBuffers.push(valueBuf);
2802
+ }
2803
+ return concat(retBuffers);
2804
+ }
2805
+ fromString(string) {
2806
+ this.value = [];
2807
+ let pos1 = 0;
2808
+ let pos2 = 0;
2809
+ let sid = "";
2810
+ do {
2811
+ pos2 = string.indexOf(".", pos1);
2812
+ if (pos2 === -1)
2813
+ sid = string.substring(pos1);
2814
+ else
2815
+ sid = string.substring(pos1, pos2);
2816
+ pos1 = pos2 + 1;
2817
+ const sidBlock = new LocalRelativeSidValueBlock();
2818
+ sidBlock.valueDec = parseInt(sid, 10);
2819
+ if (isNaN(sidBlock.valueDec))
2820
+ return true;
2821
+ this.value.push(sidBlock);
2822
+ } while (pos2 !== -1);
2823
+ return true;
2824
+ }
2825
+ toString() {
2826
+ let result = "";
2827
+ let isHexOnly = false;
2828
+ for (let i = 0; i < this.value.length; i++) {
2829
+ isHexOnly = this.value[i].isHexOnly;
2830
+ let sidStr = this.value[i].toString();
2831
+ if (i !== 0)
2832
+ result = `${result}.`;
2833
+ if (isHexOnly) {
2834
+ sidStr = `{${sidStr}}`;
2835
+ result += sidStr;
2836
+ } else
2837
+ result += sidStr;
2838
+ }
2839
+ return result;
2840
+ }
2841
+ toJSON() {
2842
+ const object = {
2843
+ ...super.toJSON(),
2844
+ value: this.toString(),
2845
+ sidArray: []
2846
+ };
2847
+ for (let i = 0; i < this.value.length; i++)
2848
+ object.sidArray.push(this.value[i].toJSON());
2849
+ return object;
2850
+ }
2851
+ };
2852
+ LocalRelativeObjectIdentifierValueBlock.NAME = "RelativeObjectIdentifierValueBlock";
2853
+ var _a$l;
2854
+ var RelativeObjectIdentifier = class extends BaseBlock {
2855
+ constructor(parameters = {}) {
2856
+ super(parameters, LocalRelativeObjectIdentifierValueBlock);
2857
+ this.idBlock.tagClass = 1;
2858
+ this.idBlock.tagNumber = 13;
2859
+ }
2860
+ getValue() {
2861
+ return this.valueBlock.toString();
2862
+ }
2863
+ setValue(value) {
2864
+ this.valueBlock.fromString(value);
2865
+ }
2866
+ onAsciiEncoding() {
2867
+ return `${this.constructor.NAME} : ${this.valueBlock.toString() || "empty"}`;
2868
+ }
2869
+ toJSON() {
2870
+ return {
2871
+ ...super.toJSON(),
2872
+ value: this.getValue()
2873
+ };
2874
+ }
2875
+ };
2876
+ _a$l = RelativeObjectIdentifier;
2877
+ (() => {
2878
+ typeStore.RelativeObjectIdentifier = _a$l;
2879
+ })();
2880
+ RelativeObjectIdentifier.NAME = "RelativeObjectIdentifier";
2881
+ var _a$k;
2882
+ var Sequence = class extends Constructed {
2883
+ constructor(parameters = {}) {
2884
+ super(parameters);
2885
+ this.idBlock.tagClass = 1;
2886
+ this.idBlock.tagNumber = 16;
2887
+ }
2888
+ };
2889
+ _a$k = Sequence;
2890
+ (() => {
2891
+ typeStore.Sequence = _a$k;
2892
+ })();
2893
+ Sequence.NAME = "SEQUENCE";
2894
+ var _a$j;
2895
+ var Set = class extends Constructed {
2896
+ constructor(parameters = {}) {
2897
+ super(parameters);
2898
+ this.idBlock.tagClass = 1;
2899
+ this.idBlock.tagNumber = 17;
2900
+ }
2901
+ };
2902
+ _a$j = Set;
2903
+ (() => {
2904
+ typeStore.Set = _a$j;
2905
+ })();
2906
+ Set.NAME = "SET";
2907
+ var LocalStringValueBlock = class extends HexBlock(ValueBlock) {
2908
+ constructor({ ...parameters } = {}) {
2909
+ super(parameters);
2910
+ this.isHexOnly = true;
2911
+ this.value = EMPTY_STRING;
2912
+ }
2913
+ toJSON() {
2914
+ return {
2915
+ ...super.toJSON(),
2916
+ value: this.value
2917
+ };
2918
+ }
2919
+ };
2920
+ LocalStringValueBlock.NAME = "StringValueBlock";
2921
+ var LocalSimpleStringValueBlock = class extends LocalStringValueBlock {
2922
+ };
2923
+ LocalSimpleStringValueBlock.NAME = "SimpleStringValueBlock";
2924
+ var LocalSimpleStringBlock = class extends BaseStringBlock {
2925
+ constructor({ ...parameters } = {}) {
2926
+ super(parameters, LocalSimpleStringValueBlock);
2927
+ }
2928
+ fromBuffer(inputBuffer) {
2929
+ this.valueBlock.value = String.fromCharCode.apply(null, BufferSourceConverter.toUint8Array(inputBuffer));
2930
+ }
2931
+ fromString(inputString) {
2932
+ const strLen = inputString.length;
2933
+ const view = this.valueBlock.valueHexView = new Uint8Array(strLen);
2934
+ for (let i = 0; i < strLen; i++)
2935
+ view[i] = inputString.charCodeAt(i);
2936
+ this.valueBlock.value = inputString;
2937
+ }
2938
+ };
2939
+ LocalSimpleStringBlock.NAME = "SIMPLE STRING";
2940
+ var LocalUtf8StringValueBlock = class extends LocalSimpleStringBlock {
2941
+ fromBuffer(inputBuffer) {
2942
+ this.valueBlock.valueHexView = BufferSourceConverter.toUint8Array(inputBuffer);
2943
+ try {
2944
+ this.valueBlock.value = Convert.ToUtf8String(inputBuffer);
2945
+ } catch (ex) {
2946
+ this.warnings.push(`Error during "decodeURIComponent": ${ex}, using raw string`);
2947
+ this.valueBlock.value = Convert.ToBinary(inputBuffer);
2948
+ }
2949
+ }
2950
+ fromString(inputString) {
2951
+ this.valueBlock.valueHexView = new Uint8Array(Convert.FromUtf8String(inputString));
2952
+ this.valueBlock.value = inputString;
2953
+ }
2954
+ };
2955
+ LocalUtf8StringValueBlock.NAME = "Utf8StringValueBlock";
2956
+ var _a$i;
2957
+ var Utf8String = class extends LocalUtf8StringValueBlock {
2958
+ constructor(parameters = {}) {
2959
+ super(parameters);
2960
+ this.idBlock.tagClass = 1;
2961
+ this.idBlock.tagNumber = 12;
2962
+ }
2963
+ };
2964
+ _a$i = Utf8String;
2965
+ (() => {
2966
+ typeStore.Utf8String = _a$i;
2967
+ })();
2968
+ Utf8String.NAME = "UTF8String";
2969
+ var LocalBmpStringValueBlock = class extends LocalSimpleStringBlock {
2970
+ fromBuffer(inputBuffer) {
2971
+ this.valueBlock.value = Convert.ToUtf16String(inputBuffer);
2972
+ this.valueBlock.valueHexView = BufferSourceConverter.toUint8Array(inputBuffer);
2973
+ }
2974
+ fromString(inputString) {
2975
+ this.valueBlock.value = inputString;
2976
+ this.valueBlock.valueHexView = new Uint8Array(Convert.FromUtf16String(inputString));
2977
+ }
2978
+ };
2979
+ LocalBmpStringValueBlock.NAME = "BmpStringValueBlock";
2980
+ var _a$h;
2981
+ var BmpString = class extends LocalBmpStringValueBlock {
2982
+ constructor({ ...parameters } = {}) {
2983
+ super(parameters);
2984
+ this.idBlock.tagClass = 1;
2985
+ this.idBlock.tagNumber = 30;
2986
+ }
2987
+ };
2988
+ _a$h = BmpString;
2989
+ (() => {
2990
+ typeStore.BmpString = _a$h;
2991
+ })();
2992
+ BmpString.NAME = "BMPString";
2993
+ var LocalUniversalStringValueBlock = class extends LocalSimpleStringBlock {
2994
+ fromBuffer(inputBuffer) {
2995
+ const copyBuffer = ArrayBuffer.isView(inputBuffer) ? inputBuffer.slice().buffer : inputBuffer.slice(0);
2996
+ const valueView = new Uint8Array(copyBuffer);
2997
+ for (let i = 0; i < valueView.length; i += 4) {
2998
+ valueView[i] = valueView[i + 3];
2999
+ valueView[i + 1] = valueView[i + 2];
3000
+ valueView[i + 2] = 0;
3001
+ valueView[i + 3] = 0;
3002
+ }
3003
+ this.valueBlock.value = String.fromCharCode.apply(null, new Uint32Array(copyBuffer));
3004
+ }
3005
+ fromString(inputString) {
3006
+ const strLength = inputString.length;
3007
+ const valueHexView = this.valueBlock.valueHexView = new Uint8Array(strLength * 4);
3008
+ for (let i = 0; i < strLength; i++) {
3009
+ const codeBuf = utilToBase(inputString.charCodeAt(i), 8);
3010
+ const codeView = new Uint8Array(codeBuf);
3011
+ if (codeView.length > 4)
3012
+ continue;
3013
+ const dif = 4 - codeView.length;
3014
+ for (let j = codeView.length - 1; j >= 0; j--)
3015
+ valueHexView[i * 4 + j + dif] = codeView[j];
3016
+ }
3017
+ this.valueBlock.value = inputString;
3018
+ }
3019
+ };
3020
+ LocalUniversalStringValueBlock.NAME = "UniversalStringValueBlock";
3021
+ var _a$g;
3022
+ var UniversalString = class extends LocalUniversalStringValueBlock {
3023
+ constructor({ ...parameters } = {}) {
3024
+ super(parameters);
3025
+ this.idBlock.tagClass = 1;
3026
+ this.idBlock.tagNumber = 28;
3027
+ }
3028
+ };
3029
+ _a$g = UniversalString;
3030
+ (() => {
3031
+ typeStore.UniversalString = _a$g;
3032
+ })();
3033
+ UniversalString.NAME = "UniversalString";
3034
+ var _a$f;
3035
+ var NumericString = class extends LocalSimpleStringBlock {
3036
+ constructor(parameters = {}) {
3037
+ super(parameters);
3038
+ this.idBlock.tagClass = 1;
3039
+ this.idBlock.tagNumber = 18;
3040
+ }
3041
+ };
3042
+ _a$f = NumericString;
3043
+ (() => {
3044
+ typeStore.NumericString = _a$f;
3045
+ })();
3046
+ NumericString.NAME = "NumericString";
3047
+ var _a$e;
3048
+ var PrintableString = class extends LocalSimpleStringBlock {
3049
+ constructor(parameters = {}) {
3050
+ super(parameters);
3051
+ this.idBlock.tagClass = 1;
3052
+ this.idBlock.tagNumber = 19;
3053
+ }
3054
+ };
3055
+ _a$e = PrintableString;
3056
+ (() => {
3057
+ typeStore.PrintableString = _a$e;
3058
+ })();
3059
+ PrintableString.NAME = "PrintableString";
3060
+ var _a$d;
3061
+ var TeletexString = class extends LocalSimpleStringBlock {
3062
+ constructor(parameters = {}) {
3063
+ super(parameters);
3064
+ this.idBlock.tagClass = 1;
3065
+ this.idBlock.tagNumber = 20;
3066
+ }
3067
+ };
3068
+ _a$d = TeletexString;
3069
+ (() => {
3070
+ typeStore.TeletexString = _a$d;
3071
+ })();
3072
+ TeletexString.NAME = "TeletexString";
3073
+ var _a$c;
3074
+ var VideotexString = class extends LocalSimpleStringBlock {
3075
+ constructor(parameters = {}) {
3076
+ super(parameters);
3077
+ this.idBlock.tagClass = 1;
3078
+ this.idBlock.tagNumber = 21;
3079
+ }
3080
+ };
3081
+ _a$c = VideotexString;
3082
+ (() => {
3083
+ typeStore.VideotexString = _a$c;
3084
+ })();
3085
+ VideotexString.NAME = "VideotexString";
3086
+ var _a$b;
3087
+ var IA5String = class extends LocalSimpleStringBlock {
3088
+ constructor(parameters = {}) {
3089
+ super(parameters);
3090
+ this.idBlock.tagClass = 1;
3091
+ this.idBlock.tagNumber = 22;
3092
+ }
3093
+ };
3094
+ _a$b = IA5String;
3095
+ (() => {
3096
+ typeStore.IA5String = _a$b;
3097
+ })();
3098
+ IA5String.NAME = "IA5String";
3099
+ var _a$a;
3100
+ var GraphicString = class extends LocalSimpleStringBlock {
3101
+ constructor(parameters = {}) {
3102
+ super(parameters);
3103
+ this.idBlock.tagClass = 1;
3104
+ this.idBlock.tagNumber = 25;
3105
+ }
3106
+ };
3107
+ _a$a = GraphicString;
3108
+ (() => {
3109
+ typeStore.GraphicString = _a$a;
3110
+ })();
3111
+ GraphicString.NAME = "GraphicString";
3112
+ var _a$9;
3113
+ var VisibleString = class extends LocalSimpleStringBlock {
3114
+ constructor(parameters = {}) {
3115
+ super(parameters);
3116
+ this.idBlock.tagClass = 1;
3117
+ this.idBlock.tagNumber = 26;
3118
+ }
3119
+ };
3120
+ _a$9 = VisibleString;
3121
+ (() => {
3122
+ typeStore.VisibleString = _a$9;
3123
+ })();
3124
+ VisibleString.NAME = "VisibleString";
3125
+ var _a$8;
3126
+ var GeneralString = class extends LocalSimpleStringBlock {
3127
+ constructor(parameters = {}) {
3128
+ super(parameters);
3129
+ this.idBlock.tagClass = 1;
3130
+ this.idBlock.tagNumber = 27;
3131
+ }
3132
+ };
3133
+ _a$8 = GeneralString;
3134
+ (() => {
3135
+ typeStore.GeneralString = _a$8;
3136
+ })();
3137
+ GeneralString.NAME = "GeneralString";
3138
+ var _a$7;
3139
+ var CharacterString = class extends LocalSimpleStringBlock {
3140
+ constructor(parameters = {}) {
3141
+ super(parameters);
3142
+ this.idBlock.tagClass = 1;
3143
+ this.idBlock.tagNumber = 29;
3144
+ }
3145
+ };
3146
+ _a$7 = CharacterString;
3147
+ (() => {
3148
+ typeStore.CharacterString = _a$7;
3149
+ })();
3150
+ CharacterString.NAME = "CharacterString";
3151
+ var _a$6;
3152
+ var UTCTime = class extends VisibleString {
3153
+ constructor({ value, valueDate, ...parameters } = {}) {
3154
+ super(parameters);
3155
+ this.year = 0;
3156
+ this.month = 0;
3157
+ this.day = 0;
3158
+ this.hour = 0;
3159
+ this.minute = 0;
3160
+ this.second = 0;
3161
+ if (value) {
3162
+ this.fromString(value);
3163
+ this.valueBlock.valueHexView = new Uint8Array(value.length);
3164
+ for (let i = 0; i < value.length; i++)
3165
+ this.valueBlock.valueHexView[i] = value.charCodeAt(i);
3166
+ }
3167
+ if (valueDate) {
3168
+ this.fromDate(valueDate);
3169
+ this.valueBlock.valueHexView = new Uint8Array(this.toBuffer());
3170
+ }
3171
+ this.idBlock.tagClass = 1;
3172
+ this.idBlock.tagNumber = 23;
3173
+ }
3174
+ fromBuffer(inputBuffer) {
3175
+ this.fromString(String.fromCharCode.apply(null, BufferSourceConverter.toUint8Array(inputBuffer)));
3176
+ }
3177
+ toBuffer() {
3178
+ const str = this.toString();
3179
+ const buffer = new ArrayBuffer(str.length);
3180
+ const view = new Uint8Array(buffer);
3181
+ for (let i = 0; i < str.length; i++)
3182
+ view[i] = str.charCodeAt(i);
3183
+ return buffer;
3184
+ }
3185
+ fromDate(inputDate) {
3186
+ this.year = inputDate.getUTCFullYear();
3187
+ this.month = inputDate.getUTCMonth() + 1;
3188
+ this.day = inputDate.getUTCDate();
3189
+ this.hour = inputDate.getUTCHours();
3190
+ this.minute = inputDate.getUTCMinutes();
3191
+ this.second = inputDate.getUTCSeconds();
3192
+ }
3193
+ toDate() {
3194
+ return new Date(Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minute, this.second));
3195
+ }
3196
+ fromString(inputString) {
3197
+ const parser = /(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig;
3198
+ const parserArray = parser.exec(inputString);
3199
+ if (parserArray === null) {
3200
+ this.error = "Wrong input string for conversion";
3201
+ return;
3202
+ }
3203
+ const year = parseInt(parserArray[1], 10);
3204
+ if (year >= 50)
3205
+ this.year = 1900 + year;
3206
+ else
3207
+ this.year = 2e3 + year;
3208
+ this.month = parseInt(parserArray[2], 10);
3209
+ this.day = parseInt(parserArray[3], 10);
3210
+ this.hour = parseInt(parserArray[4], 10);
3211
+ this.minute = parseInt(parserArray[5], 10);
3212
+ this.second = parseInt(parserArray[6], 10);
3213
+ }
3214
+ toString(encoding = "iso") {
3215
+ if (encoding === "iso") {
3216
+ const outputArray = new Array(7);
3217
+ outputArray[0] = padNumber(this.year < 2e3 ? this.year - 1900 : this.year - 2e3, 2);
3218
+ outputArray[1] = padNumber(this.month, 2);
3219
+ outputArray[2] = padNumber(this.day, 2);
3220
+ outputArray[3] = padNumber(this.hour, 2);
3221
+ outputArray[4] = padNumber(this.minute, 2);
3222
+ outputArray[5] = padNumber(this.second, 2);
3223
+ outputArray[6] = "Z";
3224
+ return outputArray.join("");
3225
+ }
3226
+ return super.toString(encoding);
3227
+ }
3228
+ onAsciiEncoding() {
3229
+ return `${this.constructor.NAME} : ${this.toDate().toISOString()}`;
3230
+ }
3231
+ toJSON() {
3232
+ return {
3233
+ ...super.toJSON(),
3234
+ year: this.year,
3235
+ month: this.month,
3236
+ day: this.day,
3237
+ hour: this.hour,
3238
+ minute: this.minute,
3239
+ second: this.second
3240
+ };
3241
+ }
3242
+ };
3243
+ _a$6 = UTCTime;
3244
+ (() => {
3245
+ typeStore.UTCTime = _a$6;
3246
+ })();
3247
+ UTCTime.NAME = "UTCTime";
3248
+ var _a$5;
3249
+ var GeneralizedTime = class extends UTCTime {
3250
+ constructor(parameters = {}) {
3251
+ var _b;
3252
+ super(parameters);
3253
+ (_b = this.millisecond) !== null && _b !== void 0 ? _b : this.millisecond = 0;
3254
+ this.idBlock.tagClass = 1;
3255
+ this.idBlock.tagNumber = 24;
3256
+ }
3257
+ fromDate(inputDate) {
3258
+ super.fromDate(inputDate);
3259
+ this.millisecond = inputDate.getUTCMilliseconds();
3260
+ }
3261
+ toDate() {
3262
+ return new Date(Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minute, this.second, this.millisecond));
3263
+ }
3264
+ fromString(inputString) {
3265
+ let isUTC = false;
3266
+ let timeString = "";
3267
+ let dateTimeString = "";
3268
+ let fractionPart = 0;
3269
+ let parser;
3270
+ let hourDifference = 0;
3271
+ let minuteDifference = 0;
3272
+ if (inputString[inputString.length - 1] === "Z") {
3273
+ timeString = inputString.substring(0, inputString.length - 1);
3274
+ isUTC = true;
3275
+ } else {
3276
+ const number = new Number(inputString[inputString.length - 1]);
3277
+ if (isNaN(number.valueOf()))
3278
+ throw new Error("Wrong input string for conversion");
3279
+ timeString = inputString;
3280
+ }
3281
+ if (isUTC) {
3282
+ if (timeString.indexOf("+") !== -1)
3283
+ throw new Error("Wrong input string for conversion");
3284
+ if (timeString.indexOf("-") !== -1)
3285
+ throw new Error("Wrong input string for conversion");
3286
+ } else {
3287
+ let multiplier = 1;
3288
+ let differencePosition = timeString.indexOf("+");
3289
+ let differenceString = "";
3290
+ if (differencePosition === -1) {
3291
+ differencePosition = timeString.indexOf("-");
3292
+ multiplier = -1;
3293
+ }
3294
+ if (differencePosition !== -1) {
3295
+ differenceString = timeString.substring(differencePosition + 1);
3296
+ timeString = timeString.substring(0, differencePosition);
3297
+ if (differenceString.length !== 2 && differenceString.length !== 4)
3298
+ throw new Error("Wrong input string for conversion");
3299
+ let number = parseInt(differenceString.substring(0, 2), 10);
3300
+ if (isNaN(number.valueOf()))
3301
+ throw new Error("Wrong input string for conversion");
3302
+ hourDifference = multiplier * number;
3303
+ if (differenceString.length === 4) {
3304
+ number = parseInt(differenceString.substring(2, 4), 10);
3305
+ if (isNaN(number.valueOf()))
3306
+ throw new Error("Wrong input string for conversion");
3307
+ minuteDifference = multiplier * number;
3308
+ }
3309
+ }
3310
+ }
3311
+ let fractionPointPosition = timeString.indexOf(".");
3312
+ if (fractionPointPosition === -1)
3313
+ fractionPointPosition = timeString.indexOf(",");
3314
+ if (fractionPointPosition !== -1) {
3315
+ const fractionPartCheck = new Number(`0${timeString.substring(fractionPointPosition)}`);
3316
+ if (isNaN(fractionPartCheck.valueOf()))
3317
+ throw new Error("Wrong input string for conversion");
3318
+ fractionPart = fractionPartCheck.valueOf();
3319
+ dateTimeString = timeString.substring(0, fractionPointPosition);
3320
+ } else
3321
+ dateTimeString = timeString;
3322
+ switch (true) {
3323
+ case dateTimeString.length === 8:
3324
+ parser = /(\d{4})(\d{2})(\d{2})/ig;
3325
+ if (fractionPointPosition !== -1)
3326
+ throw new Error("Wrong input string for conversion");
3327
+ break;
3328
+ case dateTimeString.length === 10:
3329
+ parser = /(\d{4})(\d{2})(\d{2})(\d{2})/ig;
3330
+ if (fractionPointPosition !== -1) {
3331
+ let fractionResult = 60 * fractionPart;
3332
+ this.minute = Math.floor(fractionResult);
3333
+ fractionResult = 60 * (fractionResult - this.minute);
3334
+ this.second = Math.floor(fractionResult);
3335
+ fractionResult = 1e3 * (fractionResult - this.second);
3336
+ this.millisecond = Math.floor(fractionResult);
3337
+ }
3338
+ break;
3339
+ case dateTimeString.length === 12:
3340
+ parser = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig;
3341
+ if (fractionPointPosition !== -1) {
3342
+ let fractionResult = 60 * fractionPart;
3343
+ this.second = Math.floor(fractionResult);
3344
+ fractionResult = 1e3 * (fractionResult - this.second);
3345
+ this.millisecond = Math.floor(fractionResult);
3346
+ }
3347
+ break;
3348
+ case dateTimeString.length === 14:
3349
+ parser = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig;
3350
+ if (fractionPointPosition !== -1) {
3351
+ const fractionResult = 1e3 * fractionPart;
3352
+ this.millisecond = Math.floor(fractionResult);
3353
+ }
3354
+ break;
3355
+ default:
3356
+ throw new Error("Wrong input string for conversion");
3357
+ }
3358
+ const parserArray = parser.exec(dateTimeString);
3359
+ if (parserArray === null)
3360
+ throw new Error("Wrong input string for conversion");
3361
+ for (let j = 1; j < parserArray.length; j++) {
3362
+ switch (j) {
3363
+ case 1:
3364
+ this.year = parseInt(parserArray[j], 10);
3365
+ break;
3366
+ case 2:
3367
+ this.month = parseInt(parserArray[j], 10);
3368
+ break;
3369
+ case 3:
3370
+ this.day = parseInt(parserArray[j], 10);
3371
+ break;
3372
+ case 4:
3373
+ this.hour = parseInt(parserArray[j], 10) + hourDifference;
3374
+ break;
3375
+ case 5:
3376
+ this.minute = parseInt(parserArray[j], 10) + minuteDifference;
3377
+ break;
3378
+ case 6:
3379
+ this.second = parseInt(parserArray[j], 10);
3380
+ break;
3381
+ default:
3382
+ throw new Error("Wrong input string for conversion");
3383
+ }
3384
+ }
3385
+ if (isUTC === false) {
3386
+ const tempDate = new Date(this.year, this.month, this.day, this.hour, this.minute, this.second, this.millisecond);
3387
+ this.year = tempDate.getUTCFullYear();
3388
+ this.month = tempDate.getUTCMonth();
3389
+ this.day = tempDate.getUTCDay();
3390
+ this.hour = tempDate.getUTCHours();
3391
+ this.minute = tempDate.getUTCMinutes();
3392
+ this.second = tempDate.getUTCSeconds();
3393
+ this.millisecond = tempDate.getUTCMilliseconds();
3394
+ }
3395
+ }
3396
+ toString(encoding = "iso") {
3397
+ if (encoding === "iso") {
3398
+ const outputArray = [];
3399
+ outputArray.push(padNumber(this.year, 4));
3400
+ outputArray.push(padNumber(this.month, 2));
3401
+ outputArray.push(padNumber(this.day, 2));
3402
+ outputArray.push(padNumber(this.hour, 2));
3403
+ outputArray.push(padNumber(this.minute, 2));
3404
+ outputArray.push(padNumber(this.second, 2));
3405
+ if (this.millisecond !== 0) {
3406
+ outputArray.push(".");
3407
+ outputArray.push(padNumber(this.millisecond, 3));
3408
+ }
3409
+ outputArray.push("Z");
3410
+ return outputArray.join("");
3411
+ }
3412
+ return super.toString(encoding);
3413
+ }
3414
+ toJSON() {
3415
+ return {
3416
+ ...super.toJSON(),
3417
+ millisecond: this.millisecond
3418
+ };
3419
+ }
3420
+ };
3421
+ _a$5 = GeneralizedTime;
3422
+ (() => {
3423
+ typeStore.GeneralizedTime = _a$5;
3424
+ })();
3425
+ GeneralizedTime.NAME = "GeneralizedTime";
3426
+ var _a$4;
3427
+ var DATE = class extends Utf8String {
3428
+ constructor(parameters = {}) {
3429
+ super(parameters);
3430
+ this.idBlock.tagClass = 1;
3431
+ this.idBlock.tagNumber = 31;
3432
+ }
3433
+ };
3434
+ _a$4 = DATE;
3435
+ (() => {
3436
+ typeStore.DATE = _a$4;
3437
+ })();
3438
+ DATE.NAME = "DATE";
3439
+ var _a$3;
3440
+ var TimeOfDay = class extends Utf8String {
3441
+ constructor(parameters = {}) {
3442
+ super(parameters);
3443
+ this.idBlock.tagClass = 1;
3444
+ this.idBlock.tagNumber = 32;
3445
+ }
3446
+ };
3447
+ _a$3 = TimeOfDay;
3448
+ (() => {
3449
+ typeStore.TimeOfDay = _a$3;
3450
+ })();
3451
+ TimeOfDay.NAME = "TimeOfDay";
3452
+ var _a$2;
3453
+ var DateTime = class extends Utf8String {
3454
+ constructor(parameters = {}) {
3455
+ super(parameters);
3456
+ this.idBlock.tagClass = 1;
3457
+ this.idBlock.tagNumber = 33;
3458
+ }
3459
+ };
3460
+ _a$2 = DateTime;
3461
+ (() => {
3462
+ typeStore.DateTime = _a$2;
3463
+ })();
3464
+ DateTime.NAME = "DateTime";
3465
+ var _a$1;
3466
+ var Duration = class extends Utf8String {
3467
+ constructor(parameters = {}) {
3468
+ super(parameters);
3469
+ this.idBlock.tagClass = 1;
3470
+ this.idBlock.tagNumber = 34;
3471
+ }
3472
+ };
3473
+ _a$1 = Duration;
3474
+ (() => {
3475
+ typeStore.Duration = _a$1;
3476
+ })();
3477
+ Duration.NAME = "Duration";
3478
+ var _a;
3479
+ var TIME = class extends Utf8String {
3480
+ constructor(parameters = {}) {
3481
+ super(parameters);
3482
+ this.idBlock.tagClass = 1;
3483
+ this.idBlock.tagNumber = 14;
3484
+ }
3485
+ };
3486
+ _a = TIME;
3487
+ (() => {
3488
+ typeStore.TIME = _a;
3489
+ })();
3490
+ TIME.NAME = "TIME";
3491
+ var Any = class {
3492
+ constructor({ name = EMPTY_STRING, optional = false } = {}) {
3493
+ this.name = name;
3494
+ this.optional = optional;
3495
+ }
3496
+ };
3497
+ var Choice = class extends Any {
3498
+ constructor({ value = [], ...parameters } = {}) {
3499
+ super(parameters);
3500
+ this.value = value;
3501
+ }
3502
+ };
3503
+ var Repeated = class extends Any {
3504
+ constructor({ value = new Any(), local = false, ...parameters } = {}) {
3505
+ super(parameters);
3506
+ this.value = value;
3507
+ this.local = local;
3508
+ }
3509
+ };
3510
+ var RawData = class {
3511
+ constructor({ data = EMPTY_VIEW } = {}) {
3512
+ this.dataView = BufferSourceConverter.toUint8Array(data);
3513
+ }
3514
+ get data() {
3515
+ return this.dataView.slice().buffer;
3516
+ }
3517
+ set data(value) {
3518
+ this.dataView = BufferSourceConverter.toUint8Array(value);
3519
+ }
3520
+ fromBER(inputBuffer, inputOffset, inputLength) {
3521
+ const endLength = inputOffset + inputLength;
3522
+ this.dataView = BufferSourceConverter.toUint8Array(inputBuffer).subarray(inputOffset, endLength);
3523
+ return endLength;
3524
+ }
3525
+ toBER(sizeOnly) {
3526
+ return this.dataView.slice().buffer;
3527
+ }
3528
+ };
3529
+ function compareSchema(root, inputData, inputSchema) {
3530
+ if (inputSchema instanceof Choice) {
3531
+ for (let j = 0; j < inputSchema.value.length; j++) {
3532
+ const result = compareSchema(root, inputData, inputSchema.value[j]);
3533
+ if (result.verified) {
3534
+ return {
3535
+ verified: true,
3536
+ result: root
3537
+ };
3538
+ }
3539
+ }
3540
+ {
3541
+ const _result = {
3542
+ verified: false,
3543
+ result: {
3544
+ error: "Wrong values for Choice type"
3545
+ }
3546
+ };
3547
+ if (inputSchema.hasOwnProperty(NAME))
3548
+ _result.name = inputSchema.name;
3549
+ return _result;
3550
+ }
3551
+ }
3552
+ if (inputSchema instanceof Any) {
3553
+ if (inputSchema.hasOwnProperty(NAME))
3554
+ root[inputSchema.name] = inputData;
3555
+ return {
3556
+ verified: true,
3557
+ result: root
3558
+ };
3559
+ }
3560
+ if (root instanceof Object === false) {
3561
+ return {
3562
+ verified: false,
3563
+ result: { error: "Wrong root object" }
3564
+ };
3565
+ }
3566
+ if (inputData instanceof Object === false) {
3567
+ return {
3568
+ verified: false,
3569
+ result: { error: "Wrong ASN.1 data" }
3570
+ };
3571
+ }
3572
+ if (inputSchema instanceof Object === false) {
3573
+ return {
3574
+ verified: false,
3575
+ result: { error: "Wrong ASN.1 schema" }
3576
+ };
3577
+ }
3578
+ if (ID_BLOCK in inputSchema === false) {
3579
+ return {
3580
+ verified: false,
3581
+ result: { error: "Wrong ASN.1 schema" }
3582
+ };
3583
+ }
3584
+ if (FROM_BER in inputSchema.idBlock === false) {
3585
+ return {
3586
+ verified: false,
3587
+ result: { error: "Wrong ASN.1 schema" }
3588
+ };
3589
+ }
3590
+ if (TO_BER in inputSchema.idBlock === false) {
3591
+ return {
3592
+ verified: false,
3593
+ result: { error: "Wrong ASN.1 schema" }
3594
+ };
3595
+ }
3596
+ const encodedId = inputSchema.idBlock.toBER(false);
3597
+ if (encodedId.byteLength === 0) {
3598
+ return {
3599
+ verified: false,
3600
+ result: { error: "Error encoding idBlock for ASN.1 schema" }
3601
+ };
3602
+ }
3603
+ const decodedOffset = inputSchema.idBlock.fromBER(encodedId, 0, encodedId.byteLength);
3604
+ if (decodedOffset === -1) {
3605
+ return {
3606
+ verified: false,
3607
+ result: { error: "Error decoding idBlock for ASN.1 schema" }
3608
+ };
3609
+ }
3610
+ if (inputSchema.idBlock.hasOwnProperty(TAG_CLASS) === false) {
3611
+ return {
3612
+ verified: false,
3613
+ result: { error: "Wrong ASN.1 schema" }
3614
+ };
3615
+ }
3616
+ if (inputSchema.idBlock.tagClass !== inputData.idBlock.tagClass) {
3617
+ return {
3618
+ verified: false,
3619
+ result: root
3620
+ };
3621
+ }
3622
+ if (inputSchema.idBlock.hasOwnProperty(TAG_NUMBER) === false) {
3623
+ return {
3624
+ verified: false,
3625
+ result: { error: "Wrong ASN.1 schema" }
3626
+ };
3627
+ }
3628
+ if (inputSchema.idBlock.tagNumber !== inputData.idBlock.tagNumber) {
3629
+ return {
3630
+ verified: false,
3631
+ result: root
3632
+ };
3633
+ }
3634
+ if (inputSchema.idBlock.hasOwnProperty(IS_CONSTRUCTED) === false) {
3635
+ return {
3636
+ verified: false,
3637
+ result: { error: "Wrong ASN.1 schema" }
3638
+ };
3639
+ }
3640
+ if (inputSchema.idBlock.isConstructed !== inputData.idBlock.isConstructed) {
3641
+ return {
3642
+ verified: false,
3643
+ result: root
3644
+ };
3645
+ }
3646
+ if (!(IS_HEX_ONLY in inputSchema.idBlock)) {
3647
+ return {
3648
+ verified: false,
3649
+ result: { error: "Wrong ASN.1 schema" }
3650
+ };
3651
+ }
3652
+ if (inputSchema.idBlock.isHexOnly !== inputData.idBlock.isHexOnly) {
3653
+ return {
3654
+ verified: false,
3655
+ result: root
3656
+ };
3657
+ }
3658
+ if (inputSchema.idBlock.isHexOnly) {
3659
+ if (VALUE_HEX_VIEW in inputSchema.idBlock === false) {
3660
+ return {
3661
+ verified: false,
3662
+ result: { error: "Wrong ASN.1 schema" }
3663
+ };
3664
+ }
3665
+ const schemaView = inputSchema.idBlock.valueHexView;
3666
+ const asn1View = inputData.idBlock.valueHexView;
3667
+ if (schemaView.length !== asn1View.length) {
3668
+ return {
3669
+ verified: false,
3670
+ result: root
3671
+ };
3672
+ }
3673
+ for (let i = 0; i < schemaView.length; i++) {
3674
+ if (schemaView[i] !== asn1View[1]) {
3675
+ return {
3676
+ verified: false,
3677
+ result: root
3678
+ };
3679
+ }
3680
+ }
3681
+ }
3682
+ if (inputSchema.name) {
3683
+ inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
3684
+ if (inputSchema.name)
3685
+ root[inputSchema.name] = inputData;
3686
+ }
3687
+ if (inputSchema instanceof typeStore.Constructed) {
3688
+ let admission = 0;
3689
+ let result = {
3690
+ verified: false,
3691
+ result: {
3692
+ error: "Unknown error"
3693
+ }
3694
+ };
3695
+ let maxLength = inputSchema.valueBlock.value.length;
3696
+ if (maxLength > 0) {
3697
+ if (inputSchema.valueBlock.value[0] instanceof Repeated) {
3698
+ maxLength = inputData.valueBlock.value.length;
3699
+ }
3700
+ }
3701
+ if (maxLength === 0) {
3702
+ return {
3703
+ verified: true,
3704
+ result: root
3705
+ };
3706
+ }
3707
+ if (inputData.valueBlock.value.length === 0 && inputSchema.valueBlock.value.length !== 0) {
3708
+ let _optional = true;
3709
+ for (let i = 0; i < inputSchema.valueBlock.value.length; i++)
3710
+ _optional = _optional && (inputSchema.valueBlock.value[i].optional || false);
3711
+ if (_optional) {
3712
+ return {
3713
+ verified: true,
3714
+ result: root
3715
+ };
3716
+ }
3717
+ if (inputSchema.name) {
3718
+ inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
3719
+ if (inputSchema.name)
3720
+ delete root[inputSchema.name];
3721
+ }
3722
+ root.error = "Inconsistent object length";
3723
+ return {
3724
+ verified: false,
3725
+ result: root
3726
+ };
3727
+ }
3728
+ for (let i = 0; i < maxLength; i++) {
3729
+ if (i - admission >= inputData.valueBlock.value.length) {
3730
+ if (inputSchema.valueBlock.value[i].optional === false) {
3731
+ const _result = {
3732
+ verified: false,
3733
+ result: root
3734
+ };
3735
+ root.error = "Inconsistent length between ASN.1 data and schema";
3736
+ if (inputSchema.name) {
3737
+ inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
3738
+ if (inputSchema.name) {
3739
+ delete root[inputSchema.name];
3740
+ _result.name = inputSchema.name;
3741
+ }
3742
+ }
3743
+ return _result;
3744
+ }
3745
+ } else {
3746
+ if (inputSchema.valueBlock.value[0] instanceof Repeated) {
3747
+ result = compareSchema(root, inputData.valueBlock.value[i], inputSchema.valueBlock.value[0].value);
3748
+ if (result.verified === false) {
3749
+ if (inputSchema.valueBlock.value[0].optional)
3750
+ admission++;
3751
+ else {
3752
+ if (inputSchema.name) {
3753
+ inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
3754
+ if (inputSchema.name)
3755
+ delete root[inputSchema.name];
3756
+ }
3757
+ return result;
3758
+ }
3759
+ }
3760
+ if (NAME in inputSchema.valueBlock.value[0] && inputSchema.valueBlock.value[0].name.length > 0) {
3761
+ let arrayRoot = {};
3762
+ if (LOCAL in inputSchema.valueBlock.value[0] && inputSchema.valueBlock.value[0].local)
3763
+ arrayRoot = inputData;
3764
+ else
3765
+ arrayRoot = root;
3766
+ if (typeof arrayRoot[inputSchema.valueBlock.value[0].name] === "undefined")
3767
+ arrayRoot[inputSchema.valueBlock.value[0].name] = [];
3768
+ arrayRoot[inputSchema.valueBlock.value[0].name].push(inputData.valueBlock.value[i]);
3769
+ }
3770
+ } else {
3771
+ result = compareSchema(root, inputData.valueBlock.value[i - admission], inputSchema.valueBlock.value[i]);
3772
+ if (result.verified === false) {
3773
+ if (inputSchema.valueBlock.value[i].optional)
3774
+ admission++;
3775
+ else {
3776
+ if (inputSchema.name) {
3777
+ inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
3778
+ if (inputSchema.name)
3779
+ delete root[inputSchema.name];
3780
+ }
3781
+ return result;
3782
+ }
3783
+ }
3784
+ }
3785
+ }
3786
+ }
3787
+ if (result.verified === false) {
3788
+ const _result = {
3789
+ verified: false,
3790
+ result: root
3791
+ };
3792
+ if (inputSchema.name) {
3793
+ inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
3794
+ if (inputSchema.name) {
3795
+ delete root[inputSchema.name];
3796
+ _result.name = inputSchema.name;
3797
+ }
3798
+ }
3799
+ return _result;
3800
+ }
3801
+ return {
3802
+ verified: true,
3803
+ result: root
3804
+ };
3805
+ }
3806
+ if (inputSchema.primitiveSchema && VALUE_HEX_VIEW in inputData.valueBlock) {
3807
+ const asn1 = localFromBER(inputData.valueBlock.valueHexView);
3808
+ if (asn1.offset === -1) {
3809
+ const _result = {
3810
+ verified: false,
3811
+ result: asn1.result
3812
+ };
3813
+ if (inputSchema.name) {
3814
+ inputSchema.name = inputSchema.name.replace(/^\s+|\s+$/g, EMPTY_STRING);
3815
+ if (inputSchema.name) {
3816
+ delete root[inputSchema.name];
3817
+ _result.name = inputSchema.name;
3818
+ }
3819
+ }
3820
+ return _result;
3821
+ }
3822
+ return compareSchema(root, asn1.result, inputSchema.primitiveSchema);
3823
+ }
3824
+ return {
3825
+ verified: true,
3826
+ result: root
3827
+ };
3828
+ }
3829
+ function verifySchema(inputBuffer, inputSchema) {
3830
+ if (inputSchema instanceof Object === false) {
3831
+ return {
3832
+ verified: false,
3833
+ result: { error: "Wrong ASN.1 schema type" }
3834
+ };
3835
+ }
3836
+ const asn1 = localFromBER(BufferSourceConverter.toUint8Array(inputBuffer));
3837
+ if (asn1.offset === -1) {
3838
+ return {
3839
+ verified: false,
3840
+ result: asn1.result
3841
+ };
3842
+ }
3843
+ return compareSchema(asn1.result, asn1.result, inputSchema);
3844
+ }
3845
+
3846
+ // ../../node_modules/@peculiar/asn1-schema/build/es2015/enums.js
3847
+ var AsnTypeTypes;
3848
+ (function(AsnTypeTypes2) {
3849
+ AsnTypeTypes2[AsnTypeTypes2["Sequence"] = 0] = "Sequence";
3850
+ AsnTypeTypes2[AsnTypeTypes2["Set"] = 1] = "Set";
3851
+ AsnTypeTypes2[AsnTypeTypes2["Choice"] = 2] = "Choice";
3852
+ })(AsnTypeTypes || (AsnTypeTypes = {}));
3853
+ var AsnPropTypes;
3854
+ (function(AsnPropTypes2) {
3855
+ AsnPropTypes2[AsnPropTypes2["Any"] = 1] = "Any";
3856
+ AsnPropTypes2[AsnPropTypes2["Boolean"] = 2] = "Boolean";
3857
+ AsnPropTypes2[AsnPropTypes2["OctetString"] = 3] = "OctetString";
3858
+ AsnPropTypes2[AsnPropTypes2["BitString"] = 4] = "BitString";
3859
+ AsnPropTypes2[AsnPropTypes2["Integer"] = 5] = "Integer";
3860
+ AsnPropTypes2[AsnPropTypes2["Enumerated"] = 6] = "Enumerated";
3861
+ AsnPropTypes2[AsnPropTypes2["ObjectIdentifier"] = 7] = "ObjectIdentifier";
3862
+ AsnPropTypes2[AsnPropTypes2["Utf8String"] = 8] = "Utf8String";
3863
+ AsnPropTypes2[AsnPropTypes2["BmpString"] = 9] = "BmpString";
3864
+ AsnPropTypes2[AsnPropTypes2["UniversalString"] = 10] = "UniversalString";
3865
+ AsnPropTypes2[AsnPropTypes2["NumericString"] = 11] = "NumericString";
3866
+ AsnPropTypes2[AsnPropTypes2["PrintableString"] = 12] = "PrintableString";
3867
+ AsnPropTypes2[AsnPropTypes2["TeletexString"] = 13] = "TeletexString";
3868
+ AsnPropTypes2[AsnPropTypes2["VideotexString"] = 14] = "VideotexString";
3869
+ AsnPropTypes2[AsnPropTypes2["IA5String"] = 15] = "IA5String";
3870
+ AsnPropTypes2[AsnPropTypes2["GraphicString"] = 16] = "GraphicString";
3871
+ AsnPropTypes2[AsnPropTypes2["VisibleString"] = 17] = "VisibleString";
3872
+ AsnPropTypes2[AsnPropTypes2["GeneralString"] = 18] = "GeneralString";
3873
+ AsnPropTypes2[AsnPropTypes2["CharacterString"] = 19] = "CharacterString";
3874
+ AsnPropTypes2[AsnPropTypes2["UTCTime"] = 20] = "UTCTime";
3875
+ AsnPropTypes2[AsnPropTypes2["GeneralizedTime"] = 21] = "GeneralizedTime";
3876
+ AsnPropTypes2[AsnPropTypes2["DATE"] = 22] = "DATE";
3877
+ AsnPropTypes2[AsnPropTypes2["TimeOfDay"] = 23] = "TimeOfDay";
3878
+ AsnPropTypes2[AsnPropTypes2["DateTime"] = 24] = "DateTime";
3879
+ AsnPropTypes2[AsnPropTypes2["Duration"] = 25] = "Duration";
3880
+ AsnPropTypes2[AsnPropTypes2["TIME"] = 26] = "TIME";
3881
+ AsnPropTypes2[AsnPropTypes2["Null"] = 27] = "Null";
3882
+ })(AsnPropTypes || (AsnPropTypes = {}));
3883
+
3884
+ // ../../node_modules/@peculiar/asn1-schema/build/es2015/converters.js
3885
+ function createStringConverter(Asn1Type) {
3886
+ return {
3887
+ fromASN: (value) => value.valueBlock.value,
3888
+ toASN: (value) => new Asn1Type({ value })
3889
+ };
3890
+ }
3891
+ var AsnUtf8StringConverter = createStringConverter(Utf8String);
3892
+ var AsnBmpStringConverter = createStringConverter(BmpString);
3893
+ var AsnUniversalStringConverter = createStringConverter(UniversalString);
3894
+ var AsnNumericStringConverter = createStringConverter(NumericString);
3895
+ var AsnPrintableStringConverter = createStringConverter(PrintableString);
3896
+ var AsnTeletexStringConverter = createStringConverter(TeletexString);
3897
+ var AsnVideotexStringConverter = createStringConverter(VideotexString);
3898
+ var AsnIA5StringConverter = createStringConverter(IA5String);
3899
+ var AsnGraphicStringConverter = createStringConverter(GraphicString);
3900
+ var AsnVisibleStringConverter = createStringConverter(VisibleString);
3901
+ var AsnGeneralStringConverter = createStringConverter(GeneralString);
3902
+ var AsnCharacterStringConverter = createStringConverter(CharacterString);
3903
+
3904
+ // ../../node_modules/@peculiar/asn1-schema/build/es2015/helper.js
3905
+ function isConvertible(target) {
3906
+ if (typeof target === "function" && target.prototype) {
3907
+ if (target.prototype.toASN && target.prototype.fromASN) {
3908
+ return true;
3909
+ } else {
3910
+ return isConvertible(target.prototype);
3911
+ }
3912
+ } else {
3913
+ return !!(target && typeof target === "object" && "toASN" in target && "fromASN" in target);
3914
+ }
3915
+ }
3916
+
3917
+ // ../../node_modules/@peculiar/asn1-schema/build/es2015/schema.js
3918
+ var AsnSchemaStorage = class {
3919
+ constructor() {
3920
+ this.items = /* @__PURE__ */ new WeakMap();
3921
+ }
3922
+ has(target) {
3923
+ return this.items.has(target);
3924
+ }
3925
+ get(target, checkSchema = false) {
3926
+ const schema = this.items.get(target);
3927
+ if (!schema) {
3928
+ throw new Error(`Cannot get schema for '${target.prototype.constructor.name}' target`);
3929
+ }
3930
+ if (checkSchema && !schema.schema) {
3931
+ throw new Error(`Schema '${target.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);
3932
+ }
3933
+ return schema;
3934
+ }
3935
+ cache(target) {
3936
+ const schema = this.get(target);
3937
+ if (!schema.schema) {
3938
+ schema.schema = this.create(target, true);
3939
+ }
3940
+ }
3941
+ createDefault(target) {
3942
+ const schema = {
3943
+ type: AsnTypeTypes.Sequence,
3944
+ items: {}
3945
+ };
3946
+ const parentSchema = this.findParentSchema(target);
3947
+ if (parentSchema) {
3948
+ Object.assign(schema, parentSchema);
3949
+ schema.items = Object.assign({}, schema.items, parentSchema.items);
3950
+ }
3951
+ return schema;
3952
+ }
3953
+ create(target, useNames) {
3954
+ const schema = this.items.get(target) || this.createDefault(target);
3955
+ const asn1Value = [];
3956
+ for (const key in schema.items) {
3957
+ const item = schema.items[key];
3958
+ const name = useNames ? key : "";
3959
+ let asn1Item;
3960
+ if (typeof item.type === "number") {
3961
+ const Asn1TypeName = AsnPropTypes[item.type];
3962
+ const Asn1Type = index_es_exports[Asn1TypeName];
3963
+ if (!Asn1Type) {
3964
+ throw new Error(`Cannot get ASN1 class by name '${Asn1TypeName}'`);
3965
+ }
3966
+ asn1Item = new Asn1Type({ name });
3967
+ } else if (isConvertible(item.type)) {
3968
+ const instance = new item.type();
3969
+ asn1Item = instance.toSchema(name);
3970
+ } else if (item.optional) {
3971
+ const itemSchema = this.get(item.type);
3972
+ if (itemSchema.type === AsnTypeTypes.Choice) {
3973
+ asn1Item = new Any({ name });
3974
+ } else {
3975
+ asn1Item = this.create(item.type, false);
3976
+ asn1Item.name = name;
3977
+ }
3978
+ } else {
3979
+ asn1Item = new Any({ name });
3980
+ }
3981
+ const optional = !!item.optional || item.defaultValue !== void 0;
3982
+ if (item.repeated) {
3983
+ asn1Item.name = "";
3984
+ const Container = item.repeated === "set" ? Set : Sequence;
3985
+ asn1Item = new Container({
3986
+ name: "",
3987
+ value: [
3988
+ new Repeated({
3989
+ name,
3990
+ value: asn1Item
3991
+ })
3992
+ ]
3993
+ });
3994
+ }
3995
+ if (item.context !== null && item.context !== void 0) {
3996
+ if (item.implicit) {
3997
+ if (typeof item.type === "number" || isConvertible(item.type)) {
3998
+ const Container = item.repeated ? Constructed : Primitive;
3999
+ asn1Value.push(new Container({
4000
+ name,
4001
+ optional,
4002
+ idBlock: {
4003
+ tagClass: 3,
4004
+ tagNumber: item.context
4005
+ }
4006
+ }));
4007
+ } else {
4008
+ this.cache(item.type);
4009
+ const isRepeated = !!item.repeated;
4010
+ let value = !isRepeated ? this.get(item.type, true).schema : asn1Item;
4011
+ value = "valueBlock" in value ? value.valueBlock.value : value.value;
4012
+ asn1Value.push(new Constructed({
4013
+ name: !isRepeated ? name : "",
4014
+ optional,
4015
+ idBlock: {
4016
+ tagClass: 3,
4017
+ tagNumber: item.context
4018
+ },
4019
+ value
4020
+ }));
4021
+ }
4022
+ } else {
4023
+ asn1Value.push(new Constructed({
4024
+ optional,
4025
+ idBlock: {
4026
+ tagClass: 3,
4027
+ tagNumber: item.context
4028
+ },
4029
+ value: [asn1Item]
4030
+ }));
4031
+ }
4032
+ } else {
4033
+ asn1Item.optional = optional;
4034
+ asn1Value.push(asn1Item);
4035
+ }
4036
+ }
4037
+ switch (schema.type) {
4038
+ case AsnTypeTypes.Sequence:
4039
+ return new Sequence({ value: asn1Value, name: "" });
4040
+ case AsnTypeTypes.Set:
4041
+ return new Set({ value: asn1Value, name: "" });
4042
+ case AsnTypeTypes.Choice:
4043
+ return new Choice({ value: asn1Value, name: "" });
4044
+ default:
4045
+ throw new Error(`Unsupported ASN1 type in use`);
4046
+ }
4047
+ }
4048
+ set(target, schema) {
4049
+ this.items.set(target, schema);
4050
+ return this;
4051
+ }
4052
+ findParentSchema(target) {
4053
+ const parent = Object.getPrototypeOf(target);
4054
+ if (parent) {
4055
+ const schema = this.items.get(parent);
4056
+ return schema || this.findParentSchema(parent);
4057
+ }
4058
+ return null;
4059
+ }
4060
+ };
4061
+
4062
+ // ../../node_modules/@peculiar/asn1-schema/build/es2015/storage.js
4063
+ var schemaStorage = new AsnSchemaStorage();
4064
+
4065
+ // source/x509/coerce_private_key.ts
4066
+ var crypto2 = getCrypto();
4067
+
4068
+ // source_nodejs/generate_private_key_filename.ts
4069
+ var import_jsrsasign3 = __toESM(require("jsrsasign"));
4070
+ async function generatePrivateKeyFile(privateKeyFilename, modulusLength) {
4071
+ const keys = await generateKeyPair(modulusLength);
4072
+ const privateKeyPem = await privateKeyToPEM(keys.privateKey);
4073
+ await import_fs4.default.promises.writeFile(privateKeyFilename, privateKeyPem.privPem, "utf-8");
4074
+ privateKeyPem.privPem = "";
4075
+ privateKeyPem.privDer = new Uint8Array(0);
4076
+ }
4077
+ async function generatePrivateKeyFileAlternate(privateKeyFilename, modulusLength) {
4078
+ const kp = import_jsrsasign3.default.KEYUTIL.generateKeypair("RSA", modulusLength);
4079
+ const prv = kp.prvKeyObj;
4080
+ const pub = kp.pubKeyObj;
4081
+ const prvpem = import_jsrsasign3.default.KEYUTIL.getPEM(prv, "PKCS8PRV");
4082
+ await import_fs4.default.promises.writeFile(privateKeyFilename, prvpem, "utf-8");
4083
+ }
4084
+ // Annotate the CommonJS export names for ESM import in node:
4085
+ 0 && (module.exports = {
4086
+ generatePrivateKeyFile,
4087
+ generatePrivateKeyFileAlternate,
4088
+ getCertificateStore,
4089
+ makePrivateKeyThumbPrint,
4090
+ readCertificate,
4091
+ readCertificatePEM,
4092
+ readCertificateRevocationList,
4093
+ readCertificateSigningRequest,
4094
+ readPrivateKey,
4095
+ readPrivateKeyPEM,
4096
+ readPrivateRsaKey,
4097
+ readPublicKey,
4098
+ readPublicKeyPEM,
4099
+ readPublicRsaKey,
4100
+ setCertificateStore
4101
+ });
4102
+ /*! Bundled license information:
4103
+
4104
+ pvtsutils/build/index.es.js:
4105
+ (*!
4106
+ * MIT License
4107
+ *
4108
+ * Copyright (c) 2017-2022 Peculiar Ventures, LLC
4109
+ *
4110
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
4111
+ * of this software and associated documentation files (the "Software"), to deal
4112
+ * in the Software without restriction, including without limitation the rights
4113
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4114
+ * copies of the Software, and to permit persons to whom the Software is
4115
+ * furnished to do so, subject to the following conditions:
4116
+ *
4117
+ * The above copyright notice and this permission notice shall be included in all
4118
+ * copies or substantial portions of the Software.
4119
+ *
4120
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4121
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4122
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4123
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4124
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4125
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4126
+ * SOFTWARE.
4127
+ *
4128
+ *)
4129
+
4130
+ pvutils/build/utils.es.js:
4131
+ (*!
4132
+ Copyright (c) Peculiar Ventures, LLC
4133
+ *)
4134
+
4135
+ asn1js/build/index.es.js:
4136
+ (*!
4137
+ * Copyright (c) 2014, GMO GlobalSign
4138
+ * Copyright (c) 2015-2022, Peculiar Ventures
4139
+ * All rights reserved.
4140
+ *
4141
+ * Author 2014-2019, Yury Strozhevsky
4142
+ *
4143
+ * Redistribution and use in source and binary forms, with or without modification,
4144
+ * are permitted provided that the following conditions are met:
4145
+ *
4146
+ * * Redistributions of source code must retain the above copyright notice, this
4147
+ * list of conditions and the following disclaimer.
4148
+ *
4149
+ * * Redistributions in binary form must reproduce the above copyright notice, this
4150
+ * list of conditions and the following disclaimer in the documentation and/or
4151
+ * other materials provided with the distribution.
4152
+ *
4153
+ * * Neither the name of the copyright holder nor the names of its
4154
+ * contributors may be used to endorse or promote products derived from
4155
+ * this software without specific prior written permission.
4156
+ *
4157
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
4158
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
4159
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
4160
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
4161
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
4162
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
4163
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
4164
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4165
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
4166
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4167
+ *
4168
+ *)
4169
+ */
4170
+ //# sourceMappingURL=index.js.map