edockit 0.4.0-dev.1 → 0.4.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 (48) hide show
  1. package/CHANGELOG.md +36 -1
  2. package/README.md +3 -7
  3. package/dist/{certificate-3c9dcdac.js → certificate-85461237.js} +11 -11
  4. package/dist/certificate-85461237.js.map +1 -0
  5. package/dist/{certificate-c7123a37.js → certificate-e6d074b8.js} +11 -11
  6. package/dist/certificate-e6d074b8.js.map +1 -0
  7. package/dist/core/parser/types.d.ts +16 -0
  8. package/dist/core/revocation/index.d.ts +1 -1
  9. package/dist/core/revocation/ocsp.d.ts +21 -0
  10. package/dist/core/trustedlist/build.d.ts +2 -1
  11. package/dist/core/trustedlist/index.d.ts +13 -0
  12. package/dist/core/trustedlist/loader.d.ts +14 -0
  13. package/dist/core/trustedlist/types.d.ts +4 -0
  14. package/dist/{identity-fca881b1.js → identity-2eb76bc9.js} +80 -7
  15. package/dist/identity-2eb76bc9.js.map +1 -0
  16. package/dist/{identity-c9e5052e.js → identity-d8910151.js} +77 -3
  17. package/dist/identity-d8910151.js.map +1 -0
  18. package/dist/index.cjs.js +3566 -164
  19. package/dist/index.cjs.js.map +1 -1
  20. package/dist/index.esm.js +3567 -165
  21. package/dist/index.esm.js.map +1 -1
  22. package/dist/index.umd.js +17 -17
  23. package/dist/index.umd.js.map +1 -1
  24. package/dist/{loader-ad1a5051.js → loader-776cb996.js} +21 -3
  25. package/dist/loader-776cb996.js.map +1 -0
  26. package/dist/{loader-7a0f771f.js → loader-9ce42535.js} +21 -2
  27. package/dist/loader-9ce42535.js.map +1 -0
  28. package/dist/{reference-provider-3838ebfb.js → reference-provider-1dd56087.js} +3 -3
  29. package/dist/{reference-provider-3838ebfb.js.map → reference-provider-1dd56087.js.map} +1 -1
  30. package/dist/{reference-provider-9bbbaab8.js → reference-provider-50466d83.js} +3 -3
  31. package/dist/{reference-provider-9bbbaab8.js.map → reference-provider-50466d83.js.map} +1 -1
  32. package/dist/trusted-list-build.cjs.js +65 -30
  33. package/dist/trusted-list-build.cjs.js.map +1 -1
  34. package/dist/trusted-list-build.esm.js +64 -28
  35. package/dist/trusted-list-build.esm.js.map +1 -1
  36. package/dist/trusted-list-bundled.cjs.js +4 -30392
  37. package/dist/trusted-list-bundled.cjs.js.map +1 -1
  38. package/dist/trusted-list-bundled.esm.js +4 -30392
  39. package/dist/trusted-list-bundled.esm.js.map +1 -1
  40. package/dist/trusted-list.cjs.js +3 -3
  41. package/dist/trusted-list.esm.js +3 -3
  42. package/package.json +8 -1
  43. package/dist/certificate-3c9dcdac.js.map +0 -1
  44. package/dist/certificate-c7123a37.js.map +0 -1
  45. package/dist/identity-c9e5052e.js.map +0 -1
  46. package/dist/identity-fca881b1.js.map +0 -1
  47. package/dist/loader-7a0f771f.js.map +0 -1
  48. package/dist/loader-ad1a5051.js.map +0 -1
package/dist/index.cjs.js CHANGED
@@ -8,16 +8,16 @@ Object.defineProperty(exports, '__esModule', { value: true });
8
8
 
9
9
  var fflate = require('fflate');
10
10
  var x509 = require('@peculiar/x509');
11
- var certificate = require('./certificate-c7123a37.js');
12
- var identity = require('./identity-c9e5052e.js');
13
- var normalize = require('./normalize-9626be7c.js');
11
+ var certificate = require('./certificate-e6d074b8.js');
12
+ var identity = require('./identity-d8910151.js');
14
13
  var asn1Schema = require('@peculiar/asn1-schema');
14
+ var asn1X509 = require('@peculiar/asn1-x509');
15
+ var normalize = require('./normalize-9626be7c.js');
15
16
  var asn1Cms = require('@peculiar/asn1-cms');
16
17
  var asn1Tsp = require('@peculiar/asn1-tsp');
17
18
  require('@xmldom/xmldom');
18
19
  require('xpath');
19
20
  require('@peculiar/asn1-ocsp');
20
- require('@peculiar/asn1-x509');
21
21
 
22
22
  // Canonicalization method URIs
23
23
  const CANONICALIZATION_METHODS = {
@@ -614,7 +614,7 @@ function parseSignatureFile(xmlContent, filename) {
614
614
  // Look for Signature elements as direct children
615
615
  const directSignature = certificate.querySelector(rootElement, "ds\\:Signature, Signature");
616
616
  if (directSignature) {
617
- let signatureInfo = parseSignatureElement(directSignature, xmlDoc);
617
+ let signatureInfo = parseSignatureElement(directSignature);
618
618
  signatureInfo.rawXml = text;
619
619
  return signatureInfo;
620
620
  }
@@ -631,7 +631,7 @@ function parseSignatureFile(xmlContent, filename) {
631
631
  return null;
632
632
  }
633
633
  // Parse the signature and add the raw XML
634
- let signatureInfo = parseSignatureElement(signatureElements[0], xmlDoc);
634
+ let signatureInfo = parseSignatureElement(signatureElements[0]);
635
635
  signatureInfo.rawXml = text;
636
636
  return signatureInfo;
637
637
  }
@@ -699,7 +699,7 @@ function parseSignatureElement(signatureElement, xmlDoc) {
699
699
  let signatureTimestamp;
700
700
  let signatureTimestampCanonicalizationMethod;
701
701
  let signatureTimestampInclusiveNamespacePrefixList;
702
- const signatureTimestampElement = certificate.querySelector(xmlDoc, "xades\\:SignatureTimeStamp, SignatureTimeStamp");
702
+ const signatureTimestampElement = certificate.querySelector(signatureElement, "xades\\:SignatureTimeStamp, SignatureTimeStamp");
703
703
  if (signatureTimestampElement) {
704
704
  const timestampC14nMethodEl = certificate.querySelector(signatureTimestampElement, "ds\\:CanonicalizationMethod, CanonicalizationMethod");
705
705
  signatureTimestampCanonicalizationMethod =
@@ -758,7 +758,7 @@ function parseSignatureElement(signatureElement, xmlDoc) {
758
758
  }
759
759
  }
760
760
  // Also look for XAdES CertificateValues (contains full chain excluding signer)
761
- const certValues = certificate.querySelector(xmlDoc, "xades\\:CertificateValues, CertificateValues");
761
+ const certValues = certificate.querySelector(signatureElement, "xades\\:CertificateValues, CertificateValues");
762
762
  if (certValues) {
763
763
  const encapsulatedCerts = certificate.querySelectorAll(certValues, "xades\\:EncapsulatedX509Certificate, EncapsulatedX509Certificate");
764
764
  for (const encCert of encapsulatedCerts) {
@@ -772,6 +772,29 @@ function parseSignatureElement(signatureElement, xmlDoc) {
772
772
  }
773
773
  }
774
774
  }
775
+ // Extract embedded XAdES LTV revocation material (OCSP responses / CRLs) captured
776
+ // at signing time. This lets "not revoked at signing time" be answered offline.
777
+ let revocationValues;
778
+ const revocationValuesEl = certificate.querySelector(signatureElement, "xades\\:RevocationValues, RevocationValues");
779
+ if (revocationValuesEl) {
780
+ const ocsp = [];
781
+ const crl = [];
782
+ for (const el of certificate.querySelectorAll(revocationValuesEl, "xades\\:EncapsulatedOCSPValue, EncapsulatedOCSPValue")) {
783
+ const value = el.textContent?.replace(/\s+/g, "");
784
+ if (value) {
785
+ ocsp.push(value);
786
+ }
787
+ }
788
+ for (const el of certificate.querySelectorAll(revocationValuesEl, "xades\\:EncapsulatedCRLValue, EncapsulatedCRLValue")) {
789
+ const value = el.textContent?.replace(/\s+/g, "");
790
+ if (value) {
791
+ crl.push(value);
792
+ }
793
+ }
794
+ if (ocsp.length > 0 || crl.length > 0) {
795
+ revocationValues = { ocsp, crl };
796
+ }
797
+ }
775
798
  if (certificate$1) {
776
799
  certificatePEM = formatPEM(certificate$1);
777
800
  // Extract public key and signer info
@@ -795,7 +818,7 @@ function parseSignatureElement(signatureElement, xmlDoc) {
795
818
  }
796
819
  }
797
820
  // Get signing time
798
- const signingTimeElement = certificate.querySelector(xmlDoc, "xades\\:SigningTime, SigningTime");
821
+ const signingTimeElement = certificate.querySelector(signatureElement, "xades\\:SigningTime, SigningTime");
799
822
  const signingTime = signingTimeElement && signingTimeElement.textContent
800
823
  ? new Date(signingTimeElement.textContent.trim())
801
824
  : new Date();
@@ -853,6 +876,7 @@ function parseSignatureElement(signatureElement, xmlDoc) {
853
876
  signedInfoXml,
854
877
  canonicalizationMethod,
855
878
  signatureTimestamp,
879
+ revocationValues,
856
880
  };
857
881
  }
858
882
  /**
@@ -998,200 +1022,3529 @@ function fixRSAModulusPadding(publicKeyData) {
998
1022
  if (keyBytes[0] !== 0x30) {
999
1023
  return publicKeyData;
1000
1024
  }
1001
- // Look for RSA OID to confirm it's an RSA key
1002
- const RSA_OID = [0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01];
1003
- let oidPosition = -1;
1004
- for (let i = 0; i <= keyBytes.length - RSA_OID.length; i++) {
1005
- let match = true;
1006
- for (let j = 0; j < RSA_OID.length; j++) {
1007
- if (keyBytes[i + j] !== RSA_OID[j]) {
1008
- match = false;
1009
- break;
1010
- }
1025
+ // Look for RSA OID to confirm it's an RSA key
1026
+ const RSA_OID = [0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01];
1027
+ let oidPosition = -1;
1028
+ for (let i = 0; i <= keyBytes.length - RSA_OID.length; i++) {
1029
+ let match = true;
1030
+ for (let j = 0; j < RSA_OID.length; j++) {
1031
+ if (keyBytes[i + j] !== RSA_OID[j]) {
1032
+ match = false;
1033
+ break;
1034
+ }
1035
+ }
1036
+ if (match) {
1037
+ oidPosition = i;
1038
+ break;
1039
+ }
1040
+ }
1041
+ if (oidPosition === -1) {
1042
+ return publicKeyData;
1043
+ }
1044
+ // Find the BitString that contains the key
1045
+ let bitStringPosition = -1;
1046
+ for (let i = oidPosition + RSA_OID.length; i < keyBytes.length; i++) {
1047
+ if (keyBytes[i] === 0x03) {
1048
+ // BIT STRING tag
1049
+ bitStringPosition = i;
1050
+ break;
1051
+ }
1052
+ }
1053
+ if (bitStringPosition === -1) {
1054
+ return publicKeyData;
1055
+ }
1056
+ // Skip BIT STRING tag and length bytes to find unused bits byte
1057
+ let bitStringLengthBytes = 0;
1058
+ if ((keyBytes[bitStringPosition + 1] & 0x80) === 0) {
1059
+ // Short form length
1060
+ bitStringLengthBytes = 1;
1061
+ }
1062
+ else {
1063
+ // Long form length
1064
+ bitStringLengthBytes = 1 + (keyBytes[bitStringPosition + 1] & 0x7f);
1065
+ }
1066
+ // The unused bits byte follows the length bytes
1067
+ const unusedBitsPosition = bitStringPosition + 1 + bitStringLengthBytes;
1068
+ if (unusedBitsPosition >= keyBytes.length) {
1069
+ return publicKeyData;
1070
+ }
1071
+ // The inner SEQUENCE (RSA key) should follow the unused bits byte
1072
+ const innerSequencePosition = unusedBitsPosition + 1;
1073
+ if (innerSequencePosition >= keyBytes.length || keyBytes[innerSequencePosition] !== 0x30) {
1074
+ return publicKeyData;
1075
+ }
1076
+ // Skip the inner SEQUENCE tag and length bytes to find the modulus
1077
+ let innerSequenceLengthBytes = 0;
1078
+ if ((keyBytes[innerSequencePosition + 1] & 0x80) === 0) {
1079
+ // Short form length
1080
+ innerSequenceLengthBytes = 1;
1081
+ }
1082
+ else {
1083
+ // Long form length
1084
+ innerSequenceLengthBytes = 1 + (keyBytes[innerSequencePosition + 1] & 0x7f);
1085
+ }
1086
+ // The modulus should be an INTEGER (tag 0x02) after the inner SEQUENCE
1087
+ const modulusPosition = innerSequencePosition + 1 + innerSequenceLengthBytes;
1088
+ if (modulusPosition >= keyBytes.length || keyBytes[modulusPosition] !== 0x02) {
1089
+ return publicKeyData;
1090
+ }
1091
+ // Skip the INTEGER tag and parse its length to find the modulus value
1092
+ let modulusLengthBytes = 0;
1093
+ let modulusLength = 0;
1094
+ if ((keyBytes[modulusPosition + 1] & 0x80) === 0) {
1095
+ // Short form length
1096
+ modulusLength = keyBytes[modulusPosition + 1];
1097
+ modulusLengthBytes = 1;
1098
+ }
1099
+ else {
1100
+ // Long form length
1101
+ const numLengthBytes = keyBytes[modulusPosition + 1] & 0x7f;
1102
+ modulusLengthBytes = 1 + numLengthBytes;
1103
+ // Calculate multi-byte length
1104
+ modulusLength = 0;
1105
+ for (let i = 0; i < numLengthBytes; i++) {
1106
+ modulusLength = (modulusLength << 8) | keyBytes[modulusPosition + 2 + i];
1107
+ }
1108
+ }
1109
+ // The first byte of the modulus value
1110
+ const modulusValuePosition = modulusPosition + 1 + modulusLengthBytes;
1111
+ if (modulusValuePosition >= keyBytes.length) {
1112
+ return publicKeyData;
1113
+ }
1114
+ // Check if the high bit is set and padding is needed
1115
+ if ((keyBytes[modulusValuePosition] & 0x80) !== 0) {
1116
+ // Create a new key buffer with room for the padding byte
1117
+ const fixedKey = new Uint8Array(keyBytes.length + 1);
1118
+ // Copy bytes up to the modulus value
1119
+ fixedKey.set(keyBytes.slice(0, modulusValuePosition));
1120
+ // Add the padding byte
1121
+ fixedKey[modulusValuePosition] = 0x00;
1122
+ // Copy the rest of the original key after the padding
1123
+ fixedKey.set(keyBytes.slice(modulusValuePosition), modulusValuePosition + 1);
1124
+ // Now fix all the length fields that need to be incremented
1125
+ // 1. Fix modulus length field
1126
+ if ((keyBytes[modulusPosition + 1] & 0x80) === 0) {
1127
+ // Short form
1128
+ fixedKey[modulusPosition + 1] = keyBytes[modulusPosition + 1] + 1;
1129
+ }
1130
+ else {
1131
+ // Long form
1132
+ const numLengthBytes = keyBytes[modulusPosition + 1] & 0x7f;
1133
+ let lengthValue = 0;
1134
+ for (let i = 0; i < numLengthBytes; i++) {
1135
+ lengthValue = (lengthValue << 8) | keyBytes[modulusPosition + 2 + i];
1136
+ }
1137
+ lengthValue += 1;
1138
+ for (let i = numLengthBytes - 1; i >= 0; i--) {
1139
+ fixedKey[modulusPosition + 2 + i] = lengthValue & 0xff;
1140
+ lengthValue >>= 8;
1141
+ }
1142
+ }
1143
+ // 2. Fix inner SEQUENCE length field
1144
+ if ((keyBytes[innerSequencePosition + 1] & 0x80) === 0) {
1145
+ // Short form
1146
+ fixedKey[innerSequencePosition + 1] = keyBytes[innerSequencePosition + 1] + 1;
1147
+ }
1148
+ else {
1149
+ // Long form
1150
+ const numLengthBytes = keyBytes[innerSequencePosition + 1] & 0x7f;
1151
+ let lengthValue = 0;
1152
+ for (let i = 0; i < numLengthBytes; i++) {
1153
+ lengthValue = (lengthValue << 8) | keyBytes[innerSequencePosition + 2 + i];
1154
+ }
1155
+ lengthValue += 1;
1156
+ for (let i = numLengthBytes - 1; i >= 0; i--) {
1157
+ fixedKey[innerSequencePosition + 2 + i] = lengthValue & 0xff;
1158
+ lengthValue >>= 8;
1159
+ }
1160
+ }
1161
+ // 3. Fix BIT STRING length field
1162
+ if ((keyBytes[bitStringPosition + 1] & 0x80) === 0) {
1163
+ // Short form
1164
+ fixedKey[bitStringPosition + 1] = keyBytes[bitStringPosition + 1] + 1;
1165
+ }
1166
+ else {
1167
+ // Long form
1168
+ const numLengthBytes = keyBytes[bitStringPosition + 1] & 0x7f;
1169
+ let lengthValue = 0;
1170
+ for (let i = 0; i < numLengthBytes; i++) {
1171
+ lengthValue = (lengthValue << 8) | keyBytes[bitStringPosition + 2 + i];
1172
+ }
1173
+ lengthValue += 1;
1174
+ for (let i = numLengthBytes - 1; i >= 0; i--) {
1175
+ fixedKey[bitStringPosition + 2 + i] = lengthValue & 0xff;
1176
+ lengthValue >>= 8;
1177
+ }
1178
+ }
1179
+ // 4. Fix outer SEQUENCE length field
1180
+ if ((keyBytes[1] & 0x80) === 0) {
1181
+ // Short form
1182
+ fixedKey[1] = keyBytes[1] + 1;
1183
+ }
1184
+ else {
1185
+ // Long form
1186
+ const numLengthBytes = keyBytes[1] & 0x7f;
1187
+ let lengthValue = 0;
1188
+ for (let i = 0; i < numLengthBytes; i++) {
1189
+ lengthValue = (lengthValue << 8) | keyBytes[1 + 1 + i];
1190
+ }
1191
+ lengthValue += 1;
1192
+ for (let i = numLengthBytes - 1; i >= 0; i--) {
1193
+ fixedKey[1 + 1 + i] = lengthValue & 0xff;
1194
+ lengthValue >>= 8;
1195
+ }
1196
+ }
1197
+ log("Fixed key length: " + fixedKey.length);
1198
+ return fixedKey.buffer;
1199
+ }
1200
+ return publicKeyData;
1201
+ }
1202
+
1203
+ // src/core/revocation/types.ts
1204
+ /**
1205
+ * Default options for revocation checking
1206
+ */
1207
+ const DEFAULT_REVOCATION_OPTIONS = {
1208
+ ocspEnabled: true,
1209
+ crlEnabled: true,
1210
+ ocspTimeout: 5000,
1211
+ crlTimeout: 10000,
1212
+ };
1213
+
1214
+ /*!
1215
+ * MIT License
1216
+ *
1217
+ * Copyright (c) 2017-2024 Peculiar Ventures, LLC
1218
+ *
1219
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
1220
+ * of this software and associated documentation files (the "Software"), to deal
1221
+ * in the Software without restriction, including without limitation the rights
1222
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1223
+ * copies of the Software, and to permit persons to whom the Software is
1224
+ * furnished to do so, subject to the following conditions:
1225
+ *
1226
+ * The above copyright notice and this permission notice shall be included in all
1227
+ * copies or substantial portions of the Software.
1228
+ *
1229
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1230
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1231
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1232
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1233
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1234
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1235
+ * SOFTWARE.
1236
+ *
1237
+ */
1238
+
1239
+ const ARRAY_BUFFER_NAME = "[object ArrayBuffer]";
1240
+ class BufferSourceConverter {
1241
+ static isArrayBuffer(data) {
1242
+ return Object.prototype.toString.call(data) === ARRAY_BUFFER_NAME;
1243
+ }
1244
+ static toArrayBuffer(data) {
1245
+ if (this.isArrayBuffer(data)) {
1246
+ return data;
1247
+ }
1248
+ if (data.byteLength === data.buffer.byteLength) {
1249
+ return data.buffer;
1250
+ }
1251
+ if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
1252
+ return data.buffer;
1253
+ }
1254
+ return this.toUint8Array(data.buffer)
1255
+ .slice(data.byteOffset, data.byteOffset + data.byteLength)
1256
+ .buffer;
1257
+ }
1258
+ static toUint8Array(data) {
1259
+ return this.toView(data, Uint8Array);
1260
+ }
1261
+ static toView(data, type) {
1262
+ if (data.constructor === type) {
1263
+ return data;
1264
+ }
1265
+ if (this.isArrayBuffer(data)) {
1266
+ return new type(data);
1267
+ }
1268
+ if (this.isArrayBufferView(data)) {
1269
+ return new type(data.buffer, data.byteOffset, data.byteLength);
1270
+ }
1271
+ throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
1272
+ }
1273
+ static isBufferSource(data) {
1274
+ return this.isArrayBufferView(data)
1275
+ || this.isArrayBuffer(data);
1276
+ }
1277
+ static isArrayBufferView(data) {
1278
+ return ArrayBuffer.isView(data)
1279
+ || (data && this.isArrayBuffer(data.buffer));
1280
+ }
1281
+ static isEqual(a, b) {
1282
+ const aView = BufferSourceConverter.toUint8Array(a);
1283
+ const bView = BufferSourceConverter.toUint8Array(b);
1284
+ if (aView.length !== bView.byteLength) {
1285
+ return false;
1286
+ }
1287
+ for (let i = 0; i < aView.length; i++) {
1288
+ if (aView[i] !== bView[i]) {
1289
+ return false;
1290
+ }
1291
+ }
1292
+ return true;
1293
+ }
1294
+ static concat(...args) {
1295
+ let buffers;
1296
+ if (Array.isArray(args[0]) && !(args[1] instanceof Function)) {
1297
+ buffers = args[0];
1298
+ }
1299
+ else if (Array.isArray(args[0]) && args[1] instanceof Function) {
1300
+ buffers = args[0];
1301
+ }
1302
+ else {
1303
+ if (args[args.length - 1] instanceof Function) {
1304
+ buffers = args.slice(0, args.length - 1);
1305
+ }
1306
+ else {
1307
+ buffers = args;
1308
+ }
1309
+ }
1310
+ let size = 0;
1311
+ for (const buffer of buffers) {
1312
+ size += buffer.byteLength;
1313
+ }
1314
+ const res = new Uint8Array(size);
1315
+ let offset = 0;
1316
+ for (const buffer of buffers) {
1317
+ const view = this.toUint8Array(buffer);
1318
+ res.set(view, offset);
1319
+ offset += view.length;
1320
+ }
1321
+ if (args[args.length - 1] instanceof Function) {
1322
+ return this.toView(res, args[args.length - 1]);
1323
+ }
1324
+ return res.buffer;
1325
+ }
1326
+ }
1327
+
1328
+ const STRING_TYPE = "string";
1329
+ const HEX_REGEX = /^[0-9a-f\s]+$/i;
1330
+ const BASE64_REGEX = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
1331
+ const BASE64URL_REGEX = /^[a-zA-Z0-9-_]+$/;
1332
+ class Utf8Converter {
1333
+ static fromString(text) {
1334
+ const s = unescape(encodeURIComponent(text));
1335
+ const uintArray = new Uint8Array(s.length);
1336
+ for (let i = 0; i < s.length; i++) {
1337
+ uintArray[i] = s.charCodeAt(i);
1338
+ }
1339
+ return uintArray.buffer;
1340
+ }
1341
+ static toString(buffer) {
1342
+ const buf = BufferSourceConverter.toUint8Array(buffer);
1343
+ let encodedString = "";
1344
+ for (let i = 0; i < buf.length; i++) {
1345
+ encodedString += String.fromCharCode(buf[i]);
1346
+ }
1347
+ const decodedString = decodeURIComponent(escape(encodedString));
1348
+ return decodedString;
1349
+ }
1350
+ }
1351
+ class Utf16Converter {
1352
+ static toString(buffer, littleEndian = false) {
1353
+ const arrayBuffer = BufferSourceConverter.toArrayBuffer(buffer);
1354
+ const dataView = new DataView(arrayBuffer);
1355
+ let res = "";
1356
+ for (let i = 0; i < arrayBuffer.byteLength; i += 2) {
1357
+ const code = dataView.getUint16(i, littleEndian);
1358
+ res += String.fromCharCode(code);
1359
+ }
1360
+ return res;
1361
+ }
1362
+ static fromString(text, littleEndian = false) {
1363
+ const res = new ArrayBuffer(text.length * 2);
1364
+ const dataView = new DataView(res);
1365
+ for (let i = 0; i < text.length; i++) {
1366
+ dataView.setUint16(i * 2, text.charCodeAt(i), littleEndian);
1367
+ }
1368
+ return res;
1369
+ }
1370
+ }
1371
+ class Convert {
1372
+ static isHex(data) {
1373
+ return typeof data === STRING_TYPE
1374
+ && HEX_REGEX.test(data);
1375
+ }
1376
+ static isBase64(data) {
1377
+ return typeof data === STRING_TYPE
1378
+ && BASE64_REGEX.test(data);
1379
+ }
1380
+ static isBase64Url(data) {
1381
+ return typeof data === STRING_TYPE
1382
+ && BASE64URL_REGEX.test(data);
1383
+ }
1384
+ static ToString(buffer, enc = "utf8") {
1385
+ const buf = BufferSourceConverter.toUint8Array(buffer);
1386
+ switch (enc.toLowerCase()) {
1387
+ case "utf8":
1388
+ return this.ToUtf8String(buf);
1389
+ case "binary":
1390
+ return this.ToBinary(buf);
1391
+ case "hex":
1392
+ return this.ToHex(buf);
1393
+ case "base64":
1394
+ return this.ToBase64(buf);
1395
+ case "base64url":
1396
+ return this.ToBase64Url(buf);
1397
+ case "utf16le":
1398
+ return Utf16Converter.toString(buf, true);
1399
+ case "utf16":
1400
+ case "utf16be":
1401
+ return Utf16Converter.toString(buf);
1402
+ default:
1403
+ throw new Error(`Unknown type of encoding '${enc}'`);
1404
+ }
1405
+ }
1406
+ static FromString(str, enc = "utf8") {
1407
+ if (!str) {
1408
+ return new ArrayBuffer(0);
1409
+ }
1410
+ switch (enc.toLowerCase()) {
1411
+ case "utf8":
1412
+ return this.FromUtf8String(str);
1413
+ case "binary":
1414
+ return this.FromBinary(str);
1415
+ case "hex":
1416
+ return this.FromHex(str);
1417
+ case "base64":
1418
+ return this.FromBase64(str);
1419
+ case "base64url":
1420
+ return this.FromBase64Url(str);
1421
+ case "utf16le":
1422
+ return Utf16Converter.fromString(str, true);
1423
+ case "utf16":
1424
+ case "utf16be":
1425
+ return Utf16Converter.fromString(str);
1426
+ default:
1427
+ throw new Error(`Unknown type of encoding '${enc}'`);
1428
+ }
1429
+ }
1430
+ static ToBase64(buffer) {
1431
+ const buf = BufferSourceConverter.toUint8Array(buffer);
1432
+ if (typeof btoa !== "undefined") {
1433
+ const binary = this.ToString(buf, "binary");
1434
+ return btoa(binary);
1435
+ }
1436
+ else {
1437
+ return Buffer.from(buf).toString("base64");
1438
+ }
1439
+ }
1440
+ static FromBase64(base64) {
1441
+ const formatted = this.formatString(base64);
1442
+ if (!formatted) {
1443
+ return new ArrayBuffer(0);
1444
+ }
1445
+ if (!Convert.isBase64(formatted)) {
1446
+ throw new TypeError("Argument 'base64Text' is not Base64 encoded");
1447
+ }
1448
+ if (typeof atob !== "undefined") {
1449
+ return this.FromBinary(atob(formatted));
1450
+ }
1451
+ else {
1452
+ return new Uint8Array(Buffer.from(formatted, "base64")).buffer;
1453
+ }
1454
+ }
1455
+ static FromBase64Url(base64url) {
1456
+ const formatted = this.formatString(base64url);
1457
+ if (!formatted) {
1458
+ return new ArrayBuffer(0);
1459
+ }
1460
+ if (!Convert.isBase64Url(formatted)) {
1461
+ throw new TypeError("Argument 'base64url' is not Base64Url encoded");
1462
+ }
1463
+ return this.FromBase64(this.Base64Padding(formatted.replace(/\-/g, "+").replace(/\_/g, "/")));
1464
+ }
1465
+ static ToBase64Url(data) {
1466
+ return this.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
1467
+ }
1468
+ static FromUtf8String(text, encoding = Convert.DEFAULT_UTF8_ENCODING) {
1469
+ switch (encoding) {
1470
+ case "ascii":
1471
+ return this.FromBinary(text);
1472
+ case "utf8":
1473
+ return Utf8Converter.fromString(text);
1474
+ case "utf16":
1475
+ case "utf16be":
1476
+ return Utf16Converter.fromString(text);
1477
+ case "utf16le":
1478
+ case "usc2":
1479
+ return Utf16Converter.fromString(text, true);
1480
+ default:
1481
+ throw new Error(`Unknown type of encoding '${encoding}'`);
1482
+ }
1483
+ }
1484
+ static ToUtf8String(buffer, encoding = Convert.DEFAULT_UTF8_ENCODING) {
1485
+ switch (encoding) {
1486
+ case "ascii":
1487
+ return this.ToBinary(buffer);
1488
+ case "utf8":
1489
+ return Utf8Converter.toString(buffer);
1490
+ case "utf16":
1491
+ case "utf16be":
1492
+ return Utf16Converter.toString(buffer);
1493
+ case "utf16le":
1494
+ case "usc2":
1495
+ return Utf16Converter.toString(buffer, true);
1496
+ default:
1497
+ throw new Error(`Unknown type of encoding '${encoding}'`);
1498
+ }
1499
+ }
1500
+ static FromBinary(text) {
1501
+ const stringLength = text.length;
1502
+ const resultView = new Uint8Array(stringLength);
1503
+ for (let i = 0; i < stringLength; i++) {
1504
+ resultView[i] = text.charCodeAt(i);
1505
+ }
1506
+ return resultView.buffer;
1507
+ }
1508
+ static ToBinary(buffer) {
1509
+ const buf = BufferSourceConverter.toUint8Array(buffer);
1510
+ let res = "";
1511
+ for (let i = 0; i < buf.length; i++) {
1512
+ res += String.fromCharCode(buf[i]);
1513
+ }
1514
+ return res;
1515
+ }
1516
+ static ToHex(buffer) {
1517
+ const buf = BufferSourceConverter.toUint8Array(buffer);
1518
+ let result = "";
1519
+ const len = buf.length;
1520
+ for (let i = 0; i < len; i++) {
1521
+ const byte = buf[i];
1522
+ if (byte < 16) {
1523
+ result += "0";
1524
+ }
1525
+ result += byte.toString(16);
1526
+ }
1527
+ return result;
1528
+ }
1529
+ static FromHex(hexString) {
1530
+ let formatted = this.formatString(hexString);
1531
+ if (!formatted) {
1532
+ return new ArrayBuffer(0);
1533
+ }
1534
+ if (!Convert.isHex(formatted)) {
1535
+ throw new TypeError("Argument 'hexString' is not HEX encoded");
1536
+ }
1537
+ if (formatted.length % 2) {
1538
+ formatted = `0${formatted}`;
1539
+ }
1540
+ const res = new Uint8Array(formatted.length / 2);
1541
+ for (let i = 0; i < formatted.length; i = i + 2) {
1542
+ const c = formatted.slice(i, i + 2);
1543
+ res[i / 2] = parseInt(c, 16);
1544
+ }
1545
+ return res.buffer;
1546
+ }
1547
+ static ToUtf16String(buffer, littleEndian = false) {
1548
+ return Utf16Converter.toString(buffer, littleEndian);
1549
+ }
1550
+ static FromUtf16String(text, littleEndian = false) {
1551
+ return Utf16Converter.fromString(text, littleEndian);
1552
+ }
1553
+ static Base64Padding(base64) {
1554
+ const padCount = 4 - (base64.length % 4);
1555
+ if (padCount < 4) {
1556
+ for (let i = 0; i < padCount; i++) {
1557
+ base64 += "=";
1558
+ }
1559
+ }
1560
+ return base64;
1561
+ }
1562
+ static formatString(data) {
1563
+ return (data === null || data === void 0 ? void 0 : data.replace(/[\n\r\t ]/g, "")) || "";
1564
+ }
1565
+ }
1566
+ Convert.DEFAULT_UTF8_ENCODING = "utf8";
1567
+
1568
+ /*!
1569
+ Copyright (c) Peculiar Ventures, LLC
1570
+ */
1571
+ function utilFromBase(inputBuffer, inputBase) {
1572
+ let result = 0;
1573
+ if (inputBuffer.length === 1) {
1574
+ return inputBuffer[0];
1575
+ }
1576
+ for (let i = (inputBuffer.length - 1); i >= 0; i--) {
1577
+ result += inputBuffer[(inputBuffer.length - 1) - i] * Math.pow(2, inputBase * i);
1578
+ }
1579
+ return result;
1580
+ }
1581
+ function utilToBase(value, base, reserved = (-1)) {
1582
+ const internalReserved = reserved;
1583
+ let internalValue = value;
1584
+ let result = 0;
1585
+ let biggest = Math.pow(2, base);
1586
+ for (let i = 1; i < 8; i++) {
1587
+ if (value < biggest) {
1588
+ let retBuf;
1589
+ if (internalReserved < 0) {
1590
+ retBuf = new ArrayBuffer(i);
1591
+ result = i;
1592
+ }
1593
+ else {
1594
+ if (internalReserved < i) {
1595
+ return (new ArrayBuffer(0));
1596
+ }
1597
+ retBuf = new ArrayBuffer(internalReserved);
1598
+ result = internalReserved;
1599
+ }
1600
+ const retView = new Uint8Array(retBuf);
1601
+ for (let j = (i - 1); j >= 0; j--) {
1602
+ const basis = Math.pow(2, j * base);
1603
+ retView[result - j - 1] = Math.floor(internalValue / basis);
1604
+ internalValue -= (retView[result - j - 1]) * basis;
1605
+ }
1606
+ return retBuf;
1607
+ }
1608
+ biggest *= Math.pow(2, base);
1609
+ }
1610
+ return new ArrayBuffer(0);
1611
+ }
1612
+ function utilConcatView(...views) {
1613
+ let outputLength = 0;
1614
+ let prevLength = 0;
1615
+ for (const view of views) {
1616
+ outputLength += view.length;
1617
+ }
1618
+ const retBuf = new ArrayBuffer(outputLength);
1619
+ const retView = new Uint8Array(retBuf);
1620
+ for (const view of views) {
1621
+ retView.set(view, prevLength);
1622
+ prevLength += view.length;
1623
+ }
1624
+ return retView;
1625
+ }
1626
+ function utilDecodeTC() {
1627
+ const buf = new Uint8Array(this.valueHex);
1628
+ if (this.valueHex.byteLength >= 2) {
1629
+ const condition1 = (buf[0] === 0xFF) && (buf[1] & 0x80);
1630
+ const condition2 = (buf[0] === 0x00) && ((buf[1] & 0x80) === 0x00);
1631
+ if (condition1 || condition2) {
1632
+ this.warnings.push("Needlessly long format");
1633
+ }
1634
+ }
1635
+ const bigIntBuffer = new ArrayBuffer(this.valueHex.byteLength);
1636
+ const bigIntView = new Uint8Array(bigIntBuffer);
1637
+ for (let i = 0; i < this.valueHex.byteLength; i++) {
1638
+ bigIntView[i] = 0;
1639
+ }
1640
+ bigIntView[0] = (buf[0] & 0x80);
1641
+ const bigInt = utilFromBase(bigIntView, 8);
1642
+ const smallIntBuffer = new ArrayBuffer(this.valueHex.byteLength);
1643
+ const smallIntView = new Uint8Array(smallIntBuffer);
1644
+ for (let j = 0; j < this.valueHex.byteLength; j++) {
1645
+ smallIntView[j] = buf[j];
1646
+ }
1647
+ smallIntView[0] &= 0x7F;
1648
+ const smallInt = utilFromBase(smallIntView, 8);
1649
+ return (smallInt - bigInt);
1650
+ }
1651
+ function utilEncodeTC(value) {
1652
+ const modValue = (value < 0) ? (value * (-1)) : value;
1653
+ let bigInt = 128;
1654
+ for (let i = 1; i < 8; i++) {
1655
+ if (modValue <= bigInt) {
1656
+ if (value < 0) {
1657
+ const smallInt = bigInt - modValue;
1658
+ const retBuf = utilToBase(smallInt, 8, i);
1659
+ const retView = new Uint8Array(retBuf);
1660
+ retView[0] |= 0x80;
1661
+ return retBuf;
1662
+ }
1663
+ let retBuf = utilToBase(modValue, 8, i);
1664
+ let retView = new Uint8Array(retBuf);
1665
+ if (retView[0] & 0x80) {
1666
+ const tempBuf = retBuf.slice(0);
1667
+ const tempView = new Uint8Array(tempBuf);
1668
+ retBuf = new ArrayBuffer(retBuf.byteLength + 1);
1669
+ retView = new Uint8Array(retBuf);
1670
+ for (let k = 0; k < tempBuf.byteLength; k++) {
1671
+ retView[k + 1] = tempView[k];
1672
+ }
1673
+ retView[0] = 0x00;
1674
+ }
1675
+ return retBuf;
1676
+ }
1677
+ bigInt *= Math.pow(2, 8);
1678
+ }
1679
+ return (new ArrayBuffer(0));
1680
+ }
1681
+ function isEqualBuffer(inputBuffer1, inputBuffer2) {
1682
+ if (inputBuffer1.byteLength !== inputBuffer2.byteLength) {
1683
+ return false;
1684
+ }
1685
+ const view1 = new Uint8Array(inputBuffer1);
1686
+ const view2 = new Uint8Array(inputBuffer2);
1687
+ for (let i = 0; i < view1.length; i++) {
1688
+ if (view1[i] !== view2[i]) {
1689
+ return false;
1690
+ }
1691
+ }
1692
+ return true;
1693
+ }
1694
+ function padNumber(inputNumber, fullLength) {
1695
+ const str = inputNumber.toString(10);
1696
+ if (fullLength < str.length) {
1697
+ return "";
1698
+ }
1699
+ const dif = fullLength - str.length;
1700
+ const padding = new Array(dif);
1701
+ for (let i = 0; i < dif; i++) {
1702
+ padding[i] = "0";
1703
+ }
1704
+ const paddingString = padding.join("");
1705
+ return paddingString.concat(str);
1706
+ }
1707
+
1708
+ /*!
1709
+ * Copyright (c) 2014, GMO GlobalSign
1710
+ * Copyright (c) 2015-2022, Peculiar Ventures
1711
+ * All rights reserved.
1712
+ *
1713
+ * Author 2014-2019, Yury Strozhevsky
1714
+ *
1715
+ * Redistribution and use in source and binary forms, with or without modification,
1716
+ * are permitted provided that the following conditions are met:
1717
+ *
1718
+ * * Redistributions of source code must retain the above copyright notice, this
1719
+ * list of conditions and the following disclaimer.
1720
+ *
1721
+ * * Redistributions in binary form must reproduce the above copyright notice, this
1722
+ * list of conditions and the following disclaimer in the documentation and/or
1723
+ * other materials provided with the distribution.
1724
+ *
1725
+ * * Neither the name of the copyright holder nor the names of its
1726
+ * contributors may be used to endorse or promote products derived from
1727
+ * this software without specific prior written permission.
1728
+ *
1729
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1730
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1731
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1732
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
1733
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1734
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1735
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
1736
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1737
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1738
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1739
+ *
1740
+ */
1741
+
1742
+ function assertBigInt() {
1743
+ if (typeof BigInt === "undefined") {
1744
+ throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.");
1745
+ }
1746
+ }
1747
+ function concat(buffers) {
1748
+ let outputLength = 0;
1749
+ let prevLength = 0;
1750
+ for (let i = 0; i < buffers.length; i++) {
1751
+ const buffer = buffers[i];
1752
+ outputLength += buffer.byteLength;
1753
+ }
1754
+ const retView = new Uint8Array(outputLength);
1755
+ for (let i = 0; i < buffers.length; i++) {
1756
+ const buffer = buffers[i];
1757
+ retView.set(new Uint8Array(buffer), prevLength);
1758
+ prevLength += buffer.byteLength;
1759
+ }
1760
+ return retView.buffer;
1761
+ }
1762
+ function checkBufferParams(baseBlock, inputBuffer, inputOffset, inputLength) {
1763
+ if (!(inputBuffer instanceof Uint8Array)) {
1764
+ baseBlock.error = "Wrong parameter: inputBuffer must be 'Uint8Array'";
1765
+ return false;
1766
+ }
1767
+ if (!inputBuffer.byteLength) {
1768
+ baseBlock.error = "Wrong parameter: inputBuffer has zero length";
1769
+ return false;
1770
+ }
1771
+ if (inputOffset < 0) {
1772
+ baseBlock.error = "Wrong parameter: inputOffset less than zero";
1773
+ return false;
1774
+ }
1775
+ if (inputLength < 0) {
1776
+ baseBlock.error = "Wrong parameter: inputLength less than zero";
1777
+ return false;
1778
+ }
1779
+ if ((inputBuffer.byteLength - inputOffset - inputLength) < 0) {
1780
+ baseBlock.error = "End of input reached before message was fully decoded (inconsistent offset and length values)";
1781
+ return false;
1782
+ }
1783
+ return true;
1784
+ }
1785
+
1786
+ class ViewWriter {
1787
+ constructor() {
1788
+ this.items = [];
1789
+ }
1790
+ write(buf) {
1791
+ this.items.push(buf);
1792
+ }
1793
+ final() {
1794
+ return concat(this.items);
1795
+ }
1796
+ }
1797
+
1798
+ const powers2 = [new Uint8Array([1])];
1799
+ const digitsString = "0123456789";
1800
+ const EMPTY_STRING = "";
1801
+ const EMPTY_BUFFER = new ArrayBuffer(0);
1802
+ const EMPTY_VIEW = new Uint8Array(0);
1803
+ const END_OF_CONTENT_NAME = "EndOfContent";
1804
+ const OCTET_STRING_NAME = "OCTET STRING";
1805
+ const BIT_STRING_NAME = "BIT STRING";
1806
+
1807
+ function HexBlock(BaseClass) {
1808
+ var _a;
1809
+ return _a = class Some extends BaseClass {
1810
+ get valueHex() {
1811
+ return this.valueHexView.slice().buffer;
1812
+ }
1813
+ set valueHex(value) {
1814
+ this.valueHexView = new Uint8Array(value);
1815
+ }
1816
+ constructor(...args) {
1817
+ var _b;
1818
+ super(...args);
1819
+ const params = args[0] || {};
1820
+ this.isHexOnly = (_b = params.isHexOnly) !== null && _b !== void 0 ? _b : false;
1821
+ this.valueHexView = params.valueHex ? BufferSourceConverter.toUint8Array(params.valueHex) : EMPTY_VIEW;
1822
+ }
1823
+ fromBER(inputBuffer, inputOffset, inputLength, _context) {
1824
+ const view = inputBuffer instanceof ArrayBuffer ? new Uint8Array(inputBuffer) : inputBuffer;
1825
+ if (!checkBufferParams(this, view, inputOffset, inputLength)) {
1826
+ return -1;
1827
+ }
1828
+ const endLength = inputOffset + inputLength;
1829
+ this.valueHexView = view.subarray(inputOffset, endLength);
1830
+ if (!this.valueHexView.length) {
1831
+ this.warnings.push("Zero buffer length");
1832
+ return inputOffset;
1833
+ }
1834
+ this.blockLength = inputLength;
1835
+ return endLength;
1836
+ }
1837
+ toBER(sizeOnly = false) {
1838
+ if (!this.isHexOnly) {
1839
+ this.error = "Flag 'isHexOnly' is not set, abort";
1840
+ return EMPTY_BUFFER;
1841
+ }
1842
+ if (sizeOnly) {
1843
+ return new ArrayBuffer(this.valueHexView.byteLength);
1844
+ }
1845
+ return (this.valueHexView.byteLength === this.valueHexView.buffer.byteLength)
1846
+ ? this.valueHexView.buffer
1847
+ : this.valueHexView.slice().buffer;
1848
+ }
1849
+ toJSON() {
1850
+ return {
1851
+ ...super.toJSON(),
1852
+ isHexOnly: this.isHexOnly,
1853
+ valueHex: Convert.ToHex(this.valueHexView),
1854
+ };
1855
+ }
1856
+ },
1857
+ _a.NAME = "hexBlock",
1858
+ _a;
1859
+ }
1860
+
1861
+ class LocalBaseBlock {
1862
+ static blockName() {
1863
+ return this.NAME;
1864
+ }
1865
+ get valueBeforeDecode() {
1866
+ return this.valueBeforeDecodeView.slice().buffer;
1867
+ }
1868
+ set valueBeforeDecode(value) {
1869
+ this.valueBeforeDecodeView = new Uint8Array(value);
1870
+ }
1871
+ constructor({ blockLength = 0, error = EMPTY_STRING, warnings = [], valueBeforeDecode = EMPTY_VIEW, } = {}) {
1872
+ this.blockLength = blockLength;
1873
+ this.error = error;
1874
+ this.warnings = warnings;
1875
+ this.valueBeforeDecodeView = BufferSourceConverter.toUint8Array(valueBeforeDecode);
1876
+ }
1877
+ toJSON() {
1878
+ return {
1879
+ blockName: this.constructor.NAME,
1880
+ blockLength: this.blockLength,
1881
+ error: this.error,
1882
+ warnings: this.warnings,
1883
+ valueBeforeDecode: Convert.ToHex(this.valueBeforeDecodeView),
1884
+ };
1885
+ }
1886
+ }
1887
+ LocalBaseBlock.NAME = "baseBlock";
1888
+
1889
+ class ValueBlock extends LocalBaseBlock {
1890
+ fromBER(_inputBuffer, _inputOffset, _inputLength, _context) {
1891
+ throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'");
1892
+ }
1893
+ toBER(_sizeOnly, _writer) {
1894
+ throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'");
1895
+ }
1896
+ }
1897
+ ValueBlock.NAME = "valueBlock";
1898
+
1899
+ class LocalIdentificationBlock extends HexBlock(LocalBaseBlock) {
1900
+ constructor({ idBlock = {} } = {}) {
1901
+ var _a, _b, _c, _d;
1902
+ super();
1903
+ if (idBlock) {
1904
+ this.isHexOnly = (_a = idBlock.isHexOnly) !== null && _a !== void 0 ? _a : false;
1905
+ this.valueHexView = idBlock.valueHex
1906
+ ? BufferSourceConverter.toUint8Array(idBlock.valueHex)
1907
+ : EMPTY_VIEW;
1908
+ this.tagClass = (_b = idBlock.tagClass) !== null && _b !== void 0 ? _b : -1;
1909
+ this.tagNumber = (_c = idBlock.tagNumber) !== null && _c !== void 0 ? _c : -1;
1910
+ this.isConstructed = (_d = idBlock.isConstructed) !== null && _d !== void 0 ? _d : false;
1911
+ }
1912
+ else {
1913
+ this.tagClass = -1;
1914
+ this.tagNumber = -1;
1915
+ this.isConstructed = false;
1916
+ }
1917
+ }
1918
+ toBER(sizeOnly = false) {
1919
+ let firstOctet = 0;
1920
+ switch (this.tagClass) {
1921
+ case 1:
1922
+ firstOctet |= 0x00;
1923
+ break;
1924
+ case 2:
1925
+ firstOctet |= 0x40;
1926
+ break;
1927
+ case 3:
1928
+ firstOctet |= 0x80;
1929
+ break;
1930
+ case 4:
1931
+ firstOctet |= 0xC0;
1932
+ break;
1933
+ default:
1934
+ this.error = "Unknown tag class";
1935
+ return EMPTY_BUFFER;
1936
+ }
1937
+ if (this.isConstructed)
1938
+ firstOctet |= 0x20;
1939
+ if (this.tagNumber < 31 && !this.isHexOnly) {
1940
+ const retView = new Uint8Array(1);
1941
+ if (!sizeOnly) {
1942
+ let number = this.tagNumber;
1943
+ number &= 0x1F;
1944
+ firstOctet |= number;
1945
+ retView[0] = firstOctet;
1946
+ }
1947
+ return retView.buffer;
1948
+ }
1949
+ if (!this.isHexOnly) {
1950
+ const encodedBuf = utilToBase(this.tagNumber, 7);
1951
+ const encodedView = new Uint8Array(encodedBuf);
1952
+ const size = encodedBuf.byteLength;
1953
+ const retView = new Uint8Array(size + 1);
1954
+ retView[0] = (firstOctet | 0x1F);
1955
+ if (!sizeOnly) {
1956
+ for (let i = 0; i < (size - 1); i++)
1957
+ retView[i + 1] = encodedView[i] | 0x80;
1958
+ retView[size] = encodedView[size - 1];
1959
+ }
1960
+ return retView.buffer;
1961
+ }
1962
+ const retView = new Uint8Array(this.valueHexView.byteLength + 1);
1963
+ retView[0] = (firstOctet | 0x1F);
1964
+ if (!sizeOnly) {
1965
+ const curView = this.valueHexView;
1966
+ for (let i = 0; i < (curView.length - 1); i++)
1967
+ retView[i + 1] = curView[i] | 0x80;
1968
+ retView[this.valueHexView.byteLength] = curView[curView.length - 1];
1969
+ }
1970
+ return retView.buffer;
1971
+ }
1972
+ fromBER(inputBuffer, inputOffset, inputLength) {
1973
+ const inputView = BufferSourceConverter.toUint8Array(inputBuffer);
1974
+ if (!checkBufferParams(this, inputView, inputOffset, inputLength)) {
1975
+ return -1;
1976
+ }
1977
+ const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength);
1978
+ if (intBuffer.length === 0) {
1979
+ this.error = "Zero buffer length";
1980
+ return -1;
1981
+ }
1982
+ const tagClassMask = intBuffer[0] & 0xC0;
1983
+ switch (tagClassMask) {
1984
+ case 0x00:
1985
+ this.tagClass = (1);
1986
+ break;
1987
+ case 0x40:
1988
+ this.tagClass = (2);
1989
+ break;
1990
+ case 0x80:
1991
+ this.tagClass = (3);
1992
+ break;
1993
+ case 0xC0:
1994
+ this.tagClass = (4);
1995
+ break;
1996
+ default:
1997
+ this.error = "Unknown tag class";
1998
+ return -1;
1999
+ }
2000
+ this.isConstructed = (intBuffer[0] & 0x20) === 0x20;
2001
+ this.isHexOnly = false;
2002
+ const tagNumberMask = intBuffer[0] & 0x1F;
2003
+ if (tagNumberMask !== 0x1F) {
2004
+ this.tagNumber = (tagNumberMask);
2005
+ this.blockLength = 1;
2006
+ }
2007
+ else {
2008
+ let count = 0;
2009
+ while (true) {
2010
+ const tagByteIndex = count + 1;
2011
+ if (tagByteIndex >= intBuffer.length) {
2012
+ this.error = "End of input reached before message was fully decoded";
2013
+ return -1;
2014
+ }
2015
+ count++;
2016
+ if ((intBuffer[tagByteIndex] & 0x80) === 0x00)
2017
+ break;
2018
+ }
2019
+ this.blockLength = (count + 1);
2020
+ const intTagNumberBuffer = this.valueHexView = new Uint8Array(count);
2021
+ for (let i = 0; i < count; i++)
2022
+ intTagNumberBuffer[i] = intBuffer[i + 1] & 0x7F;
2023
+ if (this.blockLength <= 9)
2024
+ this.tagNumber = utilFromBase(intTagNumberBuffer, 7);
2025
+ else {
2026
+ this.isHexOnly = true;
2027
+ this.warnings.push("Tag too long, represented as hex-coded");
2028
+ }
2029
+ }
2030
+ if (((this.tagClass === 1))
2031
+ && (this.isConstructed)) {
2032
+ switch (this.tagNumber) {
2033
+ case 1:
2034
+ case 2:
2035
+ case 5:
2036
+ case 6:
2037
+ case 9:
2038
+ case 13:
2039
+ case 14:
2040
+ case 23:
2041
+ case 24:
2042
+ case 31:
2043
+ case 32:
2044
+ case 33:
2045
+ case 34:
2046
+ this.error = "Constructed encoding used for primitive type";
2047
+ return -1;
2048
+ }
2049
+ }
2050
+ return (inputOffset + this.blockLength);
2051
+ }
2052
+ toJSON() {
2053
+ return {
2054
+ ...super.toJSON(),
2055
+ tagClass: this.tagClass,
2056
+ tagNumber: this.tagNumber,
2057
+ isConstructed: this.isConstructed,
2058
+ };
2059
+ }
2060
+ }
2061
+ LocalIdentificationBlock.NAME = "identificationBlock";
2062
+
2063
+ class LocalLengthBlock extends LocalBaseBlock {
2064
+ constructor({ lenBlock = {} } = {}) {
2065
+ var _a, _b, _c;
2066
+ super();
2067
+ this.isIndefiniteForm = (_a = lenBlock.isIndefiniteForm) !== null && _a !== void 0 ? _a : false;
2068
+ this.longFormUsed = (_b = lenBlock.longFormUsed) !== null && _b !== void 0 ? _b : false;
2069
+ this.length = (_c = lenBlock.length) !== null && _c !== void 0 ? _c : 0;
2070
+ }
2071
+ fromBER(inputBuffer, inputOffset, inputLength) {
2072
+ const view = BufferSourceConverter.toUint8Array(inputBuffer);
2073
+ if (!checkBufferParams(this, view, inputOffset, inputLength)) {
2074
+ return -1;
2075
+ }
2076
+ const intBuffer = view.subarray(inputOffset, inputOffset + inputLength);
2077
+ if (intBuffer.length === 0) {
2078
+ this.error = "Zero buffer length";
2079
+ return -1;
2080
+ }
2081
+ if (intBuffer[0] === 0xFF) {
2082
+ this.error = "Length block 0xFF is reserved by standard";
2083
+ return -1;
2084
+ }
2085
+ this.isIndefiniteForm = intBuffer[0] === 0x80;
2086
+ if (this.isIndefiniteForm) {
2087
+ this.blockLength = 1;
2088
+ return (inputOffset + this.blockLength);
2089
+ }
2090
+ this.longFormUsed = !!(intBuffer[0] & 0x80);
2091
+ if (this.longFormUsed === false) {
2092
+ this.length = (intBuffer[0]);
2093
+ this.blockLength = 1;
2094
+ return (inputOffset + this.blockLength);
2095
+ }
2096
+ const count = intBuffer[0] & 0x7F;
2097
+ if (count > 8) {
2098
+ this.error = "Too big integer";
2099
+ return -1;
2100
+ }
2101
+ if ((count + 1) > intBuffer.length) {
2102
+ this.error = "End of input reached before message was fully decoded";
2103
+ return -1;
2104
+ }
2105
+ const lenOffset = inputOffset + 1;
2106
+ const lengthBufferView = view.subarray(lenOffset, lenOffset + count);
2107
+ if (lengthBufferView[count - 1] === 0x00)
2108
+ this.warnings.push("Needlessly long encoded length");
2109
+ this.length = utilFromBase(lengthBufferView, 8);
2110
+ if (this.longFormUsed && (this.length <= 127))
2111
+ this.warnings.push("Unnecessary usage of long length form");
2112
+ this.blockLength = count + 1;
2113
+ return (inputOffset + this.blockLength);
2114
+ }
2115
+ toBER(sizeOnly = false) {
2116
+ let retBuf;
2117
+ let retView;
2118
+ if (this.length > 127)
2119
+ this.longFormUsed = true;
2120
+ if (this.isIndefiniteForm) {
2121
+ retBuf = new ArrayBuffer(1);
2122
+ if (sizeOnly === false) {
2123
+ retView = new Uint8Array(retBuf);
2124
+ retView[0] = 0x80;
2125
+ }
2126
+ return retBuf;
2127
+ }
2128
+ if (this.longFormUsed) {
2129
+ const encodedBuf = utilToBase(this.length, 8);
2130
+ if (encodedBuf.byteLength > 127) {
2131
+ this.error = "Too big length";
2132
+ return (EMPTY_BUFFER);
2133
+ }
2134
+ retBuf = new ArrayBuffer(encodedBuf.byteLength + 1);
2135
+ if (sizeOnly)
2136
+ return retBuf;
2137
+ const encodedView = new Uint8Array(encodedBuf);
2138
+ retView = new Uint8Array(retBuf);
2139
+ retView[0] = encodedBuf.byteLength | 0x80;
2140
+ for (let i = 0; i < encodedBuf.byteLength; i++)
2141
+ retView[i + 1] = encodedView[i];
2142
+ return retBuf;
2143
+ }
2144
+ retBuf = new ArrayBuffer(1);
2145
+ if (sizeOnly === false) {
2146
+ retView = new Uint8Array(retBuf);
2147
+ retView[0] = this.length;
2148
+ }
2149
+ return retBuf;
2150
+ }
2151
+ toJSON() {
2152
+ return {
2153
+ ...super.toJSON(),
2154
+ isIndefiniteForm: this.isIndefiniteForm,
2155
+ longFormUsed: this.longFormUsed,
2156
+ length: this.length,
2157
+ };
2158
+ }
2159
+ }
2160
+ LocalLengthBlock.NAME = "lengthBlock";
2161
+
2162
+ const typeStore = {};
2163
+
2164
+ class BaseBlock extends LocalBaseBlock {
2165
+ constructor({ name = EMPTY_STRING, optional = false, primitiveSchema, ...parameters } = {}, valueBlockType) {
2166
+ super(parameters);
2167
+ this.name = name;
2168
+ this.optional = optional;
2169
+ if (primitiveSchema) {
2170
+ this.primitiveSchema = primitiveSchema;
2171
+ }
2172
+ this.idBlock = new LocalIdentificationBlock(parameters);
2173
+ this.lenBlock = new LocalLengthBlock(parameters);
2174
+ this.valueBlock = valueBlockType ? new valueBlockType(parameters) : new ValueBlock(parameters);
2175
+ }
2176
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
2177
+ const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, (this.lenBlock.isIndefiniteForm)
2178
+ ? inputLength
2179
+ : this.lenBlock.length, context);
2180
+ if (resultOffset === -1) {
2181
+ this.error = this.valueBlock.error;
2182
+ return resultOffset;
2183
+ }
2184
+ if (!this.idBlock.error.length)
2185
+ this.blockLength += this.idBlock.blockLength;
2186
+ if (!this.lenBlock.error.length)
2187
+ this.blockLength += this.lenBlock.blockLength;
2188
+ if (!this.valueBlock.error.length)
2189
+ this.blockLength += this.valueBlock.blockLength;
2190
+ return resultOffset;
2191
+ }
2192
+ toBER(sizeOnly, writer) {
2193
+ const _writer = writer || new ViewWriter();
2194
+ if (!writer) {
2195
+ prepareIndefiniteForm(this);
2196
+ }
2197
+ const idBlockBuf = this.idBlock.toBER(sizeOnly);
2198
+ _writer.write(idBlockBuf);
2199
+ if (this.lenBlock.isIndefiniteForm) {
2200
+ _writer.write(new Uint8Array([0x80]).buffer);
2201
+ this.valueBlock.toBER(sizeOnly, _writer);
2202
+ _writer.write(new ArrayBuffer(2));
2203
+ }
2204
+ else {
2205
+ const valueBlockBuf = this.valueBlock.toBER(sizeOnly);
2206
+ this.lenBlock.length = valueBlockBuf.byteLength;
2207
+ const lenBlockBuf = this.lenBlock.toBER(sizeOnly);
2208
+ _writer.write(lenBlockBuf);
2209
+ _writer.write(valueBlockBuf);
2210
+ }
2211
+ if (!writer) {
2212
+ return _writer.final();
2213
+ }
2214
+ return EMPTY_BUFFER;
2215
+ }
2216
+ toJSON() {
2217
+ const object = {
2218
+ ...super.toJSON(),
2219
+ idBlock: this.idBlock.toJSON(),
2220
+ lenBlock: this.lenBlock.toJSON(),
2221
+ valueBlock: this.valueBlock.toJSON(),
2222
+ name: this.name,
2223
+ optional: this.optional,
2224
+ };
2225
+ if (this.primitiveSchema)
2226
+ object.primitiveSchema = this.primitiveSchema.toJSON();
2227
+ return object;
2228
+ }
2229
+ toString(encoding = "ascii") {
2230
+ if (encoding === "ascii") {
2231
+ return this.onAsciiEncoding();
2232
+ }
2233
+ return Convert.ToHex(this.toBER());
2234
+ }
2235
+ onAsciiEncoding() {
2236
+ const name = this.constructor.NAME;
2237
+ const value = Convert.ToHex(this.valueBlock.valueBeforeDecodeView);
2238
+ return `${name} : ${value}`;
2239
+ }
2240
+ isEqual(other) {
2241
+ if (this === other) {
2242
+ return true;
2243
+ }
2244
+ if (!(other instanceof this.constructor)) {
2245
+ return false;
2246
+ }
2247
+ const thisRaw = this.toBER();
2248
+ const otherRaw = other.toBER();
2249
+ return isEqualBuffer(thisRaw, otherRaw);
2250
+ }
2251
+ }
2252
+ BaseBlock.NAME = "BaseBlock";
2253
+ function prepareIndefiniteForm(baseBlock) {
2254
+ var _a;
2255
+ if (baseBlock instanceof typeStore.Constructed) {
2256
+ for (const value of baseBlock.valueBlock.value) {
2257
+ if (prepareIndefiniteForm(value)) {
2258
+ baseBlock.lenBlock.isIndefiniteForm = true;
2259
+ }
2260
+ }
2261
+ }
2262
+ return !!((_a = baseBlock.lenBlock) === null || _a === void 0 ? void 0 : _a.isIndefiniteForm);
2263
+ }
2264
+
2265
+ class BaseStringBlock extends BaseBlock {
2266
+ getValue() {
2267
+ return this.valueBlock.value;
2268
+ }
2269
+ setValue(value) {
2270
+ this.valueBlock.value = value;
2271
+ }
2272
+ constructor({ value = EMPTY_STRING, ...parameters } = {}, stringValueBlockType) {
2273
+ super(parameters, stringValueBlockType);
2274
+ if (value) {
2275
+ this.fromString(value);
2276
+ }
2277
+ }
2278
+ fromBER(inputBuffer, inputOffset, inputLength) {
2279
+ const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, (this.lenBlock.isIndefiniteForm)
2280
+ ? inputLength
2281
+ : this.lenBlock.length);
2282
+ if (resultOffset === -1) {
2283
+ this.error = this.valueBlock.error;
2284
+ return resultOffset;
2285
+ }
2286
+ this.fromBuffer(this.valueBlock.valueHexView);
2287
+ if (!this.idBlock.error.length)
2288
+ this.blockLength += this.idBlock.blockLength;
2289
+ if (!this.lenBlock.error.length)
2290
+ this.blockLength += this.lenBlock.blockLength;
2291
+ if (!this.valueBlock.error.length)
2292
+ this.blockLength += this.valueBlock.blockLength;
2293
+ return resultOffset;
2294
+ }
2295
+ onAsciiEncoding() {
2296
+ return `${this.constructor.NAME} : '${this.valueBlock.value}'`;
2297
+ }
2298
+ }
2299
+ BaseStringBlock.NAME = "BaseStringBlock";
2300
+
2301
+ class LocalPrimitiveValueBlock extends HexBlock(ValueBlock) {
2302
+ constructor({ isHexOnly = true, ...parameters } = {}) {
2303
+ super(parameters);
2304
+ this.isHexOnly = isHexOnly;
2305
+ }
2306
+ }
2307
+ LocalPrimitiveValueBlock.NAME = "PrimitiveValueBlock";
2308
+
2309
+ var _a$w;
2310
+ class Primitive extends BaseBlock {
2311
+ constructor(parameters = {}) {
2312
+ super(parameters, LocalPrimitiveValueBlock);
2313
+ this.idBlock.isConstructed = false;
2314
+ }
2315
+ }
2316
+ _a$w = Primitive;
2317
+ (() => {
2318
+ typeStore.Primitive = _a$w;
2319
+ })();
2320
+ Primitive.NAME = "PRIMITIVE";
2321
+
2322
+ const DEFAULT_MAX_DEPTH = 100;
2323
+ const DEFAULT_MAX_NODES = 10000;
2324
+ const DEFAULT_MAX_CONTENT_LENGTH = 16 * 1024 * 1024;
2325
+ const MAX_DEPTH_EXCEEDED_ERROR = "Maximum ASN.1 nesting depth exceeded";
2326
+ const MAX_NODES_EXCEEDED_ERROR = "Maximum ASN.1 node count exceeded";
2327
+ const MAX_CONTENT_LENGTH_EXCEEDED_ERROR = "Maximum ASN.1 content length exceeded";
2328
+ function createFromBerContext(options = {}) {
2329
+ var _a, _b, _c;
2330
+ return {
2331
+ depth: 0,
2332
+ maxDepth: (_a = options.maxDepth) !== null && _a !== void 0 ? _a : DEFAULT_MAX_DEPTH,
2333
+ nodesCount: 0,
2334
+ maxNodes: (_b = options.maxNodes) !== null && _b !== void 0 ? _b : DEFAULT_MAX_NODES,
2335
+ maxContentLength: (_c = options.maxContentLength) !== null && _c !== void 0 ? _c : DEFAULT_MAX_CONTENT_LENGTH,
2336
+ };
2337
+ }
2338
+ function createErrorResult(error) {
2339
+ const result = new BaseBlock({}, ValueBlock);
2340
+ result.error = error;
2341
+ return {
2342
+ offset: -1,
2343
+ result,
2344
+ };
2345
+ }
2346
+ function checkNodesLimit(context) {
2347
+ context.nodesCount += 1;
2348
+ if (context.nodesCount > context.maxNodes) {
2349
+ return MAX_NODES_EXCEEDED_ERROR;
2350
+ }
2351
+ return undefined;
2352
+ }
2353
+ function checkContentLengthLimit(inputLength, context) {
2354
+ if (inputLength > context.maxContentLength) {
2355
+ return MAX_CONTENT_LENGTH_EXCEEDED_ERROR;
2356
+ }
2357
+ return undefined;
2358
+ }
2359
+ function localFromBERWithChildContext(inputBuffer, inputOffset, inputLength, context) {
2360
+ const childDepth = context.depth + 1;
2361
+ if (childDepth > context.maxDepth) {
2362
+ return createErrorResult(MAX_DEPTH_EXCEEDED_ERROR);
2363
+ }
2364
+ context.depth = childDepth;
2365
+ try {
2366
+ return localFromBER(inputBuffer, inputOffset, inputLength, context);
2367
+ }
2368
+ finally {
2369
+ context.depth -= 1;
2370
+ }
2371
+ }
2372
+ function localChangeType(inputObject, newType) {
2373
+ if (inputObject instanceof newType) {
2374
+ return inputObject;
2375
+ }
2376
+ const newObject = new newType();
2377
+ newObject.idBlock = inputObject.idBlock;
2378
+ newObject.lenBlock = inputObject.lenBlock;
2379
+ newObject.warnings = inputObject.warnings;
2380
+ newObject.valueBeforeDecodeView = inputObject.valueBeforeDecodeView;
2381
+ return newObject;
2382
+ }
2383
+ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.length, context = createFromBerContext()) {
2384
+ const incomingOffset = inputOffset;
2385
+ let returnObject = new BaseBlock({}, ValueBlock);
2386
+ const baseBlock = new LocalBaseBlock();
2387
+ if (!checkBufferParams(baseBlock, inputBuffer, inputOffset, inputLength)) {
2388
+ returnObject.error = baseBlock.error;
2389
+ return {
2390
+ offset: -1,
2391
+ result: returnObject,
2392
+ };
2393
+ }
2394
+ const intBuffer = inputBuffer.subarray(inputOffset, inputOffset + inputLength);
2395
+ if (!intBuffer.length) {
2396
+ returnObject.error = "Zero buffer length";
2397
+ return {
2398
+ offset: -1,
2399
+ result: returnObject,
2400
+ };
2401
+ }
2402
+ const nodesLimitError = checkNodesLimit(context);
2403
+ if (nodesLimitError) {
2404
+ returnObject.error = nodesLimitError;
2405
+ return {
2406
+ offset: -1,
2407
+ result: returnObject,
2408
+ };
2409
+ }
2410
+ let resultOffset = returnObject.idBlock.fromBER(inputBuffer, inputOffset, inputLength);
2411
+ if (returnObject.idBlock.warnings.length) {
2412
+ returnObject.warnings.concat(returnObject.idBlock.warnings);
2413
+ }
2414
+ if (resultOffset === -1) {
2415
+ returnObject.error = returnObject.idBlock.error;
2416
+ return {
2417
+ offset: -1,
2418
+ result: returnObject,
2419
+ };
2420
+ }
2421
+ inputOffset = resultOffset;
2422
+ inputLength -= returnObject.idBlock.blockLength;
2423
+ resultOffset = returnObject.lenBlock.fromBER(inputBuffer, inputOffset, inputLength);
2424
+ if (returnObject.lenBlock.warnings.length) {
2425
+ returnObject.warnings.concat(returnObject.lenBlock.warnings);
2426
+ }
2427
+ if (resultOffset === -1) {
2428
+ returnObject.error = returnObject.lenBlock.error;
2429
+ return {
2430
+ offset: -1,
2431
+ result: returnObject,
2432
+ };
2433
+ }
2434
+ inputOffset = resultOffset;
2435
+ inputLength -= returnObject.lenBlock.blockLength;
2436
+ const valueLength = returnObject.lenBlock.isIndefiniteForm ? inputLength : returnObject.lenBlock.length;
2437
+ const contentLengthError = checkContentLengthLimit(valueLength, context);
2438
+ if (contentLengthError) {
2439
+ returnObject.error = contentLengthError;
2440
+ return {
2441
+ offset: -1,
2442
+ result: returnObject,
2443
+ };
2444
+ }
2445
+ if (!returnObject.idBlock.isConstructed
2446
+ && returnObject.lenBlock.isIndefiniteForm) {
2447
+ returnObject.error = "Indefinite length form used for primitive encoding form";
2448
+ return {
2449
+ offset: -1,
2450
+ result: returnObject,
2451
+ };
2452
+ }
2453
+ let newASN1Type = BaseBlock;
2454
+ switch (returnObject.idBlock.tagClass) {
2455
+ case 1:
2456
+ if ((returnObject.idBlock.tagNumber >= 37)
2457
+ && (returnObject.idBlock.isHexOnly === false)) {
2458
+ returnObject.error = "UNIVERSAL 37 and upper tags are reserved by ASN.1 standard";
2459
+ return {
2460
+ offset: -1,
2461
+ result: returnObject,
2462
+ };
2463
+ }
2464
+ switch (returnObject.idBlock.tagNumber) {
2465
+ case 0:
2466
+ if ((returnObject.idBlock.isConstructed)
2467
+ && (returnObject.lenBlock.length > 0)) {
2468
+ returnObject.error = "Type [UNIVERSAL 0] is reserved";
2469
+ return {
2470
+ offset: -1,
2471
+ result: returnObject,
2472
+ };
2473
+ }
2474
+ newASN1Type = typeStore.EndOfContent;
2475
+ break;
2476
+ case 1:
2477
+ newASN1Type = typeStore.Boolean;
2478
+ break;
2479
+ case 2:
2480
+ newASN1Type = typeStore.Integer;
2481
+ break;
2482
+ case 3:
2483
+ newASN1Type = typeStore.BitString;
2484
+ break;
2485
+ case 4:
2486
+ newASN1Type = typeStore.OctetString;
2487
+ break;
2488
+ case 5:
2489
+ newASN1Type = typeStore.Null;
2490
+ break;
2491
+ case 6:
2492
+ newASN1Type = typeStore.ObjectIdentifier;
2493
+ break;
2494
+ case 10:
2495
+ newASN1Type = typeStore.Enumerated;
2496
+ break;
2497
+ case 12:
2498
+ newASN1Type = typeStore.Utf8String;
2499
+ break;
2500
+ case 13:
2501
+ newASN1Type = typeStore.RelativeObjectIdentifier;
2502
+ break;
2503
+ case 14:
2504
+ newASN1Type = typeStore.TIME;
2505
+ break;
2506
+ case 15:
2507
+ returnObject.error = "[UNIVERSAL 15] is reserved by ASN.1 standard";
2508
+ return {
2509
+ offset: -1,
2510
+ result: returnObject,
2511
+ };
2512
+ case 16:
2513
+ newASN1Type = typeStore.Sequence;
2514
+ break;
2515
+ case 17:
2516
+ newASN1Type = typeStore.Set;
2517
+ break;
2518
+ case 18:
2519
+ newASN1Type = typeStore.NumericString;
2520
+ break;
2521
+ case 19:
2522
+ newASN1Type = typeStore.PrintableString;
2523
+ break;
2524
+ case 20:
2525
+ newASN1Type = typeStore.TeletexString;
2526
+ break;
2527
+ case 21:
2528
+ newASN1Type = typeStore.VideotexString;
2529
+ break;
2530
+ case 22:
2531
+ newASN1Type = typeStore.IA5String;
2532
+ break;
2533
+ case 23:
2534
+ newASN1Type = typeStore.UTCTime;
2535
+ break;
2536
+ case 24:
2537
+ newASN1Type = typeStore.GeneralizedTime;
2538
+ break;
2539
+ case 25:
2540
+ newASN1Type = typeStore.GraphicString;
2541
+ break;
2542
+ case 26:
2543
+ newASN1Type = typeStore.VisibleString;
2544
+ break;
2545
+ case 27:
2546
+ newASN1Type = typeStore.GeneralString;
2547
+ break;
2548
+ case 28:
2549
+ newASN1Type = typeStore.UniversalString;
2550
+ break;
2551
+ case 29:
2552
+ newASN1Type = typeStore.CharacterString;
2553
+ break;
2554
+ case 30:
2555
+ newASN1Type = typeStore.BmpString;
2556
+ break;
2557
+ case 31:
2558
+ newASN1Type = typeStore.DATE;
2559
+ break;
2560
+ case 32:
2561
+ newASN1Type = typeStore.TimeOfDay;
2562
+ break;
2563
+ case 33:
2564
+ newASN1Type = typeStore.DateTime;
2565
+ break;
2566
+ case 34:
2567
+ newASN1Type = typeStore.Duration;
2568
+ break;
2569
+ default: {
2570
+ const newObject = returnObject.idBlock.isConstructed
2571
+ ? new typeStore.Constructed()
2572
+ : new typeStore.Primitive();
2573
+ newObject.idBlock = returnObject.idBlock;
2574
+ newObject.lenBlock = returnObject.lenBlock;
2575
+ newObject.warnings = returnObject.warnings;
2576
+ returnObject = newObject;
2577
+ }
2578
+ }
2579
+ break;
2580
+ case 2:
2581
+ case 3:
2582
+ case 4:
2583
+ default: {
2584
+ newASN1Type = returnObject.idBlock.isConstructed
2585
+ ? typeStore.Constructed
2586
+ : typeStore.Primitive;
2587
+ }
2588
+ }
2589
+ returnObject = localChangeType(returnObject, newASN1Type);
2590
+ resultOffset = returnObject.fromBER(inputBuffer, inputOffset, valueLength, context);
2591
+ returnObject.valueBeforeDecodeView = inputBuffer.subarray(incomingOffset, incomingOffset + returnObject.blockLength);
2592
+ return {
2593
+ offset: resultOffset,
2594
+ result: returnObject,
2595
+ };
2596
+ }
2597
+ function fromBER(inputBuffer, options = {}) {
2598
+ if (!inputBuffer.byteLength) {
2599
+ const result = new BaseBlock({}, ValueBlock);
2600
+ result.error = "Input buffer has zero length";
2601
+ return {
2602
+ offset: -1,
2603
+ result,
2604
+ };
2605
+ }
2606
+ return localFromBER(BufferSourceConverter.toUint8Array(inputBuffer).slice(), 0, inputBuffer.byteLength, createFromBerContext(options));
2607
+ }
2608
+
2609
+ function checkLen(indefiniteLength, length) {
2610
+ if (indefiniteLength) {
2611
+ return 1;
2612
+ }
2613
+ return length;
2614
+ }
2615
+ class LocalConstructedValueBlock extends ValueBlock {
2616
+ constructor({ value = [], isIndefiniteForm = false, ...parameters } = {}) {
2617
+ super(parameters);
2618
+ this.value = value;
2619
+ this.isIndefiniteForm = isIndefiniteForm;
2620
+ }
2621
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
2622
+ const view = BufferSourceConverter.toUint8Array(inputBuffer);
2623
+ const parseContext = context !== null && context !== void 0 ? context : createFromBerContext();
2624
+ if (!checkBufferParams(this, view, inputOffset, inputLength)) {
2625
+ return -1;
2626
+ }
2627
+ this.valueBeforeDecodeView = view.subarray(inputOffset, inputOffset + inputLength);
2628
+ if (this.valueBeforeDecodeView.length === 0) {
2629
+ this.warnings.push("Zero buffer length");
2630
+ return inputOffset;
2631
+ }
2632
+ let currentOffset = inputOffset;
2633
+ while (checkLen(this.isIndefiniteForm, inputLength) > 0) {
2634
+ const returnObject = localFromBERWithChildContext(view, currentOffset, inputLength, parseContext);
2635
+ if (returnObject.offset === -1) {
2636
+ this.error = returnObject.result.error;
2637
+ this.warnings.concat(returnObject.result.warnings);
2638
+ return -1;
2639
+ }
2640
+ currentOffset = returnObject.offset;
2641
+ this.blockLength += returnObject.result.blockLength;
2642
+ inputLength -= returnObject.result.blockLength;
2643
+ this.value.push(returnObject.result);
2644
+ if (this.isIndefiniteForm && returnObject.result.constructor.NAME === END_OF_CONTENT_NAME) {
2645
+ break;
2646
+ }
2647
+ }
2648
+ if (this.isIndefiniteForm) {
2649
+ if (this.value[this.value.length - 1].constructor.NAME === END_OF_CONTENT_NAME) {
2650
+ this.value.pop();
2651
+ }
2652
+ else {
2653
+ this.warnings.push("No EndOfContent block encoded");
2654
+ }
2655
+ }
2656
+ return currentOffset;
2657
+ }
2658
+ toBER(sizeOnly, writer) {
2659
+ const _writer = writer || new ViewWriter();
2660
+ for (let i = 0; i < this.value.length; i++) {
2661
+ this.value[i].toBER(sizeOnly, _writer);
2662
+ }
2663
+ if (!writer) {
2664
+ return _writer.final();
2665
+ }
2666
+ return EMPTY_BUFFER;
2667
+ }
2668
+ toJSON() {
2669
+ const object = {
2670
+ ...super.toJSON(),
2671
+ isIndefiniteForm: this.isIndefiniteForm,
2672
+ value: [],
2673
+ };
2674
+ for (const value of this.value) {
2675
+ object.value.push(value.toJSON());
2676
+ }
2677
+ return object;
2678
+ }
2679
+ }
2680
+ LocalConstructedValueBlock.NAME = "ConstructedValueBlock";
2681
+
2682
+ var _a$v;
2683
+ class Constructed extends BaseBlock {
2684
+ constructor(parameters = {}) {
2685
+ super(parameters, LocalConstructedValueBlock);
2686
+ this.idBlock.isConstructed = true;
2687
+ }
2688
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
2689
+ this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
2690
+ const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, (this.lenBlock.isIndefiniteForm) ? inputLength : this.lenBlock.length, context);
2691
+ if (resultOffset === -1) {
2692
+ this.error = this.valueBlock.error;
2693
+ return resultOffset;
2694
+ }
2695
+ if (!this.idBlock.error.length)
2696
+ this.blockLength += this.idBlock.blockLength;
2697
+ if (!this.lenBlock.error.length)
2698
+ this.blockLength += this.lenBlock.blockLength;
2699
+ if (!this.valueBlock.error.length)
2700
+ this.blockLength += this.valueBlock.blockLength;
2701
+ return resultOffset;
2702
+ }
2703
+ onAsciiEncoding() {
2704
+ const values = [];
2705
+ for (const value of this.valueBlock.value) {
2706
+ values.push(value.toString("ascii").split("\n").map((o) => ` ${o}`).join("\n"));
2707
+ }
2708
+ const blockName = this.idBlock.tagClass === 3
2709
+ ? `[${this.idBlock.tagNumber}]`
2710
+ : this.constructor.NAME;
2711
+ return values.length
2712
+ ? `${blockName} :\n${values.join("\n")}`
2713
+ : `${blockName} :`;
2714
+ }
2715
+ }
2716
+ _a$v = Constructed;
2717
+ (() => {
2718
+ typeStore.Constructed = _a$v;
2719
+ })();
2720
+ Constructed.NAME = "CONSTRUCTED";
2721
+
2722
+ class LocalEndOfContentValueBlock extends ValueBlock {
2723
+ fromBER(inputBuffer, inputOffset, _inputLength) {
2724
+ return inputOffset;
2725
+ }
2726
+ toBER(_sizeOnly) {
2727
+ return EMPTY_BUFFER;
2728
+ }
2729
+ }
2730
+ LocalEndOfContentValueBlock.override = "EndOfContentValueBlock";
2731
+
2732
+ var _a$u;
2733
+ class EndOfContent extends BaseBlock {
2734
+ constructor(parameters = {}) {
2735
+ super(parameters, LocalEndOfContentValueBlock);
2736
+ this.idBlock.tagClass = 1;
2737
+ this.idBlock.tagNumber = 0;
2738
+ }
2739
+ }
2740
+ _a$u = EndOfContent;
2741
+ (() => {
2742
+ typeStore.EndOfContent = _a$u;
2743
+ })();
2744
+ EndOfContent.NAME = END_OF_CONTENT_NAME;
2745
+
2746
+ var _a$t;
2747
+ class Null extends BaseBlock {
2748
+ constructor(parameters = {}) {
2749
+ super(parameters, ValueBlock);
2750
+ this.idBlock.tagClass = 1;
2751
+ this.idBlock.tagNumber = 5;
2752
+ }
2753
+ fromBER(inputBuffer, inputOffset, inputLength) {
2754
+ if (this.lenBlock.length > 0)
2755
+ this.warnings.push("Non-zero length of value block for Null type");
2756
+ if (!this.idBlock.error.length)
2757
+ this.blockLength += this.idBlock.blockLength;
2758
+ if (!this.lenBlock.error.length)
2759
+ this.blockLength += this.lenBlock.blockLength;
2760
+ this.blockLength += inputLength;
2761
+ if ((inputOffset + inputLength) > inputBuffer.byteLength) {
2762
+ this.error = "End of input reached before message was fully decoded (inconsistent offset and length values)";
2763
+ return -1;
2764
+ }
2765
+ return (inputOffset + inputLength);
2766
+ }
2767
+ toBER(sizeOnly, writer) {
2768
+ const retBuf = new ArrayBuffer(2);
2769
+ if (!sizeOnly) {
2770
+ const retView = new Uint8Array(retBuf);
2771
+ retView[0] = 0x05;
2772
+ retView[1] = 0x00;
2773
+ }
2774
+ if (writer) {
2775
+ writer.write(retBuf);
2776
+ }
2777
+ return retBuf;
2778
+ }
2779
+ onAsciiEncoding() {
2780
+ return `${this.constructor.NAME}`;
2781
+ }
2782
+ }
2783
+ _a$t = Null;
2784
+ (() => {
2785
+ typeStore.Null = _a$t;
2786
+ })();
2787
+ Null.NAME = "NULL";
2788
+
2789
+ class LocalBooleanValueBlock extends HexBlock(ValueBlock) {
2790
+ get value() {
2791
+ for (const octet of this.valueHexView) {
2792
+ if (octet > 0) {
2793
+ return true;
2794
+ }
2795
+ }
2796
+ return false;
2797
+ }
2798
+ set value(value) {
2799
+ this.valueHexView[0] = value ? 0xFF : 0x00;
2800
+ }
2801
+ constructor({ value, ...parameters } = {}) {
2802
+ super(parameters);
2803
+ if (parameters.valueHex) {
2804
+ this.valueHexView = BufferSourceConverter.toUint8Array(parameters.valueHex);
2805
+ }
2806
+ else {
2807
+ this.valueHexView = new Uint8Array(1);
2808
+ }
2809
+ if (value) {
2810
+ this.value = value;
2811
+ }
2812
+ }
2813
+ fromBER(inputBuffer, inputOffset, inputLength) {
2814
+ const inputView = BufferSourceConverter.toUint8Array(inputBuffer);
2815
+ if (!checkBufferParams(this, inputView, inputOffset, inputLength)) {
2816
+ return -1;
2817
+ }
2818
+ this.valueHexView = inputView.subarray(inputOffset, inputOffset + inputLength);
2819
+ if (inputLength > 1)
2820
+ this.warnings.push("Boolean value encoded in more then 1 octet");
2821
+ this.isHexOnly = true;
2822
+ utilDecodeTC.call(this);
2823
+ this.blockLength = inputLength;
2824
+ return (inputOffset + inputLength);
2825
+ }
2826
+ toBER() {
2827
+ return this.valueHexView.slice();
2828
+ }
2829
+ toJSON() {
2830
+ return {
2831
+ ...super.toJSON(),
2832
+ value: this.value,
2833
+ };
2834
+ }
2835
+ }
2836
+ LocalBooleanValueBlock.NAME = "BooleanValueBlock";
2837
+
2838
+ var _a$s;
2839
+ class Boolean$1 extends BaseBlock {
2840
+ getValue() {
2841
+ return this.valueBlock.value;
2842
+ }
2843
+ setValue(value) {
2844
+ this.valueBlock.value = value;
2845
+ }
2846
+ constructor(parameters = {}) {
2847
+ super(parameters, LocalBooleanValueBlock);
2848
+ this.idBlock.tagClass = 1;
2849
+ this.idBlock.tagNumber = 1;
2850
+ }
2851
+ onAsciiEncoding() {
2852
+ return `${this.constructor.NAME} : ${this.getValue}`;
2853
+ }
2854
+ }
2855
+ _a$s = Boolean$1;
2856
+ (() => {
2857
+ typeStore.Boolean = _a$s;
2858
+ })();
2859
+ Boolean$1.NAME = "BOOLEAN";
2860
+
2861
+ class LocalOctetStringValueBlock extends HexBlock(LocalConstructedValueBlock) {
2862
+ constructor({ isConstructed = false, ...parameters } = {}) {
2863
+ super(parameters);
2864
+ this.isConstructed = isConstructed;
2865
+ }
2866
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
2867
+ let resultOffset = 0;
2868
+ if (this.isConstructed) {
2869
+ this.isHexOnly = false;
2870
+ resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength, context);
2871
+ if (resultOffset === -1)
2872
+ return resultOffset;
2873
+ for (let i = 0; i < this.value.length; i++) {
2874
+ const currentBlockName = this.value[i].constructor.NAME;
2875
+ if (currentBlockName === END_OF_CONTENT_NAME) {
2876
+ if (this.isIndefiniteForm)
2877
+ break;
2878
+ else {
2879
+ this.error = "EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only";
2880
+ return -1;
2881
+ }
2882
+ }
2883
+ if (currentBlockName !== OCTET_STRING_NAME) {
2884
+ this.error = "OCTET STRING may consists of OCTET STRINGs only";
2885
+ return -1;
2886
+ }
2887
+ }
2888
+ }
2889
+ else {
2890
+ this.isHexOnly = true;
2891
+ resultOffset = super.fromBER(inputBuffer, inputOffset, inputLength);
2892
+ this.blockLength = inputLength;
2893
+ }
2894
+ return resultOffset;
2895
+ }
2896
+ toBER(sizeOnly, writer) {
2897
+ if (this.isConstructed)
2898
+ return LocalConstructedValueBlock.prototype.toBER.call(this, sizeOnly, writer);
2899
+ return sizeOnly
2900
+ ? new ArrayBuffer(this.valueHexView.byteLength)
2901
+ : this.valueHexView.slice().buffer;
2902
+ }
2903
+ toJSON() {
2904
+ return {
2905
+ ...super.toJSON(),
2906
+ isConstructed: this.isConstructed,
2907
+ };
2908
+ }
2909
+ }
2910
+ LocalOctetStringValueBlock.NAME = "OctetStringValueBlock";
2911
+
2912
+ var _a$r;
2913
+ class OctetString extends BaseBlock {
2914
+ constructor({ idBlock = {}, lenBlock = {}, ...parameters } = {}) {
2915
+ var _b, _c;
2916
+ (_b = parameters.isConstructed) !== null && _b !== void 0 ? _b : (parameters.isConstructed = !!((_c = parameters.value) === null || _c === void 0 ? void 0 : _c.length));
2917
+ super({
2918
+ idBlock: {
2919
+ isConstructed: parameters.isConstructed,
2920
+ ...idBlock,
2921
+ },
2922
+ lenBlock: {
2923
+ ...lenBlock,
2924
+ isIndefiniteForm: !!parameters.isIndefiniteForm,
2925
+ },
2926
+ ...parameters,
2927
+ }, LocalOctetStringValueBlock);
2928
+ this.idBlock.tagClass = 1;
2929
+ this.idBlock.tagNumber = 4;
2930
+ }
2931
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
2932
+ this.valueBlock.isConstructed = this.idBlock.isConstructed;
2933
+ this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
2934
+ if (inputLength === 0) {
2935
+ if (this.idBlock.error.length === 0)
2936
+ this.blockLength += this.idBlock.blockLength;
2937
+ if (this.lenBlock.error.length === 0)
2938
+ this.blockLength += this.lenBlock.blockLength;
2939
+ return inputOffset;
2940
+ }
2941
+ if (!this.valueBlock.isConstructed) {
2942
+ const view = inputBuffer instanceof ArrayBuffer ? new Uint8Array(inputBuffer) : inputBuffer;
2943
+ const buf = view.subarray(inputOffset, inputOffset + inputLength);
2944
+ try {
2945
+ if (buf.byteLength) {
2946
+ const parseContext = context !== null && context !== void 0 ? context : createFromBerContext();
2947
+ const asn = localFromBERWithChildContext(buf, 0, buf.byteLength, parseContext);
2948
+ if (asn.offset !== -1 && asn.offset === inputLength) {
2949
+ this.valueBlock.value = [asn.result];
2950
+ }
2951
+ }
2952
+ }
2953
+ catch {
2954
+ }
2955
+ }
2956
+ return super.fromBER(inputBuffer, inputOffset, inputLength, context);
2957
+ }
2958
+ onAsciiEncoding() {
2959
+ if (this.valueBlock.isConstructed || (this.valueBlock.value && this.valueBlock.value.length)) {
2960
+ return Constructed.prototype.onAsciiEncoding.call(this);
2961
+ }
2962
+ const name = this.constructor.NAME;
2963
+ const value = Convert.ToHex(this.valueBlock.valueHexView);
2964
+ return `${name} : ${value}`;
2965
+ }
2966
+ getValue() {
2967
+ if (!this.idBlock.isConstructed) {
2968
+ return this.valueBlock.valueHexView.slice().buffer;
2969
+ }
2970
+ const array = [];
2971
+ for (const content of this.valueBlock.value) {
2972
+ if (content instanceof _a$r) {
2973
+ array.push(content.valueBlock.valueHexView);
2974
+ }
2975
+ }
2976
+ return BufferSourceConverter.concat(array);
2977
+ }
2978
+ }
2979
+ _a$r = OctetString;
2980
+ (() => {
2981
+ typeStore.OctetString = _a$r;
2982
+ })();
2983
+ OctetString.NAME = OCTET_STRING_NAME;
2984
+
2985
+ class LocalBitStringValueBlock extends HexBlock(LocalConstructedValueBlock) {
2986
+ constructor({ unusedBits = 0, isConstructed = false, ...parameters } = {}) {
2987
+ super(parameters);
2988
+ this.unusedBits = unusedBits;
2989
+ this.isConstructed = isConstructed;
2990
+ this.blockLength = this.valueHexView.byteLength;
2991
+ }
2992
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
2993
+ if (!inputLength) {
2994
+ return inputOffset;
2995
+ }
2996
+ let resultOffset = -1;
2997
+ if (this.isConstructed) {
2998
+ resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength, context);
2999
+ if (resultOffset === -1)
3000
+ return resultOffset;
3001
+ for (const value of this.value) {
3002
+ const currentBlockName = value.constructor.NAME;
3003
+ if (currentBlockName === END_OF_CONTENT_NAME) {
3004
+ if (this.isIndefiniteForm)
3005
+ break;
3006
+ else {
3007
+ this.error = "EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only";
3008
+ return -1;
3009
+ }
3010
+ }
3011
+ if (currentBlockName !== BIT_STRING_NAME) {
3012
+ this.error = "BIT STRING may consists of BIT STRINGs only";
3013
+ return -1;
3014
+ }
3015
+ const valueBlock = value.valueBlock;
3016
+ if ((this.unusedBits > 0) && (valueBlock.unusedBits > 0)) {
3017
+ this.error = "Using of \"unused bits\" inside constructive BIT STRING allowed for least one only";
3018
+ return -1;
3019
+ }
3020
+ this.unusedBits = valueBlock.unusedBits;
3021
+ }
3022
+ return resultOffset;
3023
+ }
3024
+ const inputView = BufferSourceConverter.toUint8Array(inputBuffer);
3025
+ if (!checkBufferParams(this, inputView, inputOffset, inputLength)) {
3026
+ return -1;
3027
+ }
3028
+ const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength);
3029
+ this.unusedBits = intBuffer[0];
3030
+ if (this.unusedBits > 7) {
3031
+ this.error = "Unused bits for BitString must be in range 0-7";
3032
+ return -1;
3033
+ }
3034
+ if (!this.unusedBits) {
3035
+ const buf = intBuffer.subarray(1);
3036
+ try {
3037
+ if (buf.byteLength) {
3038
+ const parseContext = context !== null && context !== void 0 ? context : createFromBerContext();
3039
+ const asn = localFromBERWithChildContext(buf, 0, buf.byteLength, parseContext);
3040
+ if (asn.offset !== -1 && asn.offset === (inputLength - 1)) {
3041
+ this.value = [asn.result];
3042
+ }
3043
+ }
3044
+ }
3045
+ catch {
3046
+ }
3047
+ }
3048
+ this.valueHexView = intBuffer.subarray(1);
3049
+ this.blockLength = intBuffer.length;
3050
+ return (inputOffset + inputLength);
3051
+ }
3052
+ toBER(sizeOnly, writer) {
3053
+ if (this.isConstructed) {
3054
+ return LocalConstructedValueBlock.prototype.toBER.call(this, sizeOnly, writer);
3055
+ }
3056
+ if (sizeOnly) {
3057
+ return new ArrayBuffer(this.valueHexView.byteLength + 1);
3058
+ }
3059
+ if (!this.valueHexView.byteLength) {
3060
+ const empty = new Uint8Array(1);
3061
+ empty[0] = 0;
3062
+ return empty.buffer;
3063
+ }
3064
+ const retView = new Uint8Array(this.valueHexView.length + 1);
3065
+ retView[0] = this.unusedBits;
3066
+ retView.set(this.valueHexView, 1);
3067
+ return retView.buffer;
3068
+ }
3069
+ toJSON() {
3070
+ return {
3071
+ ...super.toJSON(),
3072
+ unusedBits: this.unusedBits,
3073
+ isConstructed: this.isConstructed,
3074
+ };
3075
+ }
3076
+ }
3077
+ LocalBitStringValueBlock.NAME = "BitStringValueBlock";
3078
+
3079
+ var _a$q;
3080
+ class BitString extends BaseBlock {
3081
+ constructor({ idBlock = {}, lenBlock = {}, ...parameters } = {}) {
3082
+ var _b, _c;
3083
+ (_b = parameters.isConstructed) !== null && _b !== void 0 ? _b : (parameters.isConstructed = !!((_c = parameters.value) === null || _c === void 0 ? void 0 : _c.length));
3084
+ super({
3085
+ idBlock: {
3086
+ isConstructed: parameters.isConstructed,
3087
+ ...idBlock,
3088
+ },
3089
+ lenBlock: {
3090
+ ...lenBlock,
3091
+ isIndefiniteForm: !!parameters.isIndefiniteForm,
3092
+ },
3093
+ ...parameters,
3094
+ }, LocalBitStringValueBlock);
3095
+ this.idBlock.tagClass = 1;
3096
+ this.idBlock.tagNumber = 3;
3097
+ }
3098
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
3099
+ this.valueBlock.isConstructed = this.idBlock.isConstructed;
3100
+ this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
3101
+ return super.fromBER(inputBuffer, inputOffset, inputLength, context);
3102
+ }
3103
+ onAsciiEncoding() {
3104
+ if (this.valueBlock.isConstructed || (this.valueBlock.value && this.valueBlock.value.length)) {
3105
+ return Constructed.prototype.onAsciiEncoding.call(this);
3106
+ }
3107
+ else {
3108
+ const bits = [];
3109
+ const valueHex = this.valueBlock.valueHexView;
3110
+ for (const byte of valueHex) {
3111
+ bits.push(byte.toString(2).padStart(8, "0"));
3112
+ }
3113
+ const bitsStr = bits.join("");
3114
+ const name = this.constructor.NAME;
3115
+ const value = bitsStr.substring(0, bitsStr.length - this.valueBlock.unusedBits);
3116
+ return `${name} : ${value}`;
3117
+ }
3118
+ }
3119
+ }
3120
+ _a$q = BitString;
3121
+ (() => {
3122
+ typeStore.BitString = _a$q;
3123
+ })();
3124
+ BitString.NAME = BIT_STRING_NAME;
3125
+
3126
+ var _a$p;
3127
+ function viewAdd(first, second) {
3128
+ const c = new Uint8Array([0]);
3129
+ const firstView = new Uint8Array(first);
3130
+ const secondView = new Uint8Array(second);
3131
+ let firstViewCopy = firstView.slice(0);
3132
+ const firstViewCopyLength = firstViewCopy.length - 1;
3133
+ const secondViewCopy = secondView.slice(0);
3134
+ const secondViewCopyLength = secondViewCopy.length - 1;
3135
+ let value = 0;
3136
+ const max = (secondViewCopyLength < firstViewCopyLength) ? firstViewCopyLength : secondViewCopyLength;
3137
+ let counter = 0;
3138
+ for (let i = max; i >= 0; i--, counter++) {
3139
+ switch (true) {
3140
+ case (counter < secondViewCopy.length):
3141
+ value = firstViewCopy[firstViewCopyLength - counter] + secondViewCopy[secondViewCopyLength - counter] + c[0];
3142
+ break;
3143
+ default:
3144
+ value = firstViewCopy[firstViewCopyLength - counter] + c[0];
3145
+ }
3146
+ c[0] = value / 10;
3147
+ switch (true) {
3148
+ case (counter >= firstViewCopy.length):
3149
+ firstViewCopy = utilConcatView(new Uint8Array([value % 10]), firstViewCopy);
3150
+ break;
3151
+ default:
3152
+ firstViewCopy[firstViewCopyLength - counter] = value % 10;
3153
+ }
3154
+ }
3155
+ if (c[0] > 0)
3156
+ firstViewCopy = utilConcatView(c, firstViewCopy);
3157
+ return firstViewCopy;
3158
+ }
3159
+ function power2(n) {
3160
+ if (n >= powers2.length) {
3161
+ for (let p = powers2.length; p <= n; p++) {
3162
+ const c = new Uint8Array([0]);
3163
+ let digits = (powers2[p - 1]).slice(0);
3164
+ for (let i = (digits.length - 1); i >= 0; i--) {
3165
+ const newValue = new Uint8Array([(digits[i] << 1) + c[0]]);
3166
+ c[0] = newValue[0] / 10;
3167
+ digits[i] = newValue[0] % 10;
3168
+ }
3169
+ if (c[0] > 0)
3170
+ digits = utilConcatView(c, digits);
3171
+ powers2.push(digits);
3172
+ }
3173
+ }
3174
+ return powers2[n];
3175
+ }
3176
+ function viewSub(first, second) {
3177
+ let b = 0;
3178
+ const firstView = new Uint8Array(first);
3179
+ const secondView = new Uint8Array(second);
3180
+ const firstViewCopy = firstView.slice(0);
3181
+ const firstViewCopyLength = firstViewCopy.length - 1;
3182
+ const secondViewCopy = secondView.slice(0);
3183
+ const secondViewCopyLength = secondViewCopy.length - 1;
3184
+ let value;
3185
+ let counter = 0;
3186
+ for (let i = secondViewCopyLength; i >= 0; i--, counter++) {
3187
+ value = firstViewCopy[firstViewCopyLength - counter] - secondViewCopy[secondViewCopyLength - counter] - b;
3188
+ switch (true) {
3189
+ case (value < 0):
3190
+ b = 1;
3191
+ firstViewCopy[firstViewCopyLength - counter] = value + 10;
3192
+ break;
3193
+ default:
3194
+ b = 0;
3195
+ firstViewCopy[firstViewCopyLength - counter] = value;
3196
+ }
3197
+ }
3198
+ if (b > 0) {
3199
+ for (let i = (firstViewCopyLength - secondViewCopyLength + 1); i >= 0; i--, counter++) {
3200
+ value = firstViewCopy[firstViewCopyLength - counter] - b;
3201
+ if (value < 0) {
3202
+ b = 1;
3203
+ firstViewCopy[firstViewCopyLength - counter] = value + 10;
3204
+ }
3205
+ else {
3206
+ b = 0;
3207
+ firstViewCopy[firstViewCopyLength - counter] = value;
3208
+ break;
3209
+ }
3210
+ }
3211
+ }
3212
+ return firstViewCopy.slice();
3213
+ }
3214
+ class LocalIntegerValueBlock extends HexBlock(ValueBlock) {
3215
+ setValueHex() {
3216
+ if (this.valueHexView.length >= 4) {
3217
+ this.warnings.push("Too big Integer for decoding, hex only");
3218
+ this.isHexOnly = true;
3219
+ this._valueDec = 0;
3220
+ }
3221
+ else {
3222
+ this.isHexOnly = false;
3223
+ if (this.valueHexView.length > 0) {
3224
+ this._valueDec = utilDecodeTC.call(this);
3225
+ }
3226
+ }
3227
+ }
3228
+ constructor({ value, ...parameters } = {}) {
3229
+ super(parameters);
3230
+ this._valueDec = 0;
3231
+ if (parameters.valueHex) {
3232
+ this.setValueHex();
3233
+ }
3234
+ if (value !== undefined) {
3235
+ this.valueDec = value;
3236
+ }
3237
+ }
3238
+ set valueDec(v) {
3239
+ this._valueDec = v;
3240
+ this.isHexOnly = false;
3241
+ this.valueHexView = new Uint8Array(utilEncodeTC(v));
3242
+ }
3243
+ get valueDec() {
3244
+ return this._valueDec;
3245
+ }
3246
+ fromDER(inputBuffer, inputOffset, inputLength, expectedLength = 0) {
3247
+ const offset = this.fromBER(inputBuffer, inputOffset, inputLength);
3248
+ if (offset === -1)
3249
+ return offset;
3250
+ const view = this.valueHexView;
3251
+ if ((view[0] === 0x00) && ((view[1] & 0x80) !== 0)) {
3252
+ this.valueHexView = view.subarray(1);
3253
+ }
3254
+ else {
3255
+ if (expectedLength !== 0) {
3256
+ if (view.length < expectedLength) {
3257
+ if ((expectedLength - view.length) > 1)
3258
+ expectedLength = view.length + 1;
3259
+ this.valueHexView = view.subarray(expectedLength - view.length);
3260
+ }
3261
+ }
3262
+ }
3263
+ return offset;
3264
+ }
3265
+ toDER(sizeOnly = false) {
3266
+ const view = this.valueHexView;
3267
+ switch (true) {
3268
+ case ((view[0] & 0x80) !== 0):
3269
+ {
3270
+ const updatedView = new Uint8Array(this.valueHexView.length + 1);
3271
+ updatedView[0] = 0x00;
3272
+ updatedView.set(view, 1);
3273
+ this.valueHexView = updatedView;
3274
+ }
3275
+ break;
3276
+ case ((view[0] === 0x00) && ((view[1] & 0x80) === 0)):
3277
+ {
3278
+ this.valueHexView = this.valueHexView.subarray(1);
3279
+ }
3280
+ break;
3281
+ }
3282
+ return this.toBER(sizeOnly);
3283
+ }
3284
+ fromBER(inputBuffer, inputOffset, inputLength) {
3285
+ const resultOffset = super.fromBER(inputBuffer, inputOffset, inputLength);
3286
+ if (resultOffset === -1) {
3287
+ return resultOffset;
3288
+ }
3289
+ this.setValueHex();
3290
+ return resultOffset;
3291
+ }
3292
+ toBER(sizeOnly) {
3293
+ return sizeOnly
3294
+ ? new ArrayBuffer(this.valueHexView.length)
3295
+ : this.valueHexView.slice().buffer;
3296
+ }
3297
+ toJSON() {
3298
+ return {
3299
+ ...super.toJSON(),
3300
+ valueDec: this.valueDec,
3301
+ };
3302
+ }
3303
+ toString() {
3304
+ const firstBit = (this.valueHexView.length * 8) - 1;
3305
+ let digits = new Uint8Array((this.valueHexView.length * 8) / 3);
3306
+ let bitNumber = 0;
3307
+ let currentByte;
3308
+ const asn1View = this.valueHexView;
3309
+ let result = "";
3310
+ let flag = false;
3311
+ for (let byteNumber = (asn1View.byteLength - 1); byteNumber >= 0; byteNumber--) {
3312
+ currentByte = asn1View[byteNumber];
3313
+ for (let i = 0; i < 8; i++) {
3314
+ if ((currentByte & 1) === 1) {
3315
+ switch (bitNumber) {
3316
+ case firstBit:
3317
+ digits = viewSub(power2(bitNumber), digits);
3318
+ result = "-";
3319
+ break;
3320
+ default:
3321
+ digits = viewAdd(digits, power2(bitNumber));
3322
+ }
3323
+ }
3324
+ bitNumber++;
3325
+ currentByte >>= 1;
3326
+ }
3327
+ }
3328
+ for (let i = 0; i < digits.length; i++) {
3329
+ if (digits[i])
3330
+ flag = true;
3331
+ if (flag)
3332
+ result += digitsString.charAt(digits[i]);
3333
+ }
3334
+ if (flag === false)
3335
+ result += digitsString.charAt(0);
3336
+ return result;
3337
+ }
3338
+ }
3339
+ _a$p = LocalIntegerValueBlock;
3340
+ LocalIntegerValueBlock.NAME = "IntegerValueBlock";
3341
+ (() => {
3342
+ Object.defineProperty(_a$p.prototype, "valueHex", {
3343
+ set: function (v) {
3344
+ this.valueHexView = new Uint8Array(v);
3345
+ this.setValueHex();
3346
+ },
3347
+ get: function () {
3348
+ return this.valueHexView.slice().buffer;
3349
+ },
3350
+ });
3351
+ })();
3352
+
3353
+ var _a$o;
3354
+ class Integer extends BaseBlock {
3355
+ constructor(parameters = {}) {
3356
+ super(parameters, LocalIntegerValueBlock);
3357
+ this.idBlock.tagClass = 1;
3358
+ this.idBlock.tagNumber = 2;
3359
+ }
3360
+ toBigInt() {
3361
+ assertBigInt();
3362
+ return BigInt(this.valueBlock.toString());
3363
+ }
3364
+ static fromBigInt(value) {
3365
+ assertBigInt();
3366
+ const bigIntValue = BigInt(value);
3367
+ const writer = new ViewWriter();
3368
+ const hex = bigIntValue.toString(16).replace(/^-/, "");
3369
+ const view = new Uint8Array(Convert.FromHex(hex));
3370
+ if (bigIntValue < 0) {
3371
+ const first = new Uint8Array(view.length + (view[0] & 0x80 ? 1 : 0));
3372
+ first[0] |= 0x80;
3373
+ const firstInt = BigInt(`0x${Convert.ToHex(first)}`);
3374
+ const secondInt = firstInt + bigIntValue;
3375
+ const second = BufferSourceConverter.toUint8Array(Convert.FromHex(secondInt.toString(16)));
3376
+ second[0] |= 0x80;
3377
+ writer.write(second);
3378
+ }
3379
+ else {
3380
+ if (view[0] & 0x80) {
3381
+ writer.write(new Uint8Array([0]));
3382
+ }
3383
+ writer.write(view);
3384
+ }
3385
+ const res = new _a$o({ valueHex: writer.final() });
3386
+ return res;
3387
+ }
3388
+ convertToDER() {
3389
+ const integer = new _a$o({ valueHex: this.valueBlock.valueHexView });
3390
+ integer.valueBlock.toDER();
3391
+ return integer;
3392
+ }
3393
+ convertFromDER() {
3394
+ return new _a$o({
3395
+ valueHex: this.valueBlock.valueHexView[0] === 0
3396
+ ? this.valueBlock.valueHexView.subarray(1)
3397
+ : this.valueBlock.valueHexView,
3398
+ });
3399
+ }
3400
+ onAsciiEncoding() {
3401
+ return `${this.constructor.NAME} : ${this.valueBlock.toString()}`;
3402
+ }
3403
+ }
3404
+ _a$o = Integer;
3405
+ (() => {
3406
+ typeStore.Integer = _a$o;
3407
+ })();
3408
+ Integer.NAME = "INTEGER";
3409
+
3410
+ var _a$n;
3411
+ class Enumerated extends Integer {
3412
+ constructor(parameters = {}) {
3413
+ super(parameters);
3414
+ this.idBlock.tagClass = 1;
3415
+ this.idBlock.tagNumber = 10;
3416
+ }
3417
+ }
3418
+ _a$n = Enumerated;
3419
+ (() => {
3420
+ typeStore.Enumerated = _a$n;
3421
+ })();
3422
+ Enumerated.NAME = "ENUMERATED";
3423
+
3424
+ class LocalSidValueBlock extends HexBlock(ValueBlock) {
3425
+ constructor({ valueDec = -1, isFirstSid = false, ...parameters } = {}) {
3426
+ super(parameters);
3427
+ this.valueDec = valueDec;
3428
+ this.isFirstSid = isFirstSid;
3429
+ }
3430
+ fromBER(inputBuffer, inputOffset, inputLength) {
3431
+ if (!inputLength) {
3432
+ return inputOffset;
3433
+ }
3434
+ const inputView = BufferSourceConverter.toUint8Array(inputBuffer);
3435
+ if (!checkBufferParams(this, inputView, inputOffset, inputLength)) {
3436
+ return -1;
3437
+ }
3438
+ const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength);
3439
+ this.valueHexView = new Uint8Array(inputLength);
3440
+ for (let i = 0; i < inputLength; i++) {
3441
+ this.valueHexView[i] = intBuffer[i] & 0x7F;
3442
+ this.blockLength++;
3443
+ if ((intBuffer[i] & 0x80) === 0x00)
3444
+ break;
3445
+ }
3446
+ const tempView = new Uint8Array(this.blockLength);
3447
+ for (let i = 0; i < this.blockLength; i++) {
3448
+ tempView[i] = this.valueHexView[i];
3449
+ }
3450
+ this.valueHexView = tempView;
3451
+ if ((intBuffer[this.blockLength - 1] & 0x80) !== 0x00) {
3452
+ this.error = "End of input reached before message was fully decoded";
3453
+ return -1;
3454
+ }
3455
+ if (this.valueHexView[0] === 0x00)
3456
+ this.warnings.push("Needlessly long format of SID encoding");
3457
+ if (this.blockLength <= 8)
3458
+ this.valueDec = utilFromBase(this.valueHexView, 7);
3459
+ else {
3460
+ this.isHexOnly = true;
3461
+ this.warnings.push("Too big SID for decoding, hex only");
3462
+ }
3463
+ return (inputOffset + this.blockLength);
3464
+ }
3465
+ set valueBigInt(value) {
3466
+ assertBigInt();
3467
+ let bits = BigInt(value).toString(2);
3468
+ while (bits.length % 7) {
3469
+ bits = "0" + bits;
3470
+ }
3471
+ const bytes = new Uint8Array(bits.length / 7);
3472
+ for (let i = 0; i < bytes.length; i++) {
3473
+ bytes[i] = parseInt(bits.slice(i * 7, i * 7 + 7), 2) + (i + 1 < bytes.length ? 0x80 : 0);
3474
+ }
3475
+ this.fromBER(bytes.buffer, 0, bytes.length);
3476
+ }
3477
+ toBER(sizeOnly) {
3478
+ if (this.isHexOnly) {
3479
+ if (sizeOnly)
3480
+ return (new ArrayBuffer(this.valueHexView.byteLength));
3481
+ const curView = this.valueHexView;
3482
+ const retView = new Uint8Array(this.blockLength);
3483
+ for (let i = 0; i < (this.blockLength - 1); i++)
3484
+ retView[i] = curView[i] | 0x80;
3485
+ retView[this.blockLength - 1] = curView[this.blockLength - 1];
3486
+ return retView.buffer;
3487
+ }
3488
+ const encodedBuf = utilToBase(this.valueDec, 7);
3489
+ if (encodedBuf.byteLength === 0) {
3490
+ this.error = "Error during encoding SID value";
3491
+ return EMPTY_BUFFER;
3492
+ }
3493
+ const retView = new Uint8Array(encodedBuf.byteLength);
3494
+ if (!sizeOnly) {
3495
+ const encodedView = new Uint8Array(encodedBuf);
3496
+ const len = encodedBuf.byteLength - 1;
3497
+ for (let i = 0; i < len; i++)
3498
+ retView[i] = encodedView[i] | 0x80;
3499
+ retView[len] = encodedView[len];
3500
+ }
3501
+ return retView;
3502
+ }
3503
+ toString() {
3504
+ let result = "";
3505
+ if (this.isHexOnly)
3506
+ result = Convert.ToHex(this.valueHexView);
3507
+ else {
3508
+ if (this.isFirstSid) {
3509
+ let sidValue = this.valueDec;
3510
+ if (this.valueDec <= 39)
3511
+ result = "0.";
3512
+ else {
3513
+ if (this.valueDec <= 79) {
3514
+ result = "1.";
3515
+ sidValue -= 40;
3516
+ }
3517
+ else {
3518
+ result = "2.";
3519
+ sidValue -= 80;
3520
+ }
3521
+ }
3522
+ result += sidValue.toString();
3523
+ }
3524
+ else
3525
+ result = this.valueDec.toString();
3526
+ }
3527
+ return result;
3528
+ }
3529
+ toJSON() {
3530
+ return {
3531
+ ...super.toJSON(),
3532
+ valueDec: this.valueDec,
3533
+ isFirstSid: this.isFirstSid,
3534
+ };
3535
+ }
3536
+ }
3537
+ LocalSidValueBlock.NAME = "sidBlock";
3538
+
3539
+ class LocalObjectIdentifierValueBlock extends ValueBlock {
3540
+ constructor({ value = EMPTY_STRING, ...parameters } = {}) {
3541
+ super(parameters);
3542
+ this.value = [];
3543
+ if (value) {
3544
+ this.fromString(value);
3545
+ }
3546
+ }
3547
+ fromBER(inputBuffer, inputOffset, inputLength) {
3548
+ let resultOffset = inputOffset;
3549
+ while (inputLength > 0) {
3550
+ const sidBlock = new LocalSidValueBlock();
3551
+ resultOffset = sidBlock.fromBER(inputBuffer, resultOffset, inputLength);
3552
+ if (resultOffset === -1) {
3553
+ this.blockLength = 0;
3554
+ this.error = sidBlock.error;
3555
+ return resultOffset;
3556
+ }
3557
+ if (this.value.length === 0)
3558
+ sidBlock.isFirstSid = true;
3559
+ this.blockLength += sidBlock.blockLength;
3560
+ inputLength -= sidBlock.blockLength;
3561
+ this.value.push(sidBlock);
3562
+ }
3563
+ return resultOffset;
3564
+ }
3565
+ toBER(sizeOnly) {
3566
+ const retBuffers = [];
3567
+ for (let i = 0; i < this.value.length; i++) {
3568
+ const valueBuf = this.value[i].toBER(sizeOnly);
3569
+ if (valueBuf.byteLength === 0) {
3570
+ this.error = this.value[i].error;
3571
+ return EMPTY_BUFFER;
3572
+ }
3573
+ retBuffers.push(valueBuf);
3574
+ }
3575
+ return concat(retBuffers);
3576
+ }
3577
+ fromString(string) {
3578
+ this.value = [];
3579
+ let pos1 = 0;
3580
+ let pos2 = 0;
3581
+ let sid = "";
3582
+ let flag = false;
3583
+ do {
3584
+ pos2 = string.indexOf(".", pos1);
3585
+ if (pos2 === -1)
3586
+ sid = string.substring(pos1);
3587
+ else
3588
+ sid = string.substring(pos1, pos2);
3589
+ pos1 = pos2 + 1;
3590
+ if (flag) {
3591
+ const sidBlock = this.value[0];
3592
+ let plus = 0;
3593
+ switch (sidBlock.valueDec) {
3594
+ case 0:
3595
+ break;
3596
+ case 1:
3597
+ plus = 40;
3598
+ break;
3599
+ case 2:
3600
+ plus = 80;
3601
+ break;
3602
+ default:
3603
+ this.value = [];
3604
+ return;
3605
+ }
3606
+ const parsedSID = parseInt(sid, 10);
3607
+ if (isNaN(parsedSID))
3608
+ return;
3609
+ sidBlock.valueDec = parsedSID + plus;
3610
+ flag = false;
3611
+ }
3612
+ else {
3613
+ const sidBlock = new LocalSidValueBlock();
3614
+ if (sid > Number.MAX_SAFE_INTEGER) {
3615
+ assertBigInt();
3616
+ const sidValue = BigInt(sid);
3617
+ sidBlock.valueBigInt = sidValue;
3618
+ }
3619
+ else {
3620
+ sidBlock.valueDec = parseInt(sid, 10);
3621
+ if (isNaN(sidBlock.valueDec))
3622
+ return;
3623
+ }
3624
+ if (!this.value.length) {
3625
+ sidBlock.isFirstSid = true;
3626
+ flag = true;
3627
+ }
3628
+ this.value.push(sidBlock);
3629
+ }
3630
+ } while (pos2 !== -1);
3631
+ }
3632
+ toString() {
3633
+ let result = "";
3634
+ let isHexOnly = false;
3635
+ for (let i = 0; i < this.value.length; i++) {
3636
+ isHexOnly = this.value[i].isHexOnly;
3637
+ let sidStr = this.value[i].toString();
3638
+ if (i !== 0)
3639
+ result = `${result}.`;
3640
+ if (isHexOnly) {
3641
+ sidStr = `{${sidStr}}`;
3642
+ if (this.value[i].isFirstSid)
3643
+ result = `2.{${sidStr} - 80}`;
3644
+ else
3645
+ result += sidStr;
3646
+ }
3647
+ else
3648
+ result += sidStr;
3649
+ }
3650
+ return result;
3651
+ }
3652
+ toJSON() {
3653
+ const object = {
3654
+ ...super.toJSON(),
3655
+ value: this.toString(),
3656
+ sidArray: [],
3657
+ };
3658
+ for (let i = 0; i < this.value.length; i++) {
3659
+ object.sidArray.push(this.value[i].toJSON());
3660
+ }
3661
+ return object;
3662
+ }
3663
+ }
3664
+ LocalObjectIdentifierValueBlock.NAME = "ObjectIdentifierValueBlock";
3665
+
3666
+ var _a$m;
3667
+ class ObjectIdentifier extends BaseBlock {
3668
+ getValue() {
3669
+ return this.valueBlock.toString();
3670
+ }
3671
+ setValue(value) {
3672
+ this.valueBlock.fromString(value);
3673
+ }
3674
+ constructor(parameters = {}) {
3675
+ super(parameters, LocalObjectIdentifierValueBlock);
3676
+ this.idBlock.tagClass = 1;
3677
+ this.idBlock.tagNumber = 6;
3678
+ }
3679
+ onAsciiEncoding() {
3680
+ return `${this.constructor.NAME} : ${this.valueBlock.toString() || "empty"}`;
3681
+ }
3682
+ toJSON() {
3683
+ return {
3684
+ ...super.toJSON(),
3685
+ value: this.getValue(),
3686
+ };
3687
+ }
3688
+ }
3689
+ _a$m = ObjectIdentifier;
3690
+ (() => {
3691
+ typeStore.ObjectIdentifier = _a$m;
3692
+ })();
3693
+ ObjectIdentifier.NAME = "OBJECT IDENTIFIER";
3694
+
3695
+ class LocalRelativeSidValueBlock extends HexBlock(LocalBaseBlock) {
3696
+ constructor({ valueDec = 0, ...parameters } = {}) {
3697
+ super(parameters);
3698
+ this.valueDec = valueDec;
3699
+ }
3700
+ fromBER(inputBuffer, inputOffset, inputLength) {
3701
+ if (inputLength === 0)
3702
+ return inputOffset;
3703
+ const inputView = BufferSourceConverter.toUint8Array(inputBuffer);
3704
+ if (!checkBufferParams(this, inputView, inputOffset, inputLength))
3705
+ return -1;
3706
+ const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength);
3707
+ this.valueHexView = new Uint8Array(inputLength);
3708
+ for (let i = 0; i < inputLength; i++) {
3709
+ this.valueHexView[i] = intBuffer[i] & 0x7F;
3710
+ this.blockLength++;
3711
+ if ((intBuffer[i] & 0x80) === 0x00)
3712
+ break;
3713
+ }
3714
+ const tempView = new Uint8Array(this.blockLength);
3715
+ for (let i = 0; i < this.blockLength; i++)
3716
+ tempView[i] = this.valueHexView[i];
3717
+ this.valueHexView = tempView;
3718
+ if ((intBuffer[this.blockLength - 1] & 0x80) !== 0x00) {
3719
+ this.error = "End of input reached before message was fully decoded";
3720
+ return -1;
3721
+ }
3722
+ if (this.valueHexView[0] === 0x00)
3723
+ this.warnings.push("Needlessly long format of SID encoding");
3724
+ if (this.blockLength <= 8)
3725
+ this.valueDec = utilFromBase(this.valueHexView, 7);
3726
+ else {
3727
+ this.isHexOnly = true;
3728
+ this.warnings.push("Too big SID for decoding, hex only");
3729
+ }
3730
+ return (inputOffset + this.blockLength);
3731
+ }
3732
+ toBER(sizeOnly) {
3733
+ if (this.isHexOnly) {
3734
+ if (sizeOnly)
3735
+ return (new ArrayBuffer(this.valueHexView.byteLength));
3736
+ const curView = this.valueHexView;
3737
+ const retView = new Uint8Array(this.blockLength);
3738
+ for (let i = 0; i < (this.blockLength - 1); i++)
3739
+ retView[i] = curView[i] | 0x80;
3740
+ retView[this.blockLength - 1] = curView[this.blockLength - 1];
3741
+ return retView.buffer;
3742
+ }
3743
+ const encodedBuf = utilToBase(this.valueDec, 7);
3744
+ if (encodedBuf.byteLength === 0) {
3745
+ this.error = "Error during encoding SID value";
3746
+ return EMPTY_BUFFER;
3747
+ }
3748
+ const retView = new Uint8Array(encodedBuf.byteLength);
3749
+ if (!sizeOnly) {
3750
+ const encodedView = new Uint8Array(encodedBuf);
3751
+ const len = encodedBuf.byteLength - 1;
3752
+ for (let i = 0; i < len; i++)
3753
+ retView[i] = encodedView[i] | 0x80;
3754
+ retView[len] = encodedView[len];
3755
+ }
3756
+ return retView.buffer;
3757
+ }
3758
+ toString() {
3759
+ let result = "";
3760
+ if (this.isHexOnly)
3761
+ result = Convert.ToHex(this.valueHexView);
3762
+ else {
3763
+ result = this.valueDec.toString();
3764
+ }
3765
+ return result;
3766
+ }
3767
+ toJSON() {
3768
+ return {
3769
+ ...super.toJSON(),
3770
+ valueDec: this.valueDec,
3771
+ };
3772
+ }
3773
+ }
3774
+ LocalRelativeSidValueBlock.NAME = "relativeSidBlock";
3775
+
3776
+ class LocalRelativeObjectIdentifierValueBlock extends ValueBlock {
3777
+ constructor({ value = EMPTY_STRING, ...parameters } = {}) {
3778
+ super(parameters);
3779
+ this.value = [];
3780
+ if (value) {
3781
+ this.fromString(value);
3782
+ }
3783
+ }
3784
+ fromBER(inputBuffer, inputOffset, inputLength) {
3785
+ let resultOffset = inputOffset;
3786
+ while (inputLength > 0) {
3787
+ const sidBlock = new LocalRelativeSidValueBlock();
3788
+ resultOffset = sidBlock.fromBER(inputBuffer, resultOffset, inputLength);
3789
+ if (resultOffset === -1) {
3790
+ this.blockLength = 0;
3791
+ this.error = sidBlock.error;
3792
+ return resultOffset;
3793
+ }
3794
+ this.blockLength += sidBlock.blockLength;
3795
+ inputLength -= sidBlock.blockLength;
3796
+ this.value.push(sidBlock);
3797
+ }
3798
+ return resultOffset;
3799
+ }
3800
+ toBER(sizeOnly, _writer) {
3801
+ const retBuffers = [];
3802
+ for (let i = 0; i < this.value.length; i++) {
3803
+ const valueBuf = this.value[i].toBER(sizeOnly);
3804
+ if (valueBuf.byteLength === 0) {
3805
+ this.error = this.value[i].error;
3806
+ return EMPTY_BUFFER;
3807
+ }
3808
+ retBuffers.push(valueBuf);
3809
+ }
3810
+ return concat(retBuffers);
3811
+ }
3812
+ fromString(string) {
3813
+ this.value = [];
3814
+ let pos1 = 0;
3815
+ let pos2 = 0;
3816
+ let sid = "";
3817
+ do {
3818
+ pos2 = string.indexOf(".", pos1);
3819
+ if (pos2 === -1)
3820
+ sid = string.substring(pos1);
3821
+ else
3822
+ sid = string.substring(pos1, pos2);
3823
+ pos1 = pos2 + 1;
3824
+ const sidBlock = new LocalRelativeSidValueBlock();
3825
+ sidBlock.valueDec = parseInt(sid, 10);
3826
+ if (isNaN(sidBlock.valueDec))
3827
+ return true;
3828
+ this.value.push(sidBlock);
3829
+ } while (pos2 !== -1);
3830
+ return true;
3831
+ }
3832
+ toString() {
3833
+ let result = "";
3834
+ let isHexOnly = false;
3835
+ for (let i = 0; i < this.value.length; i++) {
3836
+ isHexOnly = this.value[i].isHexOnly;
3837
+ let sidStr = this.value[i].toString();
3838
+ if (i !== 0)
3839
+ result = `${result}.`;
3840
+ if (isHexOnly) {
3841
+ sidStr = `{${sidStr}}`;
3842
+ result += sidStr;
3843
+ }
3844
+ else
3845
+ result += sidStr;
3846
+ }
3847
+ return result;
3848
+ }
3849
+ toJSON() {
3850
+ const object = {
3851
+ ...super.toJSON(),
3852
+ value: this.toString(),
3853
+ sidArray: [],
3854
+ };
3855
+ for (let i = 0; i < this.value.length; i++)
3856
+ object.sidArray.push(this.value[i].toJSON());
3857
+ return object;
3858
+ }
3859
+ }
3860
+ LocalRelativeObjectIdentifierValueBlock.NAME = "RelativeObjectIdentifierValueBlock";
3861
+
3862
+ var _a$l;
3863
+ class RelativeObjectIdentifier extends BaseBlock {
3864
+ getValue() {
3865
+ return this.valueBlock.toString();
3866
+ }
3867
+ setValue(value) {
3868
+ this.valueBlock.fromString(value);
3869
+ }
3870
+ constructor(parameters = {}) {
3871
+ super(parameters, LocalRelativeObjectIdentifierValueBlock);
3872
+ this.idBlock.tagClass = 1;
3873
+ this.idBlock.tagNumber = 13;
3874
+ }
3875
+ onAsciiEncoding() {
3876
+ return `${this.constructor.NAME} : ${this.valueBlock.toString() || "empty"}`;
3877
+ }
3878
+ toJSON() {
3879
+ return {
3880
+ ...super.toJSON(),
3881
+ value: this.getValue(),
3882
+ };
3883
+ }
3884
+ }
3885
+ _a$l = RelativeObjectIdentifier;
3886
+ (() => {
3887
+ typeStore.RelativeObjectIdentifier = _a$l;
3888
+ })();
3889
+ RelativeObjectIdentifier.NAME = "RelativeObjectIdentifier";
3890
+
3891
+ var _a$k;
3892
+ class Sequence extends Constructed {
3893
+ constructor(parameters = {}) {
3894
+ super(parameters);
3895
+ this.idBlock.tagClass = 1;
3896
+ this.idBlock.tagNumber = 16;
3897
+ }
3898
+ }
3899
+ _a$k = Sequence;
3900
+ (() => {
3901
+ typeStore.Sequence = _a$k;
3902
+ })();
3903
+ Sequence.NAME = "SEQUENCE";
3904
+
3905
+ var _a$j;
3906
+ class Set$1 extends Constructed {
3907
+ constructor(parameters = {}) {
3908
+ super(parameters);
3909
+ this.idBlock.tagClass = 1;
3910
+ this.idBlock.tagNumber = 17;
3911
+ }
3912
+ }
3913
+ _a$j = Set$1;
3914
+ (() => {
3915
+ typeStore.Set = _a$j;
3916
+ })();
3917
+ Set$1.NAME = "SET";
3918
+
3919
+ class LocalStringValueBlock extends HexBlock(ValueBlock) {
3920
+ constructor({ ...parameters } = {}) {
3921
+ super(parameters);
3922
+ this.isHexOnly = true;
3923
+ this.value = EMPTY_STRING;
3924
+ }
3925
+ toJSON() {
3926
+ return {
3927
+ ...super.toJSON(),
3928
+ value: this.value,
3929
+ };
3930
+ }
3931
+ }
3932
+ LocalStringValueBlock.NAME = "StringValueBlock";
3933
+
3934
+ class LocalSimpleStringValueBlock extends LocalStringValueBlock {
3935
+ }
3936
+ LocalSimpleStringValueBlock.NAME = "SimpleStringValueBlock";
3937
+
3938
+ class LocalSimpleStringBlock extends BaseStringBlock {
3939
+ constructor({ ...parameters } = {}) {
3940
+ super(parameters, LocalSimpleStringValueBlock);
3941
+ }
3942
+ fromBuffer(inputBuffer) {
3943
+ this.valueBlock.value = String.fromCharCode.apply(null, BufferSourceConverter.toUint8Array(inputBuffer));
3944
+ }
3945
+ fromString(inputString) {
3946
+ const strLen = inputString.length;
3947
+ const view = this.valueBlock.valueHexView = new Uint8Array(strLen);
3948
+ for (let i = 0; i < strLen; i++)
3949
+ view[i] = inputString.charCodeAt(i);
3950
+ this.valueBlock.value = inputString;
3951
+ }
3952
+ }
3953
+ LocalSimpleStringBlock.NAME = "SIMPLE STRING";
3954
+
3955
+ class LocalUtf8StringValueBlock extends LocalSimpleStringBlock {
3956
+ fromBuffer(inputBuffer) {
3957
+ this.valueBlock.valueHexView = BufferSourceConverter.toUint8Array(inputBuffer);
3958
+ try {
3959
+ this.valueBlock.value = Convert.ToUtf8String(inputBuffer);
1011
3960
  }
1012
- if (match) {
1013
- oidPosition = i;
1014
- break;
3961
+ catch (ex) {
3962
+ this.warnings.push(`Error during "decodeURIComponent": ${ex}, using raw string`);
3963
+ this.valueBlock.value = Convert.ToBinary(inputBuffer);
1015
3964
  }
1016
3965
  }
1017
- if (oidPosition === -1) {
1018
- return publicKeyData;
3966
+ fromString(inputString) {
3967
+ this.valueBlock.valueHexView = new Uint8Array(Convert.FromUtf8String(inputString));
3968
+ this.valueBlock.value = inputString;
1019
3969
  }
1020
- // Find the BitString that contains the key
1021
- let bitStringPosition = -1;
1022
- for (let i = oidPosition + RSA_OID.length; i < keyBytes.length; i++) {
1023
- if (keyBytes[i] === 0x03) {
1024
- // BIT STRING tag
1025
- bitStringPosition = i;
1026
- break;
3970
+ }
3971
+ LocalUtf8StringValueBlock.NAME = "Utf8StringValueBlock";
3972
+
3973
+ var _a$i;
3974
+ class Utf8String extends LocalUtf8StringValueBlock {
3975
+ constructor(parameters = {}) {
3976
+ super(parameters);
3977
+ this.idBlock.tagClass = 1;
3978
+ this.idBlock.tagNumber = 12;
3979
+ }
3980
+ }
3981
+ _a$i = Utf8String;
3982
+ (() => {
3983
+ typeStore.Utf8String = _a$i;
3984
+ })();
3985
+ Utf8String.NAME = "UTF8String";
3986
+
3987
+ class LocalBmpStringValueBlock extends LocalSimpleStringBlock {
3988
+ fromBuffer(inputBuffer) {
3989
+ this.valueBlock.value = Convert.ToUtf16String(inputBuffer);
3990
+ this.valueBlock.valueHexView = BufferSourceConverter.toUint8Array(inputBuffer);
3991
+ }
3992
+ fromString(inputString) {
3993
+ this.valueBlock.value = inputString;
3994
+ this.valueBlock.valueHexView = new Uint8Array(Convert.FromUtf16String(inputString));
3995
+ }
3996
+ }
3997
+ LocalBmpStringValueBlock.NAME = "BmpStringValueBlock";
3998
+
3999
+ var _a$h;
4000
+ class BmpString extends LocalBmpStringValueBlock {
4001
+ constructor({ ...parameters } = {}) {
4002
+ super(parameters);
4003
+ this.idBlock.tagClass = 1;
4004
+ this.idBlock.tagNumber = 30;
4005
+ }
4006
+ }
4007
+ _a$h = BmpString;
4008
+ (() => {
4009
+ typeStore.BmpString = _a$h;
4010
+ })();
4011
+ BmpString.NAME = "BMPString";
4012
+
4013
+ class LocalUniversalStringValueBlock extends LocalSimpleStringBlock {
4014
+ fromBuffer(inputBuffer) {
4015
+ const copyBuffer = ArrayBuffer.isView(inputBuffer) ? inputBuffer.slice().buffer : inputBuffer.slice(0);
4016
+ const valueView = new Uint8Array(copyBuffer);
4017
+ for (let i = 0; i < valueView.length; i += 4) {
4018
+ valueView[i] = valueView[i + 3];
4019
+ valueView[i + 1] = valueView[i + 2];
4020
+ valueView[i + 2] = 0x00;
4021
+ valueView[i + 3] = 0x00;
4022
+ }
4023
+ this.valueBlock.value = String.fromCharCode.apply(null, new Uint32Array(copyBuffer));
4024
+ }
4025
+ fromString(inputString) {
4026
+ const strLength = inputString.length;
4027
+ const valueHexView = this.valueBlock.valueHexView = new Uint8Array(strLength * 4);
4028
+ for (let i = 0; i < strLength; i++) {
4029
+ const codeBuf = utilToBase(inputString.charCodeAt(i), 8);
4030
+ const codeView = new Uint8Array(codeBuf);
4031
+ if (codeView.length > 4)
4032
+ continue;
4033
+ const dif = 4 - codeView.length;
4034
+ for (let j = (codeView.length - 1); j >= 0; j--)
4035
+ valueHexView[i * 4 + j + dif] = codeView[j];
1027
4036
  }
4037
+ this.valueBlock.value = inputString;
1028
4038
  }
1029
- if (bitStringPosition === -1) {
1030
- return publicKeyData;
4039
+ }
4040
+ LocalUniversalStringValueBlock.NAME = "UniversalStringValueBlock";
4041
+
4042
+ var _a$g;
4043
+ class UniversalString extends LocalUniversalStringValueBlock {
4044
+ constructor({ ...parameters } = {}) {
4045
+ super(parameters);
4046
+ this.idBlock.tagClass = 1;
4047
+ this.idBlock.tagNumber = 28;
1031
4048
  }
1032
- // Skip BIT STRING tag and length bytes to find unused bits byte
1033
- let bitStringLengthBytes = 0;
1034
- if ((keyBytes[bitStringPosition + 1] & 0x80) === 0) {
1035
- // Short form length
1036
- bitStringLengthBytes = 1;
4049
+ }
4050
+ _a$g = UniversalString;
4051
+ (() => {
4052
+ typeStore.UniversalString = _a$g;
4053
+ })();
4054
+ UniversalString.NAME = "UniversalString";
4055
+
4056
+ var _a$f;
4057
+ class NumericString extends LocalSimpleStringBlock {
4058
+ constructor(parameters = {}) {
4059
+ super(parameters);
4060
+ this.idBlock.tagClass = 1;
4061
+ this.idBlock.tagNumber = 18;
1037
4062
  }
1038
- else {
1039
- // Long form length
1040
- bitStringLengthBytes = 1 + (keyBytes[bitStringPosition + 1] & 0x7f);
4063
+ }
4064
+ _a$f = NumericString;
4065
+ (() => {
4066
+ typeStore.NumericString = _a$f;
4067
+ })();
4068
+ NumericString.NAME = "NumericString";
4069
+
4070
+ var _a$e;
4071
+ class PrintableString extends LocalSimpleStringBlock {
4072
+ constructor(parameters = {}) {
4073
+ super(parameters);
4074
+ this.idBlock.tagClass = 1;
4075
+ this.idBlock.tagNumber = 19;
1041
4076
  }
1042
- // The unused bits byte follows the length bytes
1043
- const unusedBitsPosition = bitStringPosition + 1 + bitStringLengthBytes;
1044
- if (unusedBitsPosition >= keyBytes.length) {
1045
- return publicKeyData;
4077
+ }
4078
+ _a$e = PrintableString;
4079
+ (() => {
4080
+ typeStore.PrintableString = _a$e;
4081
+ })();
4082
+ PrintableString.NAME = "PrintableString";
4083
+
4084
+ var _a$d;
4085
+ class TeletexString extends LocalSimpleStringBlock {
4086
+ constructor(parameters = {}) {
4087
+ super(parameters);
4088
+ this.idBlock.tagClass = 1;
4089
+ this.idBlock.tagNumber = 20;
1046
4090
  }
1047
- // The inner SEQUENCE (RSA key) should follow the unused bits byte
1048
- const innerSequencePosition = unusedBitsPosition + 1;
1049
- if (innerSequencePosition >= keyBytes.length || keyBytes[innerSequencePosition] !== 0x30) {
1050
- return publicKeyData;
4091
+ }
4092
+ _a$d = TeletexString;
4093
+ (() => {
4094
+ typeStore.TeletexString = _a$d;
4095
+ })();
4096
+ TeletexString.NAME = "TeletexString";
4097
+
4098
+ var _a$c;
4099
+ class VideotexString extends LocalSimpleStringBlock {
4100
+ constructor(parameters = {}) {
4101
+ super(parameters);
4102
+ this.idBlock.tagClass = 1;
4103
+ this.idBlock.tagNumber = 21;
1051
4104
  }
1052
- // Skip the inner SEQUENCE tag and length bytes to find the modulus
1053
- let innerSequenceLengthBytes = 0;
1054
- if ((keyBytes[innerSequencePosition + 1] & 0x80) === 0) {
1055
- // Short form length
1056
- innerSequenceLengthBytes = 1;
4105
+ }
4106
+ _a$c = VideotexString;
4107
+ (() => {
4108
+ typeStore.VideotexString = _a$c;
4109
+ })();
4110
+ VideotexString.NAME = "VideotexString";
4111
+
4112
+ var _a$b;
4113
+ class IA5String extends LocalSimpleStringBlock {
4114
+ constructor(parameters = {}) {
4115
+ super(parameters);
4116
+ this.idBlock.tagClass = 1;
4117
+ this.idBlock.tagNumber = 22;
1057
4118
  }
1058
- else {
1059
- // Long form length
1060
- innerSequenceLengthBytes = 1 + (keyBytes[innerSequencePosition + 1] & 0x7f);
4119
+ }
4120
+ _a$b = IA5String;
4121
+ (() => {
4122
+ typeStore.IA5String = _a$b;
4123
+ })();
4124
+ IA5String.NAME = "IA5String";
4125
+
4126
+ var _a$a;
4127
+ class GraphicString extends LocalSimpleStringBlock {
4128
+ constructor(parameters = {}) {
4129
+ super(parameters);
4130
+ this.idBlock.tagClass = 1;
4131
+ this.idBlock.tagNumber = 25;
1061
4132
  }
1062
- // The modulus should be an INTEGER (tag 0x02) after the inner SEQUENCE
1063
- const modulusPosition = innerSequencePosition + 1 + innerSequenceLengthBytes;
1064
- if (modulusPosition >= keyBytes.length || keyBytes[modulusPosition] !== 0x02) {
1065
- return publicKeyData;
4133
+ }
4134
+ _a$a = GraphicString;
4135
+ (() => {
4136
+ typeStore.GraphicString = _a$a;
4137
+ })();
4138
+ GraphicString.NAME = "GraphicString";
4139
+
4140
+ var _a$9;
4141
+ class VisibleString extends LocalSimpleStringBlock {
4142
+ constructor(parameters = {}) {
4143
+ super(parameters);
4144
+ this.idBlock.tagClass = 1;
4145
+ this.idBlock.tagNumber = 26;
1066
4146
  }
1067
- // Skip the INTEGER tag and parse its length to find the modulus value
1068
- let modulusLengthBytes = 0;
1069
- let modulusLength = 0;
1070
- if ((keyBytes[modulusPosition + 1] & 0x80) === 0) {
1071
- // Short form length
1072
- modulusLength = keyBytes[modulusPosition + 1];
1073
- modulusLengthBytes = 1;
4147
+ }
4148
+ _a$9 = VisibleString;
4149
+ (() => {
4150
+ typeStore.VisibleString = _a$9;
4151
+ })();
4152
+ VisibleString.NAME = "VisibleString";
4153
+
4154
+ var _a$8;
4155
+ class GeneralString extends LocalSimpleStringBlock {
4156
+ constructor(parameters = {}) {
4157
+ super(parameters);
4158
+ this.idBlock.tagClass = 1;
4159
+ this.idBlock.tagNumber = 27;
1074
4160
  }
1075
- else {
1076
- // Long form length
1077
- const numLengthBytes = keyBytes[modulusPosition + 1] & 0x7f;
1078
- modulusLengthBytes = 1 + numLengthBytes;
1079
- // Calculate multi-byte length
1080
- modulusLength = 0;
1081
- for (let i = 0; i < numLengthBytes; i++) {
1082
- modulusLength = (modulusLength << 8) | keyBytes[modulusPosition + 2 + i];
4161
+ }
4162
+ _a$8 = GeneralString;
4163
+ (() => {
4164
+ typeStore.GeneralString = _a$8;
4165
+ })();
4166
+ GeneralString.NAME = "GeneralString";
4167
+
4168
+ var _a$7;
4169
+ class CharacterString extends LocalSimpleStringBlock {
4170
+ constructor(parameters = {}) {
4171
+ super(parameters);
4172
+ this.idBlock.tagClass = 1;
4173
+ this.idBlock.tagNumber = 29;
4174
+ }
4175
+ }
4176
+ _a$7 = CharacterString;
4177
+ (() => {
4178
+ typeStore.CharacterString = _a$7;
4179
+ })();
4180
+ CharacterString.NAME = "CharacterString";
4181
+
4182
+ var _a$6;
4183
+ class UTCTime extends VisibleString {
4184
+ constructor({ value, valueDate, ...parameters } = {}) {
4185
+ super(parameters);
4186
+ this.year = 0;
4187
+ this.month = 0;
4188
+ this.day = 0;
4189
+ this.hour = 0;
4190
+ this.minute = 0;
4191
+ this.second = 0;
4192
+ if (value) {
4193
+ this.fromString(value);
4194
+ this.valueBlock.valueHexView = new Uint8Array(value.length);
4195
+ for (let i = 0; i < value.length; i++)
4196
+ this.valueBlock.valueHexView[i] = value.charCodeAt(i);
4197
+ }
4198
+ if (valueDate) {
4199
+ this.fromDate(valueDate);
4200
+ this.valueBlock.valueHexView = new Uint8Array(this.toBuffer());
4201
+ }
4202
+ this.idBlock.tagClass = 1;
4203
+ this.idBlock.tagNumber = 23;
4204
+ }
4205
+ fromBuffer(inputBuffer) {
4206
+ this.fromString(String.fromCharCode.apply(null, BufferSourceConverter.toUint8Array(inputBuffer)));
4207
+ }
4208
+ toBuffer() {
4209
+ const str = this.toString();
4210
+ const buffer = new ArrayBuffer(str.length);
4211
+ const view = new Uint8Array(buffer);
4212
+ for (let i = 0; i < str.length; i++)
4213
+ view[i] = str.charCodeAt(i);
4214
+ return buffer;
4215
+ }
4216
+ fromDate(inputDate) {
4217
+ this.year = inputDate.getUTCFullYear();
4218
+ this.month = inputDate.getUTCMonth() + 1;
4219
+ this.day = inputDate.getUTCDate();
4220
+ this.hour = inputDate.getUTCHours();
4221
+ this.minute = inputDate.getUTCMinutes();
4222
+ this.second = inputDate.getUTCSeconds();
4223
+ }
4224
+ toDate() {
4225
+ return (new Date(Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minute, this.second)));
4226
+ }
4227
+ fromString(inputString) {
4228
+ const parser = /(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig;
4229
+ const parserArray = parser.exec(inputString);
4230
+ if (parserArray === null) {
4231
+ this.error = "Wrong input string for conversion";
4232
+ return;
4233
+ }
4234
+ const year = parseInt(parserArray[1], 10);
4235
+ if (year >= 50)
4236
+ this.year = 1900 + year;
4237
+ else
4238
+ this.year = 2000 + year;
4239
+ this.month = parseInt(parserArray[2], 10);
4240
+ this.day = parseInt(parserArray[3], 10);
4241
+ this.hour = parseInt(parserArray[4], 10);
4242
+ this.minute = parseInt(parserArray[5], 10);
4243
+ this.second = parseInt(parserArray[6], 10);
4244
+ }
4245
+ toString(encoding = "iso") {
4246
+ if (encoding === "iso") {
4247
+ const outputArray = new Array(7);
4248
+ outputArray[0] = padNumber(((this.year < 2000) ? (this.year - 1900) : (this.year - 2000)), 2);
4249
+ outputArray[1] = padNumber(this.month, 2);
4250
+ outputArray[2] = padNumber(this.day, 2);
4251
+ outputArray[3] = padNumber(this.hour, 2);
4252
+ outputArray[4] = padNumber(this.minute, 2);
4253
+ outputArray[5] = padNumber(this.second, 2);
4254
+ outputArray[6] = "Z";
4255
+ return outputArray.join("");
1083
4256
  }
4257
+ return super.toString(encoding);
1084
4258
  }
1085
- // The first byte of the modulus value
1086
- const modulusValuePosition = modulusPosition + 1 + modulusLengthBytes;
1087
- if (modulusValuePosition >= keyBytes.length) {
1088
- return publicKeyData;
4259
+ onAsciiEncoding() {
4260
+ return `${this.constructor.NAME} : ${this.toDate().toISOString()}`;
1089
4261
  }
1090
- // Check if the high bit is set and padding is needed
1091
- if ((keyBytes[modulusValuePosition] & 0x80) !== 0) {
1092
- // Create a new key buffer with room for the padding byte
1093
- const fixedKey = new Uint8Array(keyBytes.length + 1);
1094
- // Copy bytes up to the modulus value
1095
- fixedKey.set(keyBytes.slice(0, modulusValuePosition));
1096
- // Add the padding byte
1097
- fixedKey[modulusValuePosition] = 0x00;
1098
- // Copy the rest of the original key after the padding
1099
- fixedKey.set(keyBytes.slice(modulusValuePosition), modulusValuePosition + 1);
1100
- // Now fix all the length fields that need to be incremented
1101
- // 1. Fix modulus length field
1102
- if ((keyBytes[modulusPosition + 1] & 0x80) === 0) {
1103
- // Short form
1104
- fixedKey[modulusPosition + 1] = keyBytes[modulusPosition + 1] + 1;
4262
+ toJSON() {
4263
+ return {
4264
+ ...super.toJSON(),
4265
+ year: this.year,
4266
+ month: this.month,
4267
+ day: this.day,
4268
+ hour: this.hour,
4269
+ minute: this.minute,
4270
+ second: this.second,
4271
+ };
4272
+ }
4273
+ }
4274
+ _a$6 = UTCTime;
4275
+ (() => {
4276
+ typeStore.UTCTime = _a$6;
4277
+ })();
4278
+ UTCTime.NAME = "UTCTime";
4279
+
4280
+ var _a$5;
4281
+ class GeneralizedTime extends UTCTime {
4282
+ constructor(parameters = {}) {
4283
+ var _b;
4284
+ super(parameters);
4285
+ (_b = this.millisecond) !== null && _b !== void 0 ? _b : (this.millisecond = 0);
4286
+ this.idBlock.tagClass = 1;
4287
+ this.idBlock.tagNumber = 24;
4288
+ }
4289
+ fromDate(inputDate) {
4290
+ super.fromDate(inputDate);
4291
+ this.millisecond = inputDate.getUTCMilliseconds();
4292
+ }
4293
+ toDate() {
4294
+ const utcDate = Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minute, this.second, this.millisecond);
4295
+ return (new Date(utcDate));
4296
+ }
4297
+ fromString(inputString) {
4298
+ let isUTC = false;
4299
+ let timeString = "";
4300
+ let dateTimeString = "";
4301
+ let fractionPart = 0;
4302
+ let parser;
4303
+ let hourDifference = 0;
4304
+ let minuteDifference = 0;
4305
+ if (inputString[inputString.length - 1] === "Z") {
4306
+ timeString = inputString.substring(0, inputString.length - 1);
4307
+ isUTC = true;
1105
4308
  }
1106
4309
  else {
1107
- // Long form
1108
- const numLengthBytes = keyBytes[modulusPosition + 1] & 0x7f;
1109
- let lengthValue = 0;
1110
- for (let i = 0; i < numLengthBytes; i++) {
1111
- lengthValue = (lengthValue << 8) | keyBytes[modulusPosition + 2 + i];
1112
- }
1113
- lengthValue += 1;
1114
- for (let i = numLengthBytes - 1; i >= 0; i--) {
1115
- fixedKey[modulusPosition + 2 + i] = lengthValue & 0xff;
1116
- lengthValue >>= 8;
1117
- }
4310
+ const number = new Number(inputString[inputString.length - 1]);
4311
+ if (isNaN(number.valueOf()))
4312
+ throw new Error("Wrong input string for conversion");
4313
+ timeString = inputString;
1118
4314
  }
1119
- // 2. Fix inner SEQUENCE length field
1120
- if ((keyBytes[innerSequencePosition + 1] & 0x80) === 0) {
1121
- // Short form
1122
- fixedKey[innerSequencePosition + 1] = keyBytes[innerSequencePosition + 1] + 1;
4315
+ if (isUTC) {
4316
+ if (timeString.indexOf("+") !== -1)
4317
+ throw new Error("Wrong input string for conversion");
4318
+ if (timeString.indexOf("-") !== -1)
4319
+ throw new Error("Wrong input string for conversion");
1123
4320
  }
1124
4321
  else {
1125
- // Long form
1126
- const numLengthBytes = keyBytes[innerSequencePosition + 1] & 0x7f;
1127
- let lengthValue = 0;
1128
- for (let i = 0; i < numLengthBytes; i++) {
1129
- lengthValue = (lengthValue << 8) | keyBytes[innerSequencePosition + 2 + i];
4322
+ let multiplier = 1;
4323
+ let differencePosition = timeString.indexOf("+");
4324
+ let differenceString = "";
4325
+ if (differencePosition === -1) {
4326
+ differencePosition = timeString.indexOf("-");
4327
+ multiplier = -1;
1130
4328
  }
1131
- lengthValue += 1;
1132
- for (let i = numLengthBytes - 1; i >= 0; i--) {
1133
- fixedKey[innerSequencePosition + 2 + i] = lengthValue & 0xff;
1134
- lengthValue >>= 8;
4329
+ if (differencePosition !== -1) {
4330
+ differenceString = timeString.substring(differencePosition + 1);
4331
+ timeString = timeString.substring(0, differencePosition);
4332
+ if ((differenceString.length !== 2) && (differenceString.length !== 4))
4333
+ throw new Error("Wrong input string for conversion");
4334
+ let number = parseInt(differenceString.substring(0, 2), 10);
4335
+ if (isNaN(number.valueOf()))
4336
+ throw new Error("Wrong input string for conversion");
4337
+ hourDifference = multiplier * number;
4338
+ if (differenceString.length === 4) {
4339
+ number = parseInt(differenceString.substring(2, 4), 10);
4340
+ if (isNaN(number.valueOf()))
4341
+ throw new Error("Wrong input string for conversion");
4342
+ minuteDifference = multiplier * number;
4343
+ }
1135
4344
  }
1136
4345
  }
1137
- // 3. Fix BIT STRING length field
1138
- if ((keyBytes[bitStringPosition + 1] & 0x80) === 0) {
1139
- // Short form
1140
- fixedKey[bitStringPosition + 1] = keyBytes[bitStringPosition + 1] + 1;
4346
+ let fractionPointPosition = timeString.indexOf(".");
4347
+ if (fractionPointPosition === -1)
4348
+ fractionPointPosition = timeString.indexOf(",");
4349
+ if (fractionPointPosition !== -1) {
4350
+ const fractionPartCheck = new Number(`0${timeString.substring(fractionPointPosition)}`);
4351
+ if (isNaN(fractionPartCheck.valueOf()))
4352
+ throw new Error("Wrong input string for conversion");
4353
+ fractionPart = fractionPartCheck.valueOf();
4354
+ dateTimeString = timeString.substring(0, fractionPointPosition);
1141
4355
  }
1142
- else {
1143
- // Long form
1144
- const numLengthBytes = keyBytes[bitStringPosition + 1] & 0x7f;
1145
- let lengthValue = 0;
1146
- for (let i = 0; i < numLengthBytes; i++) {
1147
- lengthValue = (lengthValue << 8) | keyBytes[bitStringPosition + 2 + i];
1148
- }
1149
- lengthValue += 1;
1150
- for (let i = numLengthBytes - 1; i >= 0; i--) {
1151
- fixedKey[bitStringPosition + 2 + i] = lengthValue & 0xff;
1152
- lengthValue >>= 8;
4356
+ else
4357
+ dateTimeString = timeString;
4358
+ switch (true) {
4359
+ case (dateTimeString.length === 8):
4360
+ parser = /(\d{4})(\d{2})(\d{2})/ig;
4361
+ if (fractionPointPosition !== -1)
4362
+ throw new Error("Wrong input string for conversion");
4363
+ break;
4364
+ case (dateTimeString.length === 10):
4365
+ parser = /(\d{4})(\d{2})(\d{2})(\d{2})/ig;
4366
+ if (fractionPointPosition !== -1) {
4367
+ let fractionResult = 60 * fractionPart;
4368
+ this.minute = Math.floor(fractionResult);
4369
+ fractionResult = 60 * (fractionResult - this.minute);
4370
+ this.second = Math.floor(fractionResult);
4371
+ fractionResult = 1000 * (fractionResult - this.second);
4372
+ this.millisecond = Math.floor(fractionResult);
4373
+ }
4374
+ break;
4375
+ case (dateTimeString.length === 12):
4376
+ parser = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig;
4377
+ if (fractionPointPosition !== -1) {
4378
+ let fractionResult = 60 * fractionPart;
4379
+ this.second = Math.floor(fractionResult);
4380
+ fractionResult = 1000 * (fractionResult - this.second);
4381
+ this.millisecond = Math.floor(fractionResult);
4382
+ }
4383
+ break;
4384
+ case (dateTimeString.length === 14):
4385
+ parser = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig;
4386
+ if (fractionPointPosition !== -1) {
4387
+ const fractionResult = 1000 * fractionPart;
4388
+ this.millisecond = Math.floor(fractionResult);
4389
+ }
4390
+ break;
4391
+ default:
4392
+ throw new Error("Wrong input string for conversion");
4393
+ }
4394
+ const parserArray = parser.exec(dateTimeString);
4395
+ if (parserArray === null)
4396
+ throw new Error("Wrong input string for conversion");
4397
+ for (let j = 1; j < parserArray.length; j++) {
4398
+ switch (j) {
4399
+ case 1:
4400
+ this.year = parseInt(parserArray[j], 10);
4401
+ break;
4402
+ case 2:
4403
+ this.month = parseInt(parserArray[j], 10);
4404
+ break;
4405
+ case 3:
4406
+ this.day = parseInt(parserArray[j], 10);
4407
+ break;
4408
+ case 4:
4409
+ this.hour = parseInt(parserArray[j], 10) + hourDifference;
4410
+ break;
4411
+ case 5:
4412
+ this.minute = parseInt(parserArray[j], 10) + minuteDifference;
4413
+ break;
4414
+ case 6:
4415
+ this.second = parseInt(parserArray[j], 10);
4416
+ break;
4417
+ default:
4418
+ throw new Error("Wrong input string for conversion");
1153
4419
  }
1154
4420
  }
1155
- // 4. Fix outer SEQUENCE length field
1156
- if ((keyBytes[1] & 0x80) === 0) {
1157
- // Short form
1158
- fixedKey[1] = keyBytes[1] + 1;
4421
+ if (isUTC === false) {
4422
+ const tempDate = new Date(this.year, this.month, this.day, this.hour, this.minute, this.second, this.millisecond);
4423
+ this.year = tempDate.getUTCFullYear();
4424
+ this.month = tempDate.getUTCMonth();
4425
+ this.day = tempDate.getUTCDay();
4426
+ this.hour = tempDate.getUTCHours();
4427
+ this.minute = tempDate.getUTCMinutes();
4428
+ this.second = tempDate.getUTCSeconds();
4429
+ this.millisecond = tempDate.getUTCMilliseconds();
1159
4430
  }
1160
- else {
1161
- // Long form
1162
- const numLengthBytes = keyBytes[1] & 0x7f;
1163
- let lengthValue = 0;
1164
- for (let i = 0; i < numLengthBytes; i++) {
1165
- lengthValue = (lengthValue << 8) | keyBytes[1 + 1 + i];
1166
- }
1167
- lengthValue += 1;
1168
- for (let i = numLengthBytes - 1; i >= 0; i--) {
1169
- fixedKey[1 + 1 + i] = lengthValue & 0xff;
1170
- lengthValue >>= 8;
4431
+ }
4432
+ toString(encoding = "iso") {
4433
+ if (encoding === "iso") {
4434
+ const outputArray = [];
4435
+ outputArray.push(padNumber(this.year, 4));
4436
+ outputArray.push(padNumber(this.month, 2));
4437
+ outputArray.push(padNumber(this.day, 2));
4438
+ outputArray.push(padNumber(this.hour, 2));
4439
+ outputArray.push(padNumber(this.minute, 2));
4440
+ outputArray.push(padNumber(this.second, 2));
4441
+ if (this.millisecond !== 0) {
4442
+ outputArray.push(".");
4443
+ outputArray.push(padNumber(this.millisecond, 3));
1171
4444
  }
4445
+ outputArray.push("Z");
4446
+ return outputArray.join("");
1172
4447
  }
1173
- log("Fixed key length: " + fixedKey.length);
1174
- return fixedKey.buffer;
4448
+ return super.toString(encoding);
4449
+ }
4450
+ toJSON() {
4451
+ return {
4452
+ ...super.toJSON(),
4453
+ millisecond: this.millisecond,
4454
+ };
1175
4455
  }
1176
- return publicKeyData;
1177
4456
  }
4457
+ _a$5 = GeneralizedTime;
4458
+ (() => {
4459
+ typeStore.GeneralizedTime = _a$5;
4460
+ })();
4461
+ GeneralizedTime.NAME = "GeneralizedTime";
1178
4462
 
1179
- // src/core/revocation/types.ts
1180
- /**
1181
- * Default options for revocation checking
1182
- */
1183
- const DEFAULT_REVOCATION_OPTIONS = {
1184
- ocspEnabled: true,
1185
- crlEnabled: true,
1186
- ocspTimeout: 5000,
1187
- crlTimeout: 10000,
1188
- };
4463
+ var _a$4;
4464
+ class DATE extends Utf8String {
4465
+ constructor(parameters = {}) {
4466
+ super(parameters);
4467
+ this.idBlock.tagClass = 1;
4468
+ this.idBlock.tagNumber = 31;
4469
+ }
4470
+ }
4471
+ _a$4 = DATE;
4472
+ (() => {
4473
+ typeStore.DATE = _a$4;
4474
+ })();
4475
+ DATE.NAME = "DATE";
4476
+
4477
+ var _a$3;
4478
+ class TimeOfDay extends Utf8String {
4479
+ constructor(parameters = {}) {
4480
+ super(parameters);
4481
+ this.idBlock.tagClass = 1;
4482
+ this.idBlock.tagNumber = 32;
4483
+ }
4484
+ }
4485
+ _a$3 = TimeOfDay;
4486
+ (() => {
4487
+ typeStore.TimeOfDay = _a$3;
4488
+ })();
4489
+ TimeOfDay.NAME = "TimeOfDay";
4490
+
4491
+ var _a$2;
4492
+ class DateTime extends Utf8String {
4493
+ constructor(parameters = {}) {
4494
+ super(parameters);
4495
+ this.idBlock.tagClass = 1;
4496
+ this.idBlock.tagNumber = 33;
4497
+ }
4498
+ }
4499
+ _a$2 = DateTime;
4500
+ (() => {
4501
+ typeStore.DateTime = _a$2;
4502
+ })();
4503
+ DateTime.NAME = "DateTime";
4504
+
4505
+ var _a$1;
4506
+ class Duration extends Utf8String {
4507
+ constructor(parameters = {}) {
4508
+ super(parameters);
4509
+ this.idBlock.tagClass = 1;
4510
+ this.idBlock.tagNumber = 34;
4511
+ }
4512
+ }
4513
+ _a$1 = Duration;
4514
+ (() => {
4515
+ typeStore.Duration = _a$1;
4516
+ })();
4517
+ Duration.NAME = "Duration";
4518
+
4519
+ var _a;
4520
+ class TIME extends Utf8String {
4521
+ constructor(parameters = {}) {
4522
+ super(parameters);
4523
+ this.idBlock.tagClass = 1;
4524
+ this.idBlock.tagNumber = 14;
4525
+ }
4526
+ }
4527
+ _a = TIME;
4528
+ (() => {
4529
+ typeStore.TIME = _a;
4530
+ })();
4531
+ TIME.NAME = "TIME";
1189
4532
 
1190
4533
  // src/core/revocation/crl.ts
1191
4534
  /**
1192
4535
  * OID for CRL Distribution Points extension
1193
4536
  */
1194
4537
  const id_ce_cRLDistributionPoints = "2.5.29.31";
4538
+ /**
4539
+ * Upper bound on ASN.1 nodes when parsing large CRLs.
4540
+ *
4541
+ * asn1js enforces a DoS guard (DEFAULT_MAX_NODES = 10000) that rejects national
4542
+ * CRLs with tens of thousands of revoked entries (e.g. the Latvian LV eID ICA
4543
+ * CRL has ~13k entries -> well over 10k nodes). @peculiar/x509's X509Crl does not
4544
+ * expose the limit, so the large-CRL fallback in parseCRL() raises it here while
4545
+ * still keeping a realistic ceiling so a maliciously huge CRL is rejected.
4546
+ */
4547
+ const MAX_CRL_ASN1_NODES = 5000000;
1195
4548
  /**
1196
4549
  * Extract CRL distribution point URLs from certificate
1197
4550
  * @param cert X509Certificate to extract CRL URLs from
@@ -1250,6 +4603,47 @@ function isSerialInCRL(crl, serialNumber) {
1250
4603
  }
1251
4604
  return { isRevoked: false };
1252
4605
  }
4606
+ /**
4607
+ * Convert CRL bytes to a DER ArrayBuffer, decoding from PEM if necessary.
4608
+ */
4609
+ function crlBytesToDer(data) {
4610
+ // Detect a PEM armor by inspecting the leading bytes ("-----BEGIN").
4611
+ const head = new Uint8Array(data, 0, Math.min(data.byteLength, 16));
4612
+ let prefix = "";
4613
+ for (const byte of head) {
4614
+ prefix += String.fromCharCode(byte);
4615
+ }
4616
+ if (prefix.includes("-----BEGIN")) {
4617
+ const pem = new TextDecoder().decode(data);
4618
+ const base64 = pem
4619
+ .replace(/-----BEGIN[^-]+-----/g, "")
4620
+ .replace(/-----END[^-]+-----/g, "")
4621
+ .replace(/\s+/g, "");
4622
+ return normalize.base64ToArrayBuffer(base64);
4623
+ }
4624
+ return data;
4625
+ }
4626
+ /**
4627
+ * Parse a large CRL that exceeds asn1js's default node cap.
4628
+ *
4629
+ * X509Crl's constructor parses with asn1js defaults, so we decode the DER
4630
+ * ourselves with a raised (but bounded) node limit and then hand the already
4631
+ * decoded structure to X509Crl, which accepts a CertificateList directly.
4632
+ */
4633
+ function parseLargeCRL(data) {
4634
+ try {
4635
+ const der = crlBytesToDer(data);
4636
+ const asn1 = fromBER(der, { maxNodes: MAX_CRL_ASN1_NODES });
4637
+ if (asn1.offset === -1 || !asn1.result) {
4638
+ return null;
4639
+ }
4640
+ const certList = asn1Schema.AsnParser.fromASN(asn1.result, asn1X509.CertificateList);
4641
+ return new x509.X509Crl(certList);
4642
+ }
4643
+ catch {
4644
+ return null;
4645
+ }
4646
+ }
1253
4647
  /**
1254
4648
  * Parse CRL from DER or PEM data
1255
4649
  * @param data CRL data (DER or PEM)
@@ -1269,7 +4663,8 @@ function parseCRL(data) {
1269
4663
  return new x509.X509Crl(pem);
1270
4664
  }
1271
4665
  catch {
1272
- return null;
4666
+ // National CRLs can exceed asn1js's default node cap; retry with a raised limit.
4667
+ return parseLargeCRL(data);
1273
4668
  }
1274
4669
  }
1275
4670
  }
@@ -2742,8 +6137,15 @@ async function verifySignature(signatureInfo, files, options = {}) {
2742
6137
  // Check certificate revocation (default: enabled)
2743
6138
  if (options.checkRevocation !== false && certResult.isValid) {
2744
6139
  try {
6140
+ // Certificates carried inside embedded OCSP responses are a useful source of
6141
+ // the issuer cert, letting the lightweight live OCSP query succeed (and
6142
+ // avoiding a full CRL download) when the container's chain is empty.
6143
+ const revocationChain = [
6144
+ ...(signatureInfo.certificateChain ?? []),
6145
+ ...identity.extractCertsFromOCSPResponses(signatureInfo.revocationValues?.ocsp ?? []),
6146
+ ];
2745
6147
  const revocationResult = await checkCertificateRevocation(signatureInfo.certificatePEM, {
2746
- certificateChain: signatureInfo.certificateChain,
6148
+ certificateChain: revocationChain.length > 0 ? revocationChain : undefined,
2747
6149
  ...options.revocationOptions,
2748
6150
  });
2749
6151
  certResult.revocation = revocationResult;