node-opcua-crypto 5.3.4 → 5.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;var __defProp = Object.defineProperty;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3;var __defProp = Object.defineProperty;
2
2
  var __export = (target, all) => {
3
3
  for (var name in all)
4
4
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -645,7 +645,17 @@ function toPem(raw_key, pem) {
645
645
  } else {
646
646
  pemType = pem;
647
647
  _assert2.default.call(void 0, ["CERTIFICATE REQUEST", "CERTIFICATE", "RSA PRIVATE KEY", "PUBLIC KEY", "X509 CRL"].indexOf(pemType) >= 0);
648
- const b = raw_key.toString("base64");
648
+ const buffer = raw_key;
649
+ if (pemType === "CERTIFICATE" && buffer.length > 0) {
650
+ try {
651
+ const parts = split_der(buffer);
652
+ if (parts.length > 1) {
653
+ return parts.map((cert) => toPem(cert, pem)).join("\n");
654
+ }
655
+ } catch (_err) {
656
+ }
657
+ }
658
+ const b = buffer.toString("base64");
649
659
  const strBody = _optionalChain([b, 'access', _9 => _9.match, 'call', _10 => _10(/.{1,64}/g), 'optionalAccess', _11 => _11.join, 'call', _12 => _12("\n")]) || "";
650
660
  return `-----BEGIN ${pemType}-----
651
661
  ${strBody}
@@ -1961,6 +1971,9 @@ __export(index_es_exports, {
1961
1971
  Choice: () => Choice,
1962
1972
  Constructed: () => Constructed,
1963
1973
  DATE: () => DATE,
1974
+ DEFAULT_MAX_CONTENT_LENGTH: () => DEFAULT_MAX_CONTENT_LENGTH,
1975
+ DEFAULT_MAX_DEPTH: () => DEFAULT_MAX_DEPTH,
1976
+ DEFAULT_MAX_NODES: () => DEFAULT_MAX_NODES,
1964
1977
  DateTime: () => DateTime,
1965
1978
  Duration: () => Duration,
1966
1979
  EndOfContent: () => EndOfContent,
@@ -2541,7 +2554,7 @@ function HexBlock(BaseClass) {
2541
2554
  this.isHexOnly = (_b = params.isHexOnly) !== null && _b !== void 0 ? _b : false;
2542
2555
  this.valueHexView = params.valueHex ? BufferSourceConverter.toUint8Array(params.valueHex) : EMPTY_VIEW;
2543
2556
  }
2544
- fromBER(inputBuffer, inputOffset, inputLength) {
2557
+ fromBER(inputBuffer, inputOffset, inputLength, _context) {
2545
2558
  const view = inputBuffer instanceof ArrayBuffer ? new Uint8Array(inputBuffer) : inputBuffer;
2546
2559
  if (!checkBufferParams(this, view, inputOffset, inputLength)) {
2547
2560
  return -1;
@@ -2602,7 +2615,7 @@ var LocalBaseBlock = class {
2602
2615
  };
2603
2616
  LocalBaseBlock.NAME = "baseBlock";
2604
2617
  var ValueBlock = class extends LocalBaseBlock {
2605
- fromBER(_inputBuffer, _inputOffset, _inputLength) {
2618
+ fromBER(_inputBuffer, _inputOffset, _inputLength, _context) {
2606
2619
  throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'");
2607
2620
  }
2608
2621
  toBER(_sizeOnly, _writer) {
@@ -2715,31 +2728,21 @@ var LocalIdentificationBlock = class extends HexBlock(LocalBaseBlock) {
2715
2728
  this.tagNumber = tagNumberMask;
2716
2729
  this.blockLength = 1;
2717
2730
  } else {
2718
- let count = 1;
2719
- let intTagNumberBuffer = this.valueHexView = new Uint8Array(255);
2720
- let tagNumberBufferMaxLength = 255;
2721
- while (intBuffer[count] & 128) {
2722
- intTagNumberBuffer[count - 1] = intBuffer[count] & 127;
2723
- count++;
2724
- if (count >= intBuffer.length) {
2731
+ let count = 0;
2732
+ while (true) {
2733
+ const tagByteIndex = count + 1;
2734
+ if (tagByteIndex >= intBuffer.length) {
2725
2735
  this.error = "End of input reached before message was fully decoded";
2726
2736
  return -1;
2727
2737
  }
2728
- if (count === tagNumberBufferMaxLength) {
2729
- tagNumberBufferMaxLength += 255;
2730
- const tempBufferView2 = new Uint8Array(tagNumberBufferMaxLength);
2731
- for (let i = 0; i < intTagNumberBuffer.length; i++)
2732
- tempBufferView2[i] = intTagNumberBuffer[i];
2733
- intTagNumberBuffer = this.valueHexView = new Uint8Array(tagNumberBufferMaxLength);
2734
- }
2738
+ count++;
2739
+ if ((intBuffer[tagByteIndex] & 128) === 0)
2740
+ break;
2735
2741
  }
2736
2742
  this.blockLength = count + 1;
2737
- intTagNumberBuffer[count - 1] = intBuffer[count] & 127;
2738
- const tempBufferView = new Uint8Array(count);
2743
+ const intTagNumberBuffer = this.valueHexView = new Uint8Array(count);
2739
2744
  for (let i = 0; i < count; i++)
2740
- tempBufferView[i] = intTagNumberBuffer[i];
2741
- intTagNumberBuffer = this.valueHexView = new Uint8Array(count);
2742
- intTagNumberBuffer.set(tempBufferView);
2745
+ intTagNumberBuffer[i] = intBuffer[i + 1] & 127;
2743
2746
  if (this.blockLength <= 9)
2744
2747
  this.tagNumber = utilFromBase(intTagNumberBuffer, 7);
2745
2748
  else {
@@ -2889,8 +2892,8 @@ var BaseBlock = class extends LocalBaseBlock {
2889
2892
  this.lenBlock = new LocalLengthBlock(parameters);
2890
2893
  this.valueBlock = valueBlockType ? new valueBlockType(parameters) : new ValueBlock(parameters);
2891
2894
  }
2892
- fromBER(inputBuffer, inputOffset, inputLength) {
2893
- const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length);
2895
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
2896
+ const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length, context);
2894
2897
  if (resultOffset === -1) {
2895
2898
  this.error = this.valueBlock.error;
2896
2899
  return resultOffset;
@@ -3026,6 +3029,55 @@ _a$w = Primitive;
3026
3029
  typeStore.Primitive = _a$w;
3027
3030
  })();
3028
3031
  Primitive.NAME = "PRIMITIVE";
3032
+ var DEFAULT_MAX_DEPTH = 100;
3033
+ var DEFAULT_MAX_NODES = 1e4;
3034
+ var DEFAULT_MAX_CONTENT_LENGTH = 16 * 1024 * 1024;
3035
+ var MAX_DEPTH_EXCEEDED_ERROR = "Maximum ASN.1 nesting depth exceeded";
3036
+ var MAX_NODES_EXCEEDED_ERROR = "Maximum ASN.1 node count exceeded";
3037
+ var MAX_CONTENT_LENGTH_EXCEEDED_ERROR = "Maximum ASN.1 content length exceeded";
3038
+ function createFromBerContext(options = {}) {
3039
+ var _a2, _b, _c;
3040
+ return {
3041
+ depth: 0,
3042
+ maxDepth: (_a2 = options.maxDepth) !== null && _a2 !== void 0 ? _a2 : DEFAULT_MAX_DEPTH,
3043
+ nodesCount: 0,
3044
+ maxNodes: (_b = options.maxNodes) !== null && _b !== void 0 ? _b : DEFAULT_MAX_NODES,
3045
+ maxContentLength: (_c = options.maxContentLength) !== null && _c !== void 0 ? _c : DEFAULT_MAX_CONTENT_LENGTH
3046
+ };
3047
+ }
3048
+ function createErrorResult(error) {
3049
+ const result = new BaseBlock({}, ValueBlock);
3050
+ result.error = error;
3051
+ return {
3052
+ offset: -1,
3053
+ result
3054
+ };
3055
+ }
3056
+ function checkNodesLimit(context) {
3057
+ context.nodesCount += 1;
3058
+ if (context.nodesCount > context.maxNodes) {
3059
+ return MAX_NODES_EXCEEDED_ERROR;
3060
+ }
3061
+ return void 0;
3062
+ }
3063
+ function checkContentLengthLimit(inputLength, context) {
3064
+ if (inputLength > context.maxContentLength) {
3065
+ return MAX_CONTENT_LENGTH_EXCEEDED_ERROR;
3066
+ }
3067
+ return void 0;
3068
+ }
3069
+ function localFromBERWithChildContext(inputBuffer, inputOffset, inputLength, context) {
3070
+ const childDepth = context.depth + 1;
3071
+ if (childDepth > context.maxDepth) {
3072
+ return createErrorResult(MAX_DEPTH_EXCEEDED_ERROR);
3073
+ }
3074
+ context.depth = childDepth;
3075
+ try {
3076
+ return localFromBER(inputBuffer, inputOffset, inputLength, context);
3077
+ } finally {
3078
+ context.depth -= 1;
3079
+ }
3080
+ }
3029
3081
  function localChangeType(inputObject, newType) {
3030
3082
  if (inputObject instanceof newType) {
3031
3083
  return inputObject;
@@ -3037,7 +3089,7 @@ function localChangeType(inputObject, newType) {
3037
3089
  newObject.valueBeforeDecodeView = inputObject.valueBeforeDecodeView;
3038
3090
  return newObject;
3039
3091
  }
3040
- function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.length) {
3092
+ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.length, context = createFromBerContext()) {
3041
3093
  const incomingOffset = inputOffset;
3042
3094
  let returnObject = new BaseBlock({}, ValueBlock);
3043
3095
  const baseBlock = new LocalBaseBlock();
@@ -3056,6 +3108,14 @@ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.le
3056
3108
  result: returnObject
3057
3109
  };
3058
3110
  }
3111
+ const nodesLimitError = checkNodesLimit(context);
3112
+ if (nodesLimitError) {
3113
+ returnObject.error = nodesLimitError;
3114
+ return {
3115
+ offset: -1,
3116
+ result: returnObject
3117
+ };
3118
+ }
3059
3119
  let resultOffset = returnObject.idBlock.fromBER(inputBuffer, inputOffset, inputLength);
3060
3120
  if (returnObject.idBlock.warnings.length) {
3061
3121
  returnObject.warnings.concat(returnObject.idBlock.warnings);
@@ -3082,6 +3142,15 @@ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.le
3082
3142
  }
3083
3143
  inputOffset = resultOffset;
3084
3144
  inputLength -= returnObject.lenBlock.blockLength;
3145
+ const valueLength = returnObject.lenBlock.isIndefiniteForm ? inputLength : returnObject.lenBlock.length;
3146
+ const contentLengthError = checkContentLengthLimit(valueLength, context);
3147
+ if (contentLengthError) {
3148
+ returnObject.error = contentLengthError;
3149
+ return {
3150
+ offset: -1,
3151
+ result: returnObject
3152
+ };
3153
+ }
3085
3154
  if (!returnObject.idBlock.isConstructed && returnObject.lenBlock.isIndefiniteForm) {
3086
3155
  returnObject.error = "Indefinite length form used for primitive encoding form";
3087
3156
  return {
@@ -3220,14 +3289,14 @@ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.le
3220
3289
  }
3221
3290
  }
3222
3291
  returnObject = localChangeType(returnObject, newASN1Type);
3223
- resultOffset = returnObject.fromBER(inputBuffer, inputOffset, returnObject.lenBlock.isIndefiniteForm ? inputLength : returnObject.lenBlock.length);
3292
+ resultOffset = returnObject.fromBER(inputBuffer, inputOffset, valueLength, context);
3224
3293
  returnObject.valueBeforeDecodeView = inputBuffer.subarray(incomingOffset, incomingOffset + returnObject.blockLength);
3225
3294
  return {
3226
3295
  offset: resultOffset,
3227
3296
  result: returnObject
3228
3297
  };
3229
3298
  }
3230
- function fromBER(inputBuffer) {
3299
+ function fromBER(inputBuffer, options = {}) {
3231
3300
  if (!inputBuffer.byteLength) {
3232
3301
  const result = new BaseBlock({}, ValueBlock);
3233
3302
  result.error = "Input buffer has zero length";
@@ -3236,7 +3305,7 @@ function fromBER(inputBuffer) {
3236
3305
  result
3237
3306
  };
3238
3307
  }
3239
- return localFromBER(BufferSourceConverter.toUint8Array(inputBuffer).slice(), 0, inputBuffer.byteLength);
3308
+ return localFromBER(BufferSourceConverter.toUint8Array(inputBuffer).slice(), 0, inputBuffer.byteLength, createFromBerContext(options));
3240
3309
  }
3241
3310
  function checkLen(indefiniteLength, length) {
3242
3311
  if (indefiniteLength) {
@@ -3250,8 +3319,9 @@ var LocalConstructedValueBlock = class extends ValueBlock {
3250
3319
  this.value = value;
3251
3320
  this.isIndefiniteForm = isIndefiniteForm;
3252
3321
  }
3253
- fromBER(inputBuffer, inputOffset, inputLength) {
3322
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
3254
3323
  const view = BufferSourceConverter.toUint8Array(inputBuffer);
3324
+ const parseContext = context !== null && context !== void 0 ? context : createFromBerContext();
3255
3325
  if (!checkBufferParams(this, view, inputOffset, inputLength)) {
3256
3326
  return -1;
3257
3327
  }
@@ -3262,7 +3332,7 @@ var LocalConstructedValueBlock = class extends ValueBlock {
3262
3332
  }
3263
3333
  let currentOffset = inputOffset;
3264
3334
  while (checkLen(this.isIndefiniteForm, inputLength) > 0) {
3265
- const returnObject = localFromBER(view, currentOffset, inputLength);
3335
+ const returnObject = localFromBERWithChildContext(view, currentOffset, inputLength, parseContext);
3266
3336
  if (returnObject.offset === -1) {
3267
3337
  this.error = returnObject.result.error;
3268
3338
  this.warnings.concat(returnObject.result.warnings);
@@ -3314,9 +3384,9 @@ var Constructed = class extends BaseBlock {
3314
3384
  super(parameters, LocalConstructedValueBlock);
3315
3385
  this.idBlock.isConstructed = true;
3316
3386
  }
3317
- fromBER(inputBuffer, inputOffset, inputLength) {
3387
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
3318
3388
  this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
3319
- const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length);
3389
+ const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length, context);
3320
3390
  if (resultOffset === -1) {
3321
3391
  this.error = this.valueBlock.error;
3322
3392
  return resultOffset;
@@ -3482,11 +3552,11 @@ var LocalOctetStringValueBlock = class extends HexBlock(LocalConstructedValueBlo
3482
3552
  super(parameters);
3483
3553
  this.isConstructed = isConstructed;
3484
3554
  }
3485
- fromBER(inputBuffer, inputOffset, inputLength) {
3555
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
3486
3556
  let resultOffset = 0;
3487
3557
  if (this.isConstructed) {
3488
3558
  this.isHexOnly = false;
3489
- resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength);
3559
+ resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength, context);
3490
3560
  if (resultOffset === -1)
3491
3561
  return resultOffset;
3492
3562
  for (let i = 0; i < this.value.length; i++) {
@@ -3543,7 +3613,7 @@ var OctetString = class extends BaseBlock {
3543
3613
  this.idBlock.tagClass = 1;
3544
3614
  this.idBlock.tagNumber = 4;
3545
3615
  }
3546
- fromBER(inputBuffer, inputOffset, inputLength) {
3616
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
3547
3617
  this.valueBlock.isConstructed = this.idBlock.isConstructed;
3548
3618
  this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
3549
3619
  if (inputLength === 0) {
@@ -3558,7 +3628,8 @@ var OctetString = class extends BaseBlock {
3558
3628
  const buf = view.subarray(inputOffset, inputOffset + inputLength);
3559
3629
  try {
3560
3630
  if (buf.byteLength) {
3561
- const asn = localFromBER(buf, 0, buf.byteLength);
3631
+ const parseContext = context !== null && context !== void 0 ? context : createFromBerContext();
3632
+ const asn = localFromBERWithChildContext(buf, 0, buf.byteLength, parseContext);
3562
3633
  if (asn.offset !== -1 && asn.offset === inputLength) {
3563
3634
  this.valueBlock.value = [asn.result];
3564
3635
  }
@@ -3566,7 +3637,7 @@ var OctetString = class extends BaseBlock {
3566
3637
  } catch (e3) {
3567
3638
  }
3568
3639
  }
3569
- return super.fromBER(inputBuffer, inputOffset, inputLength);
3640
+ return super.fromBER(inputBuffer, inputOffset, inputLength, context);
3570
3641
  }
3571
3642
  onAsciiEncoding() {
3572
3643
  if (this.valueBlock.isConstructed || this.valueBlock.value && this.valueBlock.value.length) {
@@ -3601,13 +3672,13 @@ var LocalBitStringValueBlock = class extends HexBlock(LocalConstructedValueBlock
3601
3672
  this.isConstructed = isConstructed;
3602
3673
  this.blockLength = this.valueHexView.byteLength;
3603
3674
  }
3604
- fromBER(inputBuffer, inputOffset, inputLength) {
3675
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
3605
3676
  if (!inputLength) {
3606
3677
  return inputOffset;
3607
3678
  }
3608
3679
  let resultOffset = -1;
3609
3680
  if (this.isConstructed) {
3610
- resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength);
3681
+ resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength, context);
3611
3682
  if (resultOffset === -1)
3612
3683
  return resultOffset;
3613
3684
  for (const value of this.value) {
@@ -3647,7 +3718,8 @@ var LocalBitStringValueBlock = class extends HexBlock(LocalConstructedValueBlock
3647
3718
  const buf = intBuffer.subarray(1);
3648
3719
  try {
3649
3720
  if (buf.byteLength) {
3650
- const asn = localFromBER(buf, 0, buf.byteLength);
3721
+ const parseContext = context !== null && context !== void 0 ? context : createFromBerContext();
3722
+ const asn = localFromBERWithChildContext(buf, 0, buf.byteLength, parseContext);
3651
3723
  if (asn.offset !== -1 && asn.offset === inputLength - 1) {
3652
3724
  this.value = [asn.result];
3653
3725
  }
@@ -3704,10 +3776,10 @@ var BitString = class extends BaseBlock {
3704
3776
  this.idBlock.tagClass = 1;
3705
3777
  this.idBlock.tagNumber = 3;
3706
3778
  }
3707
- fromBER(inputBuffer, inputOffset, inputLength) {
3779
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
3708
3780
  this.valueBlock.isConstructed = this.idBlock.isConstructed;
3709
3781
  this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
3710
- return super.fromBER(inputBuffer, inputOffset, inputLength);
3782
+ return super.fromBER(inputBuffer, inputOffset, inputLength, context);
3711
3783
  }
3712
3784
  onAsciiEncoding() {
3713
3785
  if (this.valueBlock.isConstructed || this.valueBlock.value && this.valueBlock.value.length) {
@@ -5434,6 +5506,59 @@ function verifySchema(inputBuffer, inputSchema) {
5434
5506
  return compareSchema(asn12.result, asn12.result, inputSchema);
5435
5507
  }
5436
5508
 
5509
+ // ../../node_modules/@peculiar/utils/build/esm/bytes/buffer-source.js
5510
+ var ARRAY_BUFFER_TAG = "[object ArrayBuffer]";
5511
+ var SHARED_ARRAY_BUFFER_TAG = "[object SharedArrayBuffer]";
5512
+ function tagOf(value) {
5513
+ return Object.prototype.toString.call(value);
5514
+ }
5515
+ function isArrayBufferViewLike(value) {
5516
+ if (ArrayBuffer.isView(value)) {
5517
+ return true;
5518
+ }
5519
+ if (!value || typeof value !== "object") {
5520
+ return false;
5521
+ }
5522
+ const view = value;
5523
+ return typeof view.byteOffset === "number" && typeof view.byteLength === "number" && isArrayBufferLike(view.buffer);
5524
+ }
5525
+ function isArrayBuffer(value) {
5526
+ return tagOf(value) === ARRAY_BUFFER_TAG;
5527
+ }
5528
+ function isSharedArrayBuffer(value) {
5529
+ return typeof SharedArrayBuffer !== "undefined" && tagOf(value) === SHARED_ARRAY_BUFFER_TAG;
5530
+ }
5531
+ function isArrayBufferLike(value) {
5532
+ return isArrayBuffer(value) || isSharedArrayBuffer(value);
5533
+ }
5534
+ function isArrayBufferView(value) {
5535
+ return isArrayBufferViewLike(value);
5536
+ }
5537
+ function isBufferSource(value) {
5538
+ return isArrayBufferLike(value) || isArrayBufferView(value);
5539
+ }
5540
+ function assertBufferSource(value) {
5541
+ if (!isBufferSource(value)) {
5542
+ throw new TypeError("Expected ArrayBuffer, SharedArrayBuffer, or ArrayBufferView");
5543
+ }
5544
+ }
5545
+ function toUint8Array(data) {
5546
+ assertBufferSource(data);
5547
+ if (isArrayBufferLike(data)) {
5548
+ return new Uint8Array(data);
5549
+ }
5550
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
5551
+ }
5552
+ function toArrayBuffer(data) {
5553
+ assertBufferSource(data);
5554
+ if (isArrayBuffer(data)) {
5555
+ return data;
5556
+ }
5557
+ const buffer = new ArrayBuffer(data.byteLength);
5558
+ new Uint8Array(buffer).set(toUint8Array(data));
5559
+ return buffer;
5560
+ }
5561
+
5437
5562
  // ../../node_modules/@peculiar/asn1-schema/build/es2015/enums.js
5438
5563
  var AsnTypeTypes;
5439
5564
  (function(AsnTypeTypes2) {
@@ -5474,7 +5599,7 @@ var AsnPropTypes;
5474
5599
 
5475
5600
  // ../../node_modules/@peculiar/asn1-schema/build/es2015/converters.js
5476
5601
  var AsnAnyConverter = {
5477
- fromASN: (value) => value instanceof Null ? null : value.valueBeforeDecodeView,
5602
+ fromASN: (value) => value instanceof Null ? null : toArrayBuffer(value.valueBeforeDecodeView),
5478
5603
  toASN: (value) => {
5479
5604
  if (value === null) {
5480
5605
  return new Null();
@@ -5495,7 +5620,7 @@ var AsnEnumeratedConverter = {
5495
5620
  toASN: (value) => new Enumerated({ value })
5496
5621
  };
5497
5622
  var AsnBitStringConverter = {
5498
- fromASN: (value) => value.valueBlock.valueHexView,
5623
+ fromASN: (value) => toArrayBuffer(value.valueBlock.valueHexView),
5499
5624
  toASN: (value) => new BitString({ valueHex: value })
5500
5625
  };
5501
5626
  var AsnObjectIdentifierConverter = {
@@ -5507,7 +5632,7 @@ var AsnBooleanConverter = {
5507
5632
  toASN: (value) => new Boolean({ value })
5508
5633
  };
5509
5634
  var AsnOctetStringConverter = {
5510
- fromASN: (value) => value.valueBlock.valueHexView,
5635
+ fromASN: (value) => toArrayBuffer(value.valueBlock.valueHexView),
5511
5636
  toASN: (value) => new OctetString({ valueHex: value })
5512
5637
  };
5513
5638
  function createStringConverter(Asn1Type) {
@@ -5606,10 +5731,9 @@ function isConvertible(target) {
5606
5731
  }
5607
5732
  }
5608
5733
  function isTypeOfArray(target) {
5609
- var _a2;
5610
5734
  if (target) {
5611
5735
  const proto = Object.getPrototypeOf(target);
5612
- if (((_a2 = proto === null || proto === void 0 ? void 0 : proto.prototype) === null || _a2 === void 0 ? void 0 : _a2.constructor) === Array) {
5736
+ if (_optionalChain([proto, 'optionalAccess', _17 => _17.prototype, 'optionalAccess', _18 => _18.constructor]) === Array) {
5613
5737
  return true;
5614
5738
  }
5615
5739
  return isTypeOfArray(proto);
@@ -5634,10 +5758,8 @@ function isArrayEqual(bytes1, bytes2) {
5634
5758
  }
5635
5759
 
5636
5760
  // ../../node_modules/@peculiar/asn1-schema/build/es2015/schema.js
5637
- var AsnSchemaStorage = class {
5638
- constructor() {
5639
- this.items = /* @__PURE__ */ new WeakMap();
5640
- }
5761
+ var AsnSchemaStorage = (_class2 = class {constructor() { _class2.prototype.__init2.call(this); }
5762
+ __init2() {this.items = /* @__PURE__ */ new WeakMap()}
5641
5763
  has(target) {
5642
5764
  return this.items.has(target);
5643
5765
  }
@@ -5658,7 +5780,10 @@ var AsnSchemaStorage = class {
5658
5780
  }
5659
5781
  }
5660
5782
  createDefault(target) {
5661
- const schema = { type: AsnTypeTypes.Sequence, items: {} };
5783
+ const schema = {
5784
+ type: AsnTypeTypes.Sequence,
5785
+ items: {}
5786
+ };
5662
5787
  const parentSchema = this.findParentSchema(target);
5663
5788
  if (parentSchema) {
5664
5789
  Object.assign(schema, parentSchema);
@@ -5700,14 +5825,24 @@ var AsnSchemaStorage = class {
5700
5825
  const Container = item.repeated === "set" ? Set : Sequence;
5701
5826
  asn1Item = new Container({
5702
5827
  name: "",
5703
- value: [new Repeated({ name, value: asn1Item })]
5828
+ value: [new Repeated({
5829
+ name,
5830
+ value: asn1Item
5831
+ })]
5704
5832
  });
5705
5833
  }
5706
5834
  if (item.context !== null && item.context !== void 0) {
5707
5835
  if (item.implicit) {
5708
5836
  if (typeof item.type === "number" || isConvertible(item.type)) {
5709
5837
  const Container = item.repeated ? Constructed : Primitive;
5710
- asn1Value.push(new Container({ name, optional, idBlock: { tagClass: 3, tagNumber: item.context } }));
5838
+ asn1Value.push(new Container({
5839
+ name,
5840
+ optional,
5841
+ idBlock: {
5842
+ tagClass: 3,
5843
+ tagNumber: item.context
5844
+ }
5845
+ }));
5711
5846
  } else {
5712
5847
  this.cache(item.type);
5713
5848
  const isRepeated = !!item.repeated;
@@ -5716,14 +5851,20 @@ var AsnSchemaStorage = class {
5716
5851
  asn1Value.push(new Constructed({
5717
5852
  name: !isRepeated ? name : "",
5718
5853
  optional,
5719
- idBlock: { tagClass: 3, tagNumber: item.context },
5854
+ idBlock: {
5855
+ tagClass: 3,
5856
+ tagNumber: item.context
5857
+ },
5720
5858
  value
5721
5859
  }));
5722
5860
  }
5723
5861
  } else {
5724
5862
  asn1Value.push(new Constructed({
5725
5863
  optional,
5726
- idBlock: { tagClass: 3, tagNumber: item.context },
5864
+ idBlock: {
5865
+ tagClass: 3,
5866
+ tagNumber: item.context
5867
+ },
5727
5868
  value: [asn1Item]
5728
5869
  }));
5729
5870
  }
@@ -5734,13 +5875,22 @@ var AsnSchemaStorage = class {
5734
5875
  }
5735
5876
  switch (schema.type) {
5736
5877
  case AsnTypeTypes.Sequence:
5737
- return new Sequence({ value: asn1Value, name: "" });
5878
+ return new Sequence({
5879
+ value: asn1Value,
5880
+ name: ""
5881
+ });
5738
5882
  case AsnTypeTypes.Set:
5739
- return new Set({ value: asn1Value, name: "" });
5883
+ return new Set({
5884
+ value: asn1Value,
5885
+ name: ""
5886
+ });
5740
5887
  case AsnTypeTypes.Choice:
5741
- return new Choice({ value: asn1Value, name: "" });
5888
+ return new Choice({
5889
+ value: asn1Value,
5890
+ name: ""
5891
+ });
5742
5892
  default:
5743
- throw new Error(`Unsupported ASN1 type in use`);
5893
+ throw new Error("Unsupported ASN1 type in use");
5744
5894
  }
5745
5895
  }
5746
5896
  set(target, schema) {
@@ -5755,23 +5905,20 @@ var AsnSchemaStorage = class {
5755
5905
  }
5756
5906
  return null;
5757
5907
  }
5758
- };
5908
+ }, _class2);
5759
5909
 
5760
5910
  // ../../node_modules/@peculiar/asn1-schema/build/es2015/storage.js
5761
5911
  var schemaStorage = new AsnSchemaStorage();
5762
5912
 
5763
5913
  // ../../node_modules/@peculiar/asn1-schema/build/es2015/errors/schema_validation.js
5764
- var AsnSchemaValidationError = class extends Error {
5765
- constructor() {
5766
- super(...arguments);
5767
- this.schemas = [];
5768
- }
5769
- };
5914
+ var AsnSchemaValidationError = (_class3 = class extends Error {constructor(...args2) { super(...args2); _class3.prototype.__init3.call(this); }
5915
+ __init3() {this.schemas = []}
5916
+ }, _class3);
5770
5917
 
5771
5918
  // ../../node_modules/@peculiar/asn1-schema/build/es2015/parser.js
5772
5919
  var AsnParser = class {
5773
5920
  static parse(data, target) {
5774
- const asn1Parsed = fromBER(data);
5921
+ const asn1Parsed = fromBER(toArrayBuffer(data));
5775
5922
  if (asn1Parsed.result.error) {
5776
5923
  throw new Error(asn1Parsed.result.error);
5777
5924
  }
@@ -5788,10 +5935,10 @@ var AsnParser = class {
5788
5935
  schemaStorage.cache(target);
5789
5936
  let targetSchema = schema.schema;
5790
5937
  const choiceResult = this.handleChoiceTypes(asn1Schema, schema, target, targetSchema);
5791
- if (choiceResult === null || choiceResult === void 0 ? void 0 : choiceResult.result) {
5938
+ if (_optionalChain([choiceResult, 'optionalAccess', _19 => _19.result])) {
5792
5939
  return choiceResult.result;
5793
5940
  }
5794
- if (choiceResult === null || choiceResult === void 0 ? void 0 : choiceResult.targetSchema) {
5941
+ if (_optionalChain([choiceResult, 'optionalAccess', _20 => _20.targetSchema])) {
5795
5942
  targetSchema = choiceResult.targetSchema;
5796
5943
  }
5797
5944
  const sequenceResult = this.handleSequenceTypes(asn1Schema, schema, target, targetSchema);
@@ -5899,7 +6046,10 @@ var AsnParser = class {
5899
6046
  static processOptionalChoiceField(asn1Element, schemaItem) {
5900
6047
  try {
5901
6048
  const value = this.fromASN(asn1Element, schemaItem.type);
5902
- return { processed: true, value };
6049
+ return {
6050
+ processed: true,
6051
+ value
6052
+ };
5903
6053
  } catch (err) {
5904
6054
  if (err instanceof AsnSchemaValidationError && /Wrong values for Choice type/.test(err.message)) {
5905
6055
  return { processed: false };
@@ -5909,7 +6059,7 @@ var AsnParser = class {
5909
6059
  }
5910
6060
  static handleArrayTypes(asn1Schema, schema, target) {
5911
6061
  if (!("value" in asn1Schema.valueBlock && Array.isArray(asn1Schema.valueBlock.value))) {
5912
- throw new Error(`Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.`);
6062
+ throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");
5913
6063
  }
5914
6064
  const itemType = schema.itemType;
5915
6065
  if (typeof itemType === "number") {
@@ -5945,8 +6095,7 @@ var AsnParser = class {
5945
6095
  }
5946
6096
  }
5947
6097
  static processPrimitiveSchemaItem(asn1SchemaValue, schemaItem, schemaItemType) {
5948
- var _a2;
5949
- const converter = (_a2 = schemaItem.converter) !== null && _a2 !== void 0 ? _a2 : isConvertible(schemaItemType) ? new schemaItemType() : null;
6098
+ const converter = _nullishCoalesce(schemaItem.converter, () => ( (isConvertible(schemaItemType) ? new schemaItemType() : null)));
5950
6099
  if (!converter) {
5951
6100
  throw new Error("Converter is empty");
5952
6101
  }
@@ -6087,7 +6236,7 @@ var AsnSerializer = class _AsnSerializer {
6087
6236
  if (schemaItem.implicit) {
6088
6237
  if (!schemaItem.repeated && (typeof schemaItem.type === "number" || isConvertible(schemaItem.type))) {
6089
6238
  const value = {};
6090
- value.valueHex = asn1Item instanceof Null ? asn1Item.valueBeforeDecodeView : asn1Item.valueBlock.toBER();
6239
+ value.valueHex = asn1Item instanceof Null ? toArrayBuffer(asn1Item.valueBeforeDecodeView) : asn1Item.valueBlock.toBER();
6091
6240
  asn1Value.push(new Primitive({
6092
6241
  optional: schemaItem.optional,
6093
6242
  idBlock: {
@@ -6153,9 +6302,7 @@ var AsnSerializer = class _AsnSerializer {
6153
6302
  }
6154
6303
  const items = Array.from(objProp, (element) => converter.toASN(element));
6155
6304
  const Container = schemaItem.repeated === "sequence" ? Sequence : Set;
6156
- asn1Item = new Container({
6157
- value: items
6158
- });
6305
+ asn1Item = new Container({ value: items });
6159
6306
  } else {
6160
6307
  asn1Item = converter.toASN(objProp);
6161
6308
  }
@@ -6166,9 +6313,7 @@ var AsnSerializer = class _AsnSerializer {
6166
6313
  }
6167
6314
  const items = Array.from(objProp, (element) => this.toASN(element));
6168
6315
  const Container = schemaItem.repeated === "sequence" ? Sequence : Set;
6169
- asn1Item = new Container({
6170
- value: items
6171
- });
6316
+ asn1Item = new Container({ value: items });
6172
6317
  } else {
6173
6318
  asn1Item = this.toASN(objProp);
6174
6319
  }
@@ -6186,7 +6331,7 @@ var AsnConvert = class _AsnConvert {
6186
6331
  return AsnParser.parse(data, target);
6187
6332
  }
6188
6333
  static toString(data) {
6189
- const buf = BufferSourceConverter.isBufferSource(data) ? BufferSourceConverter.toArrayBuffer(data) : _AsnConvert.serialize(data);
6334
+ const buf = isBufferSource(data) ? toArrayBuffer(data) : _AsnConvert.serialize(data);
6190
6335
  const asn = fromBER(buf);
6191
6336
  if (asn.offset === -1) {
6192
6337
  throw new Error(`Cannot decode ASN.1 data. ${asn.result.error}`);
@@ -6268,7 +6413,7 @@ async function createSelfSignedCertificate({
6268
6413
  function rsaLengthPrivateKey(key) {
6269
6414
  const keyPem = typeof key.hidden === "string" ? key.hidden : key.hidden.export({ type: "pkcs1", format: "pem" }).toString();
6270
6415
  const keyObject = _crypto2.createPrivateKey.call(void 0, keyPem);
6271
- const modulusLength = _optionalChain([keyObject, 'access', _17 => _17.asymmetricKeyDetails, 'optionalAccess', _18 => _18.modulusLength]);
6416
+ const modulusLength = _optionalChain([keyObject, 'access', _21 => _21.asymmetricKeyDetails, 'optionalAccess', _22 => _22.modulusLength]);
6272
6417
  _assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from private key");
6273
6418
  return modulusLength / 8;
6274
6419
  }
@@ -6311,7 +6456,7 @@ function rsaLengthPublicKey(key) {
6311
6456
  key = coercePublicKeyPem(key);
6312
6457
  _assert2.default.call(void 0, typeof key === "string");
6313
6458
  const keyObject = _crypto2.createPublicKey.call(void 0, key);
6314
- const modulusLength = _optionalChain([keyObject, 'access', _19 => _19.asymmetricKeyDetails, 'optionalAccess', _20 => _20.modulusLength]);
6459
+ const modulusLength = _optionalChain([keyObject, 'access', _23 => _23.asymmetricKeyDetails, 'optionalAccess', _24 => _24.modulusLength]);
6315
6460
  _assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from public key");
6316
6461
  return modulusLength / 8;
6317
6462
  }
@@ -6319,7 +6464,7 @@ function rsaLengthRsaPublicKey(key) {
6319
6464
  key = coerceRsaPublicKeyPem(key);
6320
6465
  _assert2.default.call(void 0, typeof key === "string");
6321
6466
  const keyObject = _crypto2.createPublicKey.call(void 0, key);
6322
- const modulusLength = _optionalChain([keyObject, 'access', _21 => _21.asymmetricKeyDetails, 'optionalAccess', _22 => _22.modulusLength]);
6467
+ const modulusLength = _optionalChain([keyObject, 'access', _25 => _25.asymmetricKeyDetails, 'optionalAccess', _26 => _26.modulusLength]);
6323
6468
  _assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from public key");
6324
6469
  return modulusLength / 8;
6325
6470
  }
@@ -6624,4 +6769,4 @@ asn1js/build/index.es.js:
6624
6769
  *
6625
6770
  *)
6626
6771
  */
6627
- //# sourceMappingURL=chunk-AZUYUXWD.cjs.map
6772
+ //# sourceMappingURL=chunk-FRVYTI7S.cjs.map