node-opcua-crypto 5.3.5 → 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 });
@@ -652,7 +652,7 @@ function toPem(raw_key, pem) {
652
652
  if (parts.length > 1) {
653
653
  return parts.map((cert) => toPem(cert, pem)).join("\n");
654
654
  }
655
- } catch (err) {
655
+ } catch (_err) {
656
656
  }
657
657
  }
658
658
  const b = buffer.toString("base64");
@@ -1971,6 +1971,9 @@ __export(index_es_exports, {
1971
1971
  Choice: () => Choice,
1972
1972
  Constructed: () => Constructed,
1973
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,
1974
1977
  DateTime: () => DateTime,
1975
1978
  Duration: () => Duration,
1976
1979
  EndOfContent: () => EndOfContent,
@@ -2551,7 +2554,7 @@ function HexBlock(BaseClass) {
2551
2554
  this.isHexOnly = (_b = params.isHexOnly) !== null && _b !== void 0 ? _b : false;
2552
2555
  this.valueHexView = params.valueHex ? BufferSourceConverter.toUint8Array(params.valueHex) : EMPTY_VIEW;
2553
2556
  }
2554
- fromBER(inputBuffer, inputOffset, inputLength) {
2557
+ fromBER(inputBuffer, inputOffset, inputLength, _context) {
2555
2558
  const view = inputBuffer instanceof ArrayBuffer ? new Uint8Array(inputBuffer) : inputBuffer;
2556
2559
  if (!checkBufferParams(this, view, inputOffset, inputLength)) {
2557
2560
  return -1;
@@ -2612,7 +2615,7 @@ var LocalBaseBlock = class {
2612
2615
  };
2613
2616
  LocalBaseBlock.NAME = "baseBlock";
2614
2617
  var ValueBlock = class extends LocalBaseBlock {
2615
- fromBER(_inputBuffer, _inputOffset, _inputLength) {
2618
+ fromBER(_inputBuffer, _inputOffset, _inputLength, _context) {
2616
2619
  throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'");
2617
2620
  }
2618
2621
  toBER(_sizeOnly, _writer) {
@@ -2725,31 +2728,21 @@ var LocalIdentificationBlock = class extends HexBlock(LocalBaseBlock) {
2725
2728
  this.tagNumber = tagNumberMask;
2726
2729
  this.blockLength = 1;
2727
2730
  } else {
2728
- let count = 1;
2729
- let intTagNumberBuffer = this.valueHexView = new Uint8Array(255);
2730
- let tagNumberBufferMaxLength = 255;
2731
- while (intBuffer[count] & 128) {
2732
- intTagNumberBuffer[count - 1] = intBuffer[count] & 127;
2733
- count++;
2734
- if (count >= intBuffer.length) {
2731
+ let count = 0;
2732
+ while (true) {
2733
+ const tagByteIndex = count + 1;
2734
+ if (tagByteIndex >= intBuffer.length) {
2735
2735
  this.error = "End of input reached before message was fully decoded";
2736
2736
  return -1;
2737
2737
  }
2738
- if (count === tagNumberBufferMaxLength) {
2739
- tagNumberBufferMaxLength += 255;
2740
- const tempBufferView2 = new Uint8Array(tagNumberBufferMaxLength);
2741
- for (let i = 0; i < intTagNumberBuffer.length; i++)
2742
- tempBufferView2[i] = intTagNumberBuffer[i];
2743
- intTagNumberBuffer = this.valueHexView = new Uint8Array(tagNumberBufferMaxLength);
2744
- }
2738
+ count++;
2739
+ if ((intBuffer[tagByteIndex] & 128) === 0)
2740
+ break;
2745
2741
  }
2746
2742
  this.blockLength = count + 1;
2747
- intTagNumberBuffer[count - 1] = intBuffer[count] & 127;
2748
- const tempBufferView = new Uint8Array(count);
2743
+ const intTagNumberBuffer = this.valueHexView = new Uint8Array(count);
2749
2744
  for (let i = 0; i < count; i++)
2750
- tempBufferView[i] = intTagNumberBuffer[i];
2751
- intTagNumberBuffer = this.valueHexView = new Uint8Array(count);
2752
- intTagNumberBuffer.set(tempBufferView);
2745
+ intTagNumberBuffer[i] = intBuffer[i + 1] & 127;
2753
2746
  if (this.blockLength <= 9)
2754
2747
  this.tagNumber = utilFromBase(intTagNumberBuffer, 7);
2755
2748
  else {
@@ -2899,8 +2892,8 @@ var BaseBlock = class extends LocalBaseBlock {
2899
2892
  this.lenBlock = new LocalLengthBlock(parameters);
2900
2893
  this.valueBlock = valueBlockType ? new valueBlockType(parameters) : new ValueBlock(parameters);
2901
2894
  }
2902
- fromBER(inputBuffer, inputOffset, inputLength) {
2903
- 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);
2904
2897
  if (resultOffset === -1) {
2905
2898
  this.error = this.valueBlock.error;
2906
2899
  return resultOffset;
@@ -3036,6 +3029,55 @@ _a$w = Primitive;
3036
3029
  typeStore.Primitive = _a$w;
3037
3030
  })();
3038
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
+ }
3039
3081
  function localChangeType(inputObject, newType) {
3040
3082
  if (inputObject instanceof newType) {
3041
3083
  return inputObject;
@@ -3047,7 +3089,7 @@ function localChangeType(inputObject, newType) {
3047
3089
  newObject.valueBeforeDecodeView = inputObject.valueBeforeDecodeView;
3048
3090
  return newObject;
3049
3091
  }
3050
- function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.length) {
3092
+ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.length, context = createFromBerContext()) {
3051
3093
  const incomingOffset = inputOffset;
3052
3094
  let returnObject = new BaseBlock({}, ValueBlock);
3053
3095
  const baseBlock = new LocalBaseBlock();
@@ -3066,6 +3108,14 @@ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.le
3066
3108
  result: returnObject
3067
3109
  };
3068
3110
  }
3111
+ const nodesLimitError = checkNodesLimit(context);
3112
+ if (nodesLimitError) {
3113
+ returnObject.error = nodesLimitError;
3114
+ return {
3115
+ offset: -1,
3116
+ result: returnObject
3117
+ };
3118
+ }
3069
3119
  let resultOffset = returnObject.idBlock.fromBER(inputBuffer, inputOffset, inputLength);
3070
3120
  if (returnObject.idBlock.warnings.length) {
3071
3121
  returnObject.warnings.concat(returnObject.idBlock.warnings);
@@ -3092,6 +3142,15 @@ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.le
3092
3142
  }
3093
3143
  inputOffset = resultOffset;
3094
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
+ }
3095
3154
  if (!returnObject.idBlock.isConstructed && returnObject.lenBlock.isIndefiniteForm) {
3096
3155
  returnObject.error = "Indefinite length form used for primitive encoding form";
3097
3156
  return {
@@ -3230,14 +3289,14 @@ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.le
3230
3289
  }
3231
3290
  }
3232
3291
  returnObject = localChangeType(returnObject, newASN1Type);
3233
- resultOffset = returnObject.fromBER(inputBuffer, inputOffset, returnObject.lenBlock.isIndefiniteForm ? inputLength : returnObject.lenBlock.length);
3292
+ resultOffset = returnObject.fromBER(inputBuffer, inputOffset, valueLength, context);
3234
3293
  returnObject.valueBeforeDecodeView = inputBuffer.subarray(incomingOffset, incomingOffset + returnObject.blockLength);
3235
3294
  return {
3236
3295
  offset: resultOffset,
3237
3296
  result: returnObject
3238
3297
  };
3239
3298
  }
3240
- function fromBER(inputBuffer) {
3299
+ function fromBER(inputBuffer, options = {}) {
3241
3300
  if (!inputBuffer.byteLength) {
3242
3301
  const result = new BaseBlock({}, ValueBlock);
3243
3302
  result.error = "Input buffer has zero length";
@@ -3246,7 +3305,7 @@ function fromBER(inputBuffer) {
3246
3305
  result
3247
3306
  };
3248
3307
  }
3249
- return localFromBER(BufferSourceConverter.toUint8Array(inputBuffer).slice(), 0, inputBuffer.byteLength);
3308
+ return localFromBER(BufferSourceConverter.toUint8Array(inputBuffer).slice(), 0, inputBuffer.byteLength, createFromBerContext(options));
3250
3309
  }
3251
3310
  function checkLen(indefiniteLength, length) {
3252
3311
  if (indefiniteLength) {
@@ -3260,8 +3319,9 @@ var LocalConstructedValueBlock = class extends ValueBlock {
3260
3319
  this.value = value;
3261
3320
  this.isIndefiniteForm = isIndefiniteForm;
3262
3321
  }
3263
- fromBER(inputBuffer, inputOffset, inputLength) {
3322
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
3264
3323
  const view = BufferSourceConverter.toUint8Array(inputBuffer);
3324
+ const parseContext = context !== null && context !== void 0 ? context : createFromBerContext();
3265
3325
  if (!checkBufferParams(this, view, inputOffset, inputLength)) {
3266
3326
  return -1;
3267
3327
  }
@@ -3272,7 +3332,7 @@ var LocalConstructedValueBlock = class extends ValueBlock {
3272
3332
  }
3273
3333
  let currentOffset = inputOffset;
3274
3334
  while (checkLen(this.isIndefiniteForm, inputLength) > 0) {
3275
- const returnObject = localFromBER(view, currentOffset, inputLength);
3335
+ const returnObject = localFromBERWithChildContext(view, currentOffset, inputLength, parseContext);
3276
3336
  if (returnObject.offset === -1) {
3277
3337
  this.error = returnObject.result.error;
3278
3338
  this.warnings.concat(returnObject.result.warnings);
@@ -3324,9 +3384,9 @@ var Constructed = class extends BaseBlock {
3324
3384
  super(parameters, LocalConstructedValueBlock);
3325
3385
  this.idBlock.isConstructed = true;
3326
3386
  }
3327
- fromBER(inputBuffer, inputOffset, inputLength) {
3387
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
3328
3388
  this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
3329
- 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);
3330
3390
  if (resultOffset === -1) {
3331
3391
  this.error = this.valueBlock.error;
3332
3392
  return resultOffset;
@@ -3492,11 +3552,11 @@ var LocalOctetStringValueBlock = class extends HexBlock(LocalConstructedValueBlo
3492
3552
  super(parameters);
3493
3553
  this.isConstructed = isConstructed;
3494
3554
  }
3495
- fromBER(inputBuffer, inputOffset, inputLength) {
3555
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
3496
3556
  let resultOffset = 0;
3497
3557
  if (this.isConstructed) {
3498
3558
  this.isHexOnly = false;
3499
- resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength);
3559
+ resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength, context);
3500
3560
  if (resultOffset === -1)
3501
3561
  return resultOffset;
3502
3562
  for (let i = 0; i < this.value.length; i++) {
@@ -3553,7 +3613,7 @@ var OctetString = class extends BaseBlock {
3553
3613
  this.idBlock.tagClass = 1;
3554
3614
  this.idBlock.tagNumber = 4;
3555
3615
  }
3556
- fromBER(inputBuffer, inputOffset, inputLength) {
3616
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
3557
3617
  this.valueBlock.isConstructed = this.idBlock.isConstructed;
3558
3618
  this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
3559
3619
  if (inputLength === 0) {
@@ -3568,7 +3628,8 @@ var OctetString = class extends BaseBlock {
3568
3628
  const buf = view.subarray(inputOffset, inputOffset + inputLength);
3569
3629
  try {
3570
3630
  if (buf.byteLength) {
3571
- 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);
3572
3633
  if (asn.offset !== -1 && asn.offset === inputLength) {
3573
3634
  this.valueBlock.value = [asn.result];
3574
3635
  }
@@ -3576,7 +3637,7 @@ var OctetString = class extends BaseBlock {
3576
3637
  } catch (e3) {
3577
3638
  }
3578
3639
  }
3579
- return super.fromBER(inputBuffer, inputOffset, inputLength);
3640
+ return super.fromBER(inputBuffer, inputOffset, inputLength, context);
3580
3641
  }
3581
3642
  onAsciiEncoding() {
3582
3643
  if (this.valueBlock.isConstructed || this.valueBlock.value && this.valueBlock.value.length) {
@@ -3611,13 +3672,13 @@ var LocalBitStringValueBlock = class extends HexBlock(LocalConstructedValueBlock
3611
3672
  this.isConstructed = isConstructed;
3612
3673
  this.blockLength = this.valueHexView.byteLength;
3613
3674
  }
3614
- fromBER(inputBuffer, inputOffset, inputLength) {
3675
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
3615
3676
  if (!inputLength) {
3616
3677
  return inputOffset;
3617
3678
  }
3618
3679
  let resultOffset = -1;
3619
3680
  if (this.isConstructed) {
3620
- resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength);
3681
+ resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength, context);
3621
3682
  if (resultOffset === -1)
3622
3683
  return resultOffset;
3623
3684
  for (const value of this.value) {
@@ -3657,7 +3718,8 @@ var LocalBitStringValueBlock = class extends HexBlock(LocalConstructedValueBlock
3657
3718
  const buf = intBuffer.subarray(1);
3658
3719
  try {
3659
3720
  if (buf.byteLength) {
3660
- 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);
3661
3723
  if (asn.offset !== -1 && asn.offset === inputLength - 1) {
3662
3724
  this.value = [asn.result];
3663
3725
  }
@@ -3714,10 +3776,10 @@ var BitString = class extends BaseBlock {
3714
3776
  this.idBlock.tagClass = 1;
3715
3777
  this.idBlock.tagNumber = 3;
3716
3778
  }
3717
- fromBER(inputBuffer, inputOffset, inputLength) {
3779
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
3718
3780
  this.valueBlock.isConstructed = this.idBlock.isConstructed;
3719
3781
  this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
3720
- return super.fromBER(inputBuffer, inputOffset, inputLength);
3782
+ return super.fromBER(inputBuffer, inputOffset, inputLength, context);
3721
3783
  }
3722
3784
  onAsciiEncoding() {
3723
3785
  if (this.valueBlock.isConstructed || this.valueBlock.value && this.valueBlock.value.length) {
@@ -5444,6 +5506,59 @@ function verifySchema(inputBuffer, inputSchema) {
5444
5506
  return compareSchema(asn12.result, asn12.result, inputSchema);
5445
5507
  }
5446
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
+
5447
5562
  // ../../node_modules/@peculiar/asn1-schema/build/es2015/enums.js
5448
5563
  var AsnTypeTypes;
5449
5564
  (function(AsnTypeTypes2) {
@@ -5484,7 +5599,7 @@ var AsnPropTypes;
5484
5599
 
5485
5600
  // ../../node_modules/@peculiar/asn1-schema/build/es2015/converters.js
5486
5601
  var AsnAnyConverter = {
5487
- fromASN: (value) => value instanceof Null ? null : value.valueBeforeDecodeView,
5602
+ fromASN: (value) => value instanceof Null ? null : toArrayBuffer(value.valueBeforeDecodeView),
5488
5603
  toASN: (value) => {
5489
5604
  if (value === null) {
5490
5605
  return new Null();
@@ -5505,7 +5620,7 @@ var AsnEnumeratedConverter = {
5505
5620
  toASN: (value) => new Enumerated({ value })
5506
5621
  };
5507
5622
  var AsnBitStringConverter = {
5508
- fromASN: (value) => value.valueBlock.valueHexView,
5623
+ fromASN: (value) => toArrayBuffer(value.valueBlock.valueHexView),
5509
5624
  toASN: (value) => new BitString({ valueHex: value })
5510
5625
  };
5511
5626
  var AsnObjectIdentifierConverter = {
@@ -5517,7 +5632,7 @@ var AsnBooleanConverter = {
5517
5632
  toASN: (value) => new Boolean({ value })
5518
5633
  };
5519
5634
  var AsnOctetStringConverter = {
5520
- fromASN: (value) => value.valueBlock.valueHexView,
5635
+ fromASN: (value) => toArrayBuffer(value.valueBlock.valueHexView),
5521
5636
  toASN: (value) => new OctetString({ valueHex: value })
5522
5637
  };
5523
5638
  function createStringConverter(Asn1Type) {
@@ -5616,10 +5731,9 @@ function isConvertible(target) {
5616
5731
  }
5617
5732
  }
5618
5733
  function isTypeOfArray(target) {
5619
- var _a2;
5620
5734
  if (target) {
5621
5735
  const proto = Object.getPrototypeOf(target);
5622
- 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) {
5623
5737
  return true;
5624
5738
  }
5625
5739
  return isTypeOfArray(proto);
@@ -5644,10 +5758,8 @@ function isArrayEqual(bytes1, bytes2) {
5644
5758
  }
5645
5759
 
5646
5760
  // ../../node_modules/@peculiar/asn1-schema/build/es2015/schema.js
5647
- var AsnSchemaStorage = class {
5648
- constructor() {
5649
- this.items = /* @__PURE__ */ new WeakMap();
5650
- }
5761
+ var AsnSchemaStorage = (_class2 = class {constructor() { _class2.prototype.__init2.call(this); }
5762
+ __init2() {this.items = /* @__PURE__ */ new WeakMap()}
5651
5763
  has(target) {
5652
5764
  return this.items.has(target);
5653
5765
  }
@@ -5668,7 +5780,10 @@ var AsnSchemaStorage = class {
5668
5780
  }
5669
5781
  }
5670
5782
  createDefault(target) {
5671
- const schema = { type: AsnTypeTypes.Sequence, items: {} };
5783
+ const schema = {
5784
+ type: AsnTypeTypes.Sequence,
5785
+ items: {}
5786
+ };
5672
5787
  const parentSchema = this.findParentSchema(target);
5673
5788
  if (parentSchema) {
5674
5789
  Object.assign(schema, parentSchema);
@@ -5710,14 +5825,24 @@ var AsnSchemaStorage = class {
5710
5825
  const Container = item.repeated === "set" ? Set : Sequence;
5711
5826
  asn1Item = new Container({
5712
5827
  name: "",
5713
- value: [new Repeated({ name, value: asn1Item })]
5828
+ value: [new Repeated({
5829
+ name,
5830
+ value: asn1Item
5831
+ })]
5714
5832
  });
5715
5833
  }
5716
5834
  if (item.context !== null && item.context !== void 0) {
5717
5835
  if (item.implicit) {
5718
5836
  if (typeof item.type === "number" || isConvertible(item.type)) {
5719
5837
  const Container = item.repeated ? Constructed : Primitive;
5720
- 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
+ }));
5721
5846
  } else {
5722
5847
  this.cache(item.type);
5723
5848
  const isRepeated = !!item.repeated;
@@ -5726,14 +5851,20 @@ var AsnSchemaStorage = class {
5726
5851
  asn1Value.push(new Constructed({
5727
5852
  name: !isRepeated ? name : "",
5728
5853
  optional,
5729
- idBlock: { tagClass: 3, tagNumber: item.context },
5854
+ idBlock: {
5855
+ tagClass: 3,
5856
+ tagNumber: item.context
5857
+ },
5730
5858
  value
5731
5859
  }));
5732
5860
  }
5733
5861
  } else {
5734
5862
  asn1Value.push(new Constructed({
5735
5863
  optional,
5736
- idBlock: { tagClass: 3, tagNumber: item.context },
5864
+ idBlock: {
5865
+ tagClass: 3,
5866
+ tagNumber: item.context
5867
+ },
5737
5868
  value: [asn1Item]
5738
5869
  }));
5739
5870
  }
@@ -5744,13 +5875,22 @@ var AsnSchemaStorage = class {
5744
5875
  }
5745
5876
  switch (schema.type) {
5746
5877
  case AsnTypeTypes.Sequence:
5747
- return new Sequence({ value: asn1Value, name: "" });
5878
+ return new Sequence({
5879
+ value: asn1Value,
5880
+ name: ""
5881
+ });
5748
5882
  case AsnTypeTypes.Set:
5749
- return new Set({ value: asn1Value, name: "" });
5883
+ return new Set({
5884
+ value: asn1Value,
5885
+ name: ""
5886
+ });
5750
5887
  case AsnTypeTypes.Choice:
5751
- return new Choice({ value: asn1Value, name: "" });
5888
+ return new Choice({
5889
+ value: asn1Value,
5890
+ name: ""
5891
+ });
5752
5892
  default:
5753
- throw new Error(`Unsupported ASN1 type in use`);
5893
+ throw new Error("Unsupported ASN1 type in use");
5754
5894
  }
5755
5895
  }
5756
5896
  set(target, schema) {
@@ -5765,23 +5905,20 @@ var AsnSchemaStorage = class {
5765
5905
  }
5766
5906
  return null;
5767
5907
  }
5768
- };
5908
+ }, _class2);
5769
5909
 
5770
5910
  // ../../node_modules/@peculiar/asn1-schema/build/es2015/storage.js
5771
5911
  var schemaStorage = new AsnSchemaStorage();
5772
5912
 
5773
5913
  // ../../node_modules/@peculiar/asn1-schema/build/es2015/errors/schema_validation.js
5774
- var AsnSchemaValidationError = class extends Error {
5775
- constructor() {
5776
- super(...arguments);
5777
- this.schemas = [];
5778
- }
5779
- };
5914
+ var AsnSchemaValidationError = (_class3 = class extends Error {constructor(...args2) { super(...args2); _class3.prototype.__init3.call(this); }
5915
+ __init3() {this.schemas = []}
5916
+ }, _class3);
5780
5917
 
5781
5918
  // ../../node_modules/@peculiar/asn1-schema/build/es2015/parser.js
5782
5919
  var AsnParser = class {
5783
5920
  static parse(data, target) {
5784
- const asn1Parsed = fromBER(data);
5921
+ const asn1Parsed = fromBER(toArrayBuffer(data));
5785
5922
  if (asn1Parsed.result.error) {
5786
5923
  throw new Error(asn1Parsed.result.error);
5787
5924
  }
@@ -5798,10 +5935,10 @@ var AsnParser = class {
5798
5935
  schemaStorage.cache(target);
5799
5936
  let targetSchema = schema.schema;
5800
5937
  const choiceResult = this.handleChoiceTypes(asn1Schema, schema, target, targetSchema);
5801
- if (choiceResult === null || choiceResult === void 0 ? void 0 : choiceResult.result) {
5938
+ if (_optionalChain([choiceResult, 'optionalAccess', _19 => _19.result])) {
5802
5939
  return choiceResult.result;
5803
5940
  }
5804
- if (choiceResult === null || choiceResult === void 0 ? void 0 : choiceResult.targetSchema) {
5941
+ if (_optionalChain([choiceResult, 'optionalAccess', _20 => _20.targetSchema])) {
5805
5942
  targetSchema = choiceResult.targetSchema;
5806
5943
  }
5807
5944
  const sequenceResult = this.handleSequenceTypes(asn1Schema, schema, target, targetSchema);
@@ -5909,7 +6046,10 @@ var AsnParser = class {
5909
6046
  static processOptionalChoiceField(asn1Element, schemaItem) {
5910
6047
  try {
5911
6048
  const value = this.fromASN(asn1Element, schemaItem.type);
5912
- return { processed: true, value };
6049
+ return {
6050
+ processed: true,
6051
+ value
6052
+ };
5913
6053
  } catch (err) {
5914
6054
  if (err instanceof AsnSchemaValidationError && /Wrong values for Choice type/.test(err.message)) {
5915
6055
  return { processed: false };
@@ -5919,7 +6059,7 @@ var AsnParser = class {
5919
6059
  }
5920
6060
  static handleArrayTypes(asn1Schema, schema, target) {
5921
6061
  if (!("value" in asn1Schema.valueBlock && Array.isArray(asn1Schema.valueBlock.value))) {
5922
- 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.");
5923
6063
  }
5924
6064
  const itemType = schema.itemType;
5925
6065
  if (typeof itemType === "number") {
@@ -5955,8 +6095,7 @@ var AsnParser = class {
5955
6095
  }
5956
6096
  }
5957
6097
  static processPrimitiveSchemaItem(asn1SchemaValue, schemaItem, schemaItemType) {
5958
- var _a2;
5959
- 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)));
5960
6099
  if (!converter) {
5961
6100
  throw new Error("Converter is empty");
5962
6101
  }
@@ -6097,7 +6236,7 @@ var AsnSerializer = class _AsnSerializer {
6097
6236
  if (schemaItem.implicit) {
6098
6237
  if (!schemaItem.repeated && (typeof schemaItem.type === "number" || isConvertible(schemaItem.type))) {
6099
6238
  const value = {};
6100
- value.valueHex = asn1Item instanceof Null ? asn1Item.valueBeforeDecodeView : asn1Item.valueBlock.toBER();
6239
+ value.valueHex = asn1Item instanceof Null ? toArrayBuffer(asn1Item.valueBeforeDecodeView) : asn1Item.valueBlock.toBER();
6101
6240
  asn1Value.push(new Primitive({
6102
6241
  optional: schemaItem.optional,
6103
6242
  idBlock: {
@@ -6163,9 +6302,7 @@ var AsnSerializer = class _AsnSerializer {
6163
6302
  }
6164
6303
  const items = Array.from(objProp, (element) => converter.toASN(element));
6165
6304
  const Container = schemaItem.repeated === "sequence" ? Sequence : Set;
6166
- asn1Item = new Container({
6167
- value: items
6168
- });
6305
+ asn1Item = new Container({ value: items });
6169
6306
  } else {
6170
6307
  asn1Item = converter.toASN(objProp);
6171
6308
  }
@@ -6176,9 +6313,7 @@ var AsnSerializer = class _AsnSerializer {
6176
6313
  }
6177
6314
  const items = Array.from(objProp, (element) => this.toASN(element));
6178
6315
  const Container = schemaItem.repeated === "sequence" ? Sequence : Set;
6179
- asn1Item = new Container({
6180
- value: items
6181
- });
6316
+ asn1Item = new Container({ value: items });
6182
6317
  } else {
6183
6318
  asn1Item = this.toASN(objProp);
6184
6319
  }
@@ -6196,7 +6331,7 @@ var AsnConvert = class _AsnConvert {
6196
6331
  return AsnParser.parse(data, target);
6197
6332
  }
6198
6333
  static toString(data) {
6199
- const buf = BufferSourceConverter.isBufferSource(data) ? BufferSourceConverter.toArrayBuffer(data) : _AsnConvert.serialize(data);
6334
+ const buf = isBufferSource(data) ? toArrayBuffer(data) : _AsnConvert.serialize(data);
6200
6335
  const asn = fromBER(buf);
6201
6336
  if (asn.offset === -1) {
6202
6337
  throw new Error(`Cannot decode ASN.1 data. ${asn.result.error}`);
@@ -6278,7 +6413,7 @@ async function createSelfSignedCertificate({
6278
6413
  function rsaLengthPrivateKey(key) {
6279
6414
  const keyPem = typeof key.hidden === "string" ? key.hidden : key.hidden.export({ type: "pkcs1", format: "pem" }).toString();
6280
6415
  const keyObject = _crypto2.createPrivateKey.call(void 0, keyPem);
6281
- 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]);
6282
6417
  _assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from private key");
6283
6418
  return modulusLength / 8;
6284
6419
  }
@@ -6321,7 +6456,7 @@ function rsaLengthPublicKey(key) {
6321
6456
  key = coercePublicKeyPem(key);
6322
6457
  _assert2.default.call(void 0, typeof key === "string");
6323
6458
  const keyObject = _crypto2.createPublicKey.call(void 0, key);
6324
- 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]);
6325
6460
  _assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from public key");
6326
6461
  return modulusLength / 8;
6327
6462
  }
@@ -6329,7 +6464,7 @@ function rsaLengthRsaPublicKey(key) {
6329
6464
  key = coerceRsaPublicKeyPem(key);
6330
6465
  _assert2.default.call(void 0, typeof key === "string");
6331
6466
  const keyObject = _crypto2.createPublicKey.call(void 0, key);
6332
- 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]);
6333
6468
  _assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from public key");
6334
6469
  return modulusLength / 8;
6335
6470
  }
@@ -6634,4 +6769,4 @@ asn1js/build/index.es.js:
6634
6769
  *
6635
6770
  *)
6636
6771
  */
6637
- //# sourceMappingURL=chunk-LRB5Q533.cjs.map
6772
+ //# sourceMappingURL=chunk-FRVYTI7S.cjs.map