node-opcua-crypto 4.16.0 → 4.16.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.
- package/LICENSE +23 -23
- package/dist/{chunk-XPM4YIBT.mjs → chunk-JDT2M2NN.mjs} +7 -7
- package/dist/{chunk-F5EAPW2U.mjs → chunk-MGQCHN54.mjs} +339 -202
- package/dist/chunk-MGQCHN54.mjs.map +1 -0
- package/dist/index.js +337 -200
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/source/index.js +337 -200
- package/dist/source/index.js.map +1 -1
- package/dist/source/index.mjs +1 -1
- package/dist/source/index_web.js +337 -200
- package/dist/source/index_web.js.map +1 -1
- package/dist/source/index_web.mjs +1 -1
- package/dist/source_nodejs/index.js +99 -116
- package/dist/source_nodejs/index.js.map +1 -1
- package/dist/source_nodejs/index.mjs +2 -2
- package/package.json +5 -5
- package/dist/chunk-F5EAPW2U.mjs.map +0 -1
- /package/dist/{chunk-XPM4YIBT.mjs.map → chunk-JDT2M2NN.mjs.map} +0 -0
|
@@ -11,8 +11,8 @@ var __export = (target, all) => {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
// ../../node_modules/tsup/assets/esm_shims.js
|
|
14
|
-
import { fileURLToPath } from "url";
|
|
15
14
|
import path from "path";
|
|
15
|
+
import { fileURLToPath } from "url";
|
|
16
16
|
var getFilename = () => fileURLToPath(import.meta.url);
|
|
17
17
|
var getDirname = () => path.dirname(getFilename());
|
|
18
18
|
var __dirname = /* @__PURE__ */ getDirname();
|
|
@@ -2113,7 +2113,7 @@ var BufferSourceConverter = class _BufferSourceConverter {
|
|
|
2113
2113
|
}
|
|
2114
2114
|
};
|
|
2115
2115
|
var STRING_TYPE = "string";
|
|
2116
|
-
var HEX_REGEX = /^[0-9a-f]+$/i;
|
|
2116
|
+
var HEX_REGEX = /^[0-9a-f\s]+$/i;
|
|
2117
2117
|
var BASE64_REGEX = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
2118
2118
|
var BASE64URL_REGEX = /^[a-zA-Z0-9-_]+$/;
|
|
2119
2119
|
var Utf8Converter = class {
|
|
@@ -2561,19 +2561,19 @@ var BIT_STRING_NAME = "BIT STRING";
|
|
|
2561
2561
|
function HexBlock(BaseClass) {
|
|
2562
2562
|
var _a2;
|
|
2563
2563
|
return _a2 = class Some extends BaseClass {
|
|
2564
|
-
constructor(...args) {
|
|
2565
|
-
var _a3;
|
|
2566
|
-
super(...args);
|
|
2567
|
-
const params = args[0] || {};
|
|
2568
|
-
this.isHexOnly = (_a3 = params.isHexOnly) !== null && _a3 !== void 0 ? _a3 : false;
|
|
2569
|
-
this.valueHexView = params.valueHex ? BufferSourceConverter.toUint8Array(params.valueHex) : EMPTY_VIEW;
|
|
2570
|
-
}
|
|
2571
2564
|
get valueHex() {
|
|
2572
2565
|
return this.valueHexView.slice().buffer;
|
|
2573
2566
|
}
|
|
2574
2567
|
set valueHex(value) {
|
|
2575
2568
|
this.valueHexView = new Uint8Array(value);
|
|
2576
2569
|
}
|
|
2570
|
+
constructor(...args) {
|
|
2571
|
+
var _b;
|
|
2572
|
+
super(...args);
|
|
2573
|
+
const params = args[0] || {};
|
|
2574
|
+
this.isHexOnly = (_b = params.isHexOnly) !== null && _b !== void 0 ? _b : false;
|
|
2575
|
+
this.valueHexView = params.valueHex ? BufferSourceConverter.toUint8Array(params.valueHex) : EMPTY_VIEW;
|
|
2576
|
+
}
|
|
2577
2577
|
fromBER(inputBuffer, inputOffset, inputLength) {
|
|
2578
2578
|
const view = inputBuffer instanceof ArrayBuffer ? new Uint8Array(inputBuffer) : inputBuffer;
|
|
2579
2579
|
if (!checkBufferParams(this, view, inputOffset, inputLength)) {
|
|
@@ -2608,12 +2608,6 @@ function HexBlock(BaseClass) {
|
|
|
2608
2608
|
}, _a2.NAME = "hexBlock", _a2;
|
|
2609
2609
|
}
|
|
2610
2610
|
var LocalBaseBlock = class {
|
|
2611
|
-
constructor({ blockLength = 0, error = EMPTY_STRING, warnings = [], valueBeforeDecode = EMPTY_VIEW } = {}) {
|
|
2612
|
-
this.blockLength = blockLength;
|
|
2613
|
-
this.error = error;
|
|
2614
|
-
this.warnings = warnings;
|
|
2615
|
-
this.valueBeforeDecodeView = BufferSourceConverter.toUint8Array(valueBeforeDecode);
|
|
2616
|
-
}
|
|
2617
2611
|
static blockName() {
|
|
2618
2612
|
return this.NAME;
|
|
2619
2613
|
}
|
|
@@ -2623,6 +2617,12 @@ var LocalBaseBlock = class {
|
|
|
2623
2617
|
set valueBeforeDecode(value) {
|
|
2624
2618
|
this.valueBeforeDecodeView = new Uint8Array(value);
|
|
2625
2619
|
}
|
|
2620
|
+
constructor({ blockLength = 0, error = EMPTY_STRING, warnings = [], valueBeforeDecode = EMPTY_VIEW } = {}) {
|
|
2621
|
+
this.blockLength = blockLength;
|
|
2622
|
+
this.error = error;
|
|
2623
|
+
this.warnings = warnings;
|
|
2624
|
+
this.valueBeforeDecodeView = BufferSourceConverter.toUint8Array(valueBeforeDecode);
|
|
2625
|
+
}
|
|
2626
2626
|
toJSON() {
|
|
2627
2627
|
return {
|
|
2628
2628
|
blockName: this.constructor.NAME,
|
|
@@ -2635,10 +2635,10 @@ var LocalBaseBlock = class {
|
|
|
2635
2635
|
};
|
|
2636
2636
|
LocalBaseBlock.NAME = "baseBlock";
|
|
2637
2637
|
var ValueBlock = class extends LocalBaseBlock {
|
|
2638
|
-
fromBER(
|
|
2638
|
+
fromBER(_inputBuffer, _inputOffset, _inputLength) {
|
|
2639
2639
|
throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'");
|
|
2640
2640
|
}
|
|
2641
|
-
toBER(
|
|
2641
|
+
toBER(_sizeOnly, _writer) {
|
|
2642
2642
|
throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'");
|
|
2643
2643
|
}
|
|
2644
2644
|
};
|
|
@@ -2979,7 +2979,9 @@ var BaseBlock = class extends LocalBaseBlock {
|
|
|
2979
2979
|
return Convert.ToHex(this.toBER());
|
|
2980
2980
|
}
|
|
2981
2981
|
onAsciiEncoding() {
|
|
2982
|
-
|
|
2982
|
+
const name = this.constructor.NAME;
|
|
2983
|
+
const value = Convert.ToHex(this.valueBlock.valueBeforeDecodeView);
|
|
2984
|
+
return `${name} : ${value}`;
|
|
2983
2985
|
}
|
|
2984
2986
|
isEqual(other) {
|
|
2985
2987
|
if (this === other) {
|
|
@@ -2995,6 +2997,7 @@ var BaseBlock = class extends LocalBaseBlock {
|
|
|
2995
2997
|
};
|
|
2996
2998
|
BaseBlock.NAME = "BaseBlock";
|
|
2997
2999
|
function prepareIndefiniteForm(baseBlock) {
|
|
3000
|
+
var _a2;
|
|
2998
3001
|
if (baseBlock instanceof typeStore.Constructed) {
|
|
2999
3002
|
for (const value of baseBlock.valueBlock.value) {
|
|
3000
3003
|
if (prepareIndefiniteForm(value)) {
|
|
@@ -3002,21 +3005,21 @@ function prepareIndefiniteForm(baseBlock) {
|
|
|
3002
3005
|
}
|
|
3003
3006
|
}
|
|
3004
3007
|
}
|
|
3005
|
-
return !!baseBlock.lenBlock.isIndefiniteForm;
|
|
3008
|
+
return !!((_a2 = baseBlock.lenBlock) === null || _a2 === void 0 ? void 0 : _a2.isIndefiniteForm);
|
|
3006
3009
|
}
|
|
3007
3010
|
var BaseStringBlock = class extends BaseBlock {
|
|
3008
|
-
constructor({ value = EMPTY_STRING, ...parameters } = {}, stringValueBlockType) {
|
|
3009
|
-
super(parameters, stringValueBlockType);
|
|
3010
|
-
if (value) {
|
|
3011
|
-
this.fromString(value);
|
|
3012
|
-
}
|
|
3013
|
-
}
|
|
3014
3011
|
getValue() {
|
|
3015
3012
|
return this.valueBlock.value;
|
|
3016
3013
|
}
|
|
3017
3014
|
setValue(value) {
|
|
3018
3015
|
this.valueBlock.value = value;
|
|
3019
3016
|
}
|
|
3017
|
+
constructor({ value = EMPTY_STRING, ...parameters } = {}, stringValueBlockType) {
|
|
3018
|
+
super(parameters, stringValueBlockType);
|
|
3019
|
+
if (value) {
|
|
3020
|
+
this.fromString(value);
|
|
3021
|
+
}
|
|
3022
|
+
}
|
|
3020
3023
|
fromBER(inputBuffer, inputOffset, inputLength) {
|
|
3021
3024
|
const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length);
|
|
3022
3025
|
if (resultOffset === -1) {
|
|
@@ -3375,10 +3378,10 @@ _a$v = Constructed;
|
|
|
3375
3378
|
})();
|
|
3376
3379
|
Constructed.NAME = "CONSTRUCTED";
|
|
3377
3380
|
var LocalEndOfContentValueBlock = class extends ValueBlock {
|
|
3378
|
-
fromBER(inputBuffer, inputOffset,
|
|
3381
|
+
fromBER(inputBuffer, inputOffset, _inputLength) {
|
|
3379
3382
|
return inputOffset;
|
|
3380
3383
|
}
|
|
3381
|
-
toBER(
|
|
3384
|
+
toBER(_sizeOnly) {
|
|
3382
3385
|
return EMPTY_BUFFER;
|
|
3383
3386
|
}
|
|
3384
3387
|
};
|
|
@@ -3439,17 +3442,6 @@ _a$t = Null;
|
|
|
3439
3442
|
})();
|
|
3440
3443
|
Null.NAME = "NULL";
|
|
3441
3444
|
var LocalBooleanValueBlock = class extends HexBlock(ValueBlock) {
|
|
3442
|
-
constructor({ value, ...parameters } = {}) {
|
|
3443
|
-
super(parameters);
|
|
3444
|
-
if (parameters.valueHex) {
|
|
3445
|
-
this.valueHexView = BufferSourceConverter.toUint8Array(parameters.valueHex);
|
|
3446
|
-
} else {
|
|
3447
|
-
this.valueHexView = new Uint8Array(1);
|
|
3448
|
-
}
|
|
3449
|
-
if (value) {
|
|
3450
|
-
this.value = value;
|
|
3451
|
-
}
|
|
3452
|
-
}
|
|
3453
3445
|
get value() {
|
|
3454
3446
|
for (const octet of this.valueHexView) {
|
|
3455
3447
|
if (octet > 0) {
|
|
@@ -3461,6 +3453,17 @@ var LocalBooleanValueBlock = class extends HexBlock(ValueBlock) {
|
|
|
3461
3453
|
set value(value) {
|
|
3462
3454
|
this.valueHexView[0] = value ? 255 : 0;
|
|
3463
3455
|
}
|
|
3456
|
+
constructor({ value, ...parameters } = {}) {
|
|
3457
|
+
super(parameters);
|
|
3458
|
+
if (parameters.valueHex) {
|
|
3459
|
+
this.valueHexView = BufferSourceConverter.toUint8Array(parameters.valueHex);
|
|
3460
|
+
} else {
|
|
3461
|
+
this.valueHexView = new Uint8Array(1);
|
|
3462
|
+
}
|
|
3463
|
+
if (value) {
|
|
3464
|
+
this.value = value;
|
|
3465
|
+
}
|
|
3466
|
+
}
|
|
3464
3467
|
fromBER(inputBuffer, inputOffset, inputLength) {
|
|
3465
3468
|
const inputView = BufferSourceConverter.toUint8Array(inputBuffer);
|
|
3466
3469
|
if (!checkBufferParams(this, inputView, inputOffset, inputLength)) {
|
|
@@ -3487,17 +3490,17 @@ var LocalBooleanValueBlock = class extends HexBlock(ValueBlock) {
|
|
|
3487
3490
|
LocalBooleanValueBlock.NAME = "BooleanValueBlock";
|
|
3488
3491
|
var _a$s;
|
|
3489
3492
|
var Boolean = class extends BaseBlock {
|
|
3490
|
-
constructor(parameters = {}) {
|
|
3491
|
-
super(parameters, LocalBooleanValueBlock);
|
|
3492
|
-
this.idBlock.tagClass = 1;
|
|
3493
|
-
this.idBlock.tagNumber = 1;
|
|
3494
|
-
}
|
|
3495
3493
|
getValue() {
|
|
3496
3494
|
return this.valueBlock.value;
|
|
3497
3495
|
}
|
|
3498
3496
|
setValue(value) {
|
|
3499
3497
|
this.valueBlock.value = value;
|
|
3500
3498
|
}
|
|
3499
|
+
constructor(parameters = {}) {
|
|
3500
|
+
super(parameters, LocalBooleanValueBlock);
|
|
3501
|
+
this.idBlock.tagClass = 1;
|
|
3502
|
+
this.idBlock.tagNumber = 1;
|
|
3503
|
+
}
|
|
3501
3504
|
onAsciiEncoding() {
|
|
3502
3505
|
return `${this.constructor.NAME} : ${this.getValue}`;
|
|
3503
3506
|
}
|
|
@@ -3555,7 +3558,7 @@ var LocalOctetStringValueBlock = class extends HexBlock(LocalConstructedValueBlo
|
|
|
3555
3558
|
};
|
|
3556
3559
|
LocalOctetStringValueBlock.NAME = "OctetStringValueBlock";
|
|
3557
3560
|
var _a$r;
|
|
3558
|
-
var OctetString = class
|
|
3561
|
+
var OctetString = class extends BaseBlock {
|
|
3559
3562
|
constructor({ idBlock = {}, lenBlock = {}, ...parameters } = {}) {
|
|
3560
3563
|
var _b, _c;
|
|
3561
3564
|
(_b = parameters.isConstructed) !== null && _b !== void 0 ? _b : parameters.isConstructed = !!((_c = parameters.value) === null || _c === void 0 ? void 0 : _c.length);
|
|
@@ -3593,7 +3596,7 @@ var OctetString = class _OctetString extends BaseBlock {
|
|
|
3593
3596
|
this.valueBlock.value = [asn.result];
|
|
3594
3597
|
}
|
|
3595
3598
|
}
|
|
3596
|
-
} catch
|
|
3599
|
+
} catch {
|
|
3597
3600
|
}
|
|
3598
3601
|
}
|
|
3599
3602
|
return super.fromBER(inputBuffer, inputOffset, inputLength);
|
|
@@ -3602,7 +3605,9 @@ var OctetString = class _OctetString extends BaseBlock {
|
|
|
3602
3605
|
if (this.valueBlock.isConstructed || this.valueBlock.value && this.valueBlock.value.length) {
|
|
3603
3606
|
return Constructed.prototype.onAsciiEncoding.call(this);
|
|
3604
3607
|
}
|
|
3605
|
-
|
|
3608
|
+
const name = this.constructor.NAME;
|
|
3609
|
+
const value = Convert.ToHex(this.valueBlock.valueHexView);
|
|
3610
|
+
return `${name} : ${value}`;
|
|
3606
3611
|
}
|
|
3607
3612
|
getValue() {
|
|
3608
3613
|
if (!this.idBlock.isConstructed) {
|
|
@@ -3610,7 +3615,7 @@ var OctetString = class _OctetString extends BaseBlock {
|
|
|
3610
3615
|
}
|
|
3611
3616
|
const array = [];
|
|
3612
3617
|
for (const content of this.valueBlock.value) {
|
|
3613
|
-
if (content instanceof
|
|
3618
|
+
if (content instanceof _a$r) {
|
|
3614
3619
|
array.push(content.valueBlock.valueHexView);
|
|
3615
3620
|
}
|
|
3616
3621
|
}
|
|
@@ -3680,7 +3685,7 @@ var LocalBitStringValueBlock = class extends HexBlock(LocalConstructedValueBlock
|
|
|
3680
3685
|
this.value = [asn.result];
|
|
3681
3686
|
}
|
|
3682
3687
|
}
|
|
3683
|
-
} catch
|
|
3688
|
+
} catch {
|
|
3684
3689
|
}
|
|
3685
3690
|
}
|
|
3686
3691
|
this.valueHexView = intBuffer.subarray(1);
|
|
@@ -3695,7 +3700,9 @@ var LocalBitStringValueBlock = class extends HexBlock(LocalConstructedValueBlock
|
|
|
3695
3700
|
return new ArrayBuffer(this.valueHexView.byteLength + 1);
|
|
3696
3701
|
}
|
|
3697
3702
|
if (!this.valueHexView.byteLength) {
|
|
3698
|
-
|
|
3703
|
+
const empty = new Uint8Array(1);
|
|
3704
|
+
empty[0] = 0;
|
|
3705
|
+
return empty.buffer;
|
|
3699
3706
|
}
|
|
3700
3707
|
const retView = new Uint8Array(this.valueHexView.length + 1);
|
|
3701
3708
|
retView[0] = this.unusedBits;
|
|
@@ -3745,7 +3752,9 @@ var BitString = class extends BaseBlock {
|
|
|
3745
3752
|
bits.push(byte.toString(2).padStart(8, "0"));
|
|
3746
3753
|
}
|
|
3747
3754
|
const bitsStr = bits.join("");
|
|
3748
|
-
|
|
3755
|
+
const name = this.constructor.NAME;
|
|
3756
|
+
const value = bitsStr.substring(0, bitsStr.length - this.valueBlock.unusedBits);
|
|
3757
|
+
return `${name} : ${value}`;
|
|
3749
3758
|
}
|
|
3750
3759
|
}
|
|
3751
3760
|
};
|
|
@@ -3842,16 +3851,6 @@ function viewSub(first, second) {
|
|
|
3842
3851
|
return firstViewCopy.slice();
|
|
3843
3852
|
}
|
|
3844
3853
|
var LocalIntegerValueBlock = class extends HexBlock(ValueBlock) {
|
|
3845
|
-
constructor({ value, ...parameters } = {}) {
|
|
3846
|
-
super(parameters);
|
|
3847
|
-
this._valueDec = 0;
|
|
3848
|
-
if (parameters.valueHex) {
|
|
3849
|
-
this.setValueHex();
|
|
3850
|
-
}
|
|
3851
|
-
if (value !== void 0) {
|
|
3852
|
-
this.valueDec = value;
|
|
3853
|
-
}
|
|
3854
|
-
}
|
|
3855
3854
|
setValueHex() {
|
|
3856
3855
|
if (this.valueHexView.length >= 4) {
|
|
3857
3856
|
this.warnings.push("Too big Integer for decoding, hex only");
|
|
@@ -3864,6 +3863,16 @@ var LocalIntegerValueBlock = class extends HexBlock(ValueBlock) {
|
|
|
3864
3863
|
}
|
|
3865
3864
|
}
|
|
3866
3865
|
}
|
|
3866
|
+
constructor({ value, ...parameters } = {}) {
|
|
3867
|
+
super(parameters);
|
|
3868
|
+
this._valueDec = 0;
|
|
3869
|
+
if (parameters.valueHex) {
|
|
3870
|
+
this.setValueHex();
|
|
3871
|
+
}
|
|
3872
|
+
if (value !== void 0) {
|
|
3873
|
+
this.valueDec = value;
|
|
3874
|
+
}
|
|
3875
|
+
}
|
|
3867
3876
|
set valueDec(v) {
|
|
3868
3877
|
this._valueDec = v;
|
|
3869
3878
|
this.isHexOnly = false;
|
|
@@ -3976,7 +3985,7 @@ LocalIntegerValueBlock.NAME = "IntegerValueBlock";
|
|
|
3976
3985
|
});
|
|
3977
3986
|
})();
|
|
3978
3987
|
var _a$o;
|
|
3979
|
-
var Integer = class
|
|
3988
|
+
var Integer = class extends BaseBlock {
|
|
3980
3989
|
constructor(parameters = {}) {
|
|
3981
3990
|
super(parameters, LocalIntegerValueBlock);
|
|
3982
3991
|
this.idBlock.tagClass = 1;
|
|
@@ -4006,18 +4015,16 @@ var Integer = class _Integer extends BaseBlock {
|
|
|
4006
4015
|
}
|
|
4007
4016
|
writer.write(view);
|
|
4008
4017
|
}
|
|
4009
|
-
const res = new
|
|
4010
|
-
valueHex: writer.final()
|
|
4011
|
-
});
|
|
4018
|
+
const res = new _a$o({ valueHex: writer.final() });
|
|
4012
4019
|
return res;
|
|
4013
4020
|
}
|
|
4014
4021
|
convertToDER() {
|
|
4015
|
-
const integer = new
|
|
4022
|
+
const integer = new _a$o({ valueHex: this.valueBlock.valueHexView });
|
|
4016
4023
|
integer.valueBlock.toDER();
|
|
4017
4024
|
return integer;
|
|
4018
4025
|
}
|
|
4019
4026
|
convertFromDER() {
|
|
4020
|
-
return new
|
|
4027
|
+
return new _a$o({
|
|
4021
4028
|
valueHex: this.valueBlock.valueHexView[0] === 0 ? this.valueBlock.valueHexView.subarray(1) : this.valueBlock.valueHexView
|
|
4022
4029
|
});
|
|
4023
4030
|
}
|
|
@@ -4280,17 +4287,17 @@ var LocalObjectIdentifierValueBlock = class extends ValueBlock {
|
|
|
4280
4287
|
LocalObjectIdentifierValueBlock.NAME = "ObjectIdentifierValueBlock";
|
|
4281
4288
|
var _a$m;
|
|
4282
4289
|
var ObjectIdentifier = class extends BaseBlock {
|
|
4283
|
-
constructor(parameters = {}) {
|
|
4284
|
-
super(parameters, LocalObjectIdentifierValueBlock);
|
|
4285
|
-
this.idBlock.tagClass = 1;
|
|
4286
|
-
this.idBlock.tagNumber = 6;
|
|
4287
|
-
}
|
|
4288
4290
|
getValue() {
|
|
4289
4291
|
return this.valueBlock.toString();
|
|
4290
4292
|
}
|
|
4291
4293
|
setValue(value) {
|
|
4292
4294
|
this.valueBlock.fromString(value);
|
|
4293
4295
|
}
|
|
4296
|
+
constructor(parameters = {}) {
|
|
4297
|
+
super(parameters, LocalObjectIdentifierValueBlock);
|
|
4298
|
+
this.idBlock.tagClass = 1;
|
|
4299
|
+
this.idBlock.tagNumber = 6;
|
|
4300
|
+
}
|
|
4294
4301
|
onAsciiEncoding() {
|
|
4295
4302
|
return `${this.constructor.NAME} : ${this.valueBlock.toString() || "empty"}`;
|
|
4296
4303
|
}
|
|
@@ -4410,7 +4417,7 @@ var LocalRelativeObjectIdentifierValueBlock = class extends ValueBlock {
|
|
|
4410
4417
|
}
|
|
4411
4418
|
return resultOffset;
|
|
4412
4419
|
}
|
|
4413
|
-
toBER(sizeOnly,
|
|
4420
|
+
toBER(sizeOnly, _writer) {
|
|
4414
4421
|
const retBuffers = [];
|
|
4415
4422
|
for (let i = 0; i < this.value.length; i++) {
|
|
4416
4423
|
const valueBuf = this.value[i].toBER(sizeOnly);
|
|
@@ -4472,17 +4479,17 @@ var LocalRelativeObjectIdentifierValueBlock = class extends ValueBlock {
|
|
|
4472
4479
|
LocalRelativeObjectIdentifierValueBlock.NAME = "RelativeObjectIdentifierValueBlock";
|
|
4473
4480
|
var _a$l;
|
|
4474
4481
|
var RelativeObjectIdentifier = class extends BaseBlock {
|
|
4475
|
-
constructor(parameters = {}) {
|
|
4476
|
-
super(parameters, LocalRelativeObjectIdentifierValueBlock);
|
|
4477
|
-
this.idBlock.tagClass = 1;
|
|
4478
|
-
this.idBlock.tagNumber = 13;
|
|
4479
|
-
}
|
|
4480
4482
|
getValue() {
|
|
4481
4483
|
return this.valueBlock.toString();
|
|
4482
4484
|
}
|
|
4483
4485
|
setValue(value) {
|
|
4484
4486
|
this.valueBlock.fromString(value);
|
|
4485
4487
|
}
|
|
4488
|
+
constructor(parameters = {}) {
|
|
4489
|
+
super(parameters, LocalRelativeObjectIdentifierValueBlock);
|
|
4490
|
+
this.idBlock.tagClass = 1;
|
|
4491
|
+
this.idBlock.tagNumber = 13;
|
|
4492
|
+
}
|
|
4486
4493
|
onAsciiEncoding() {
|
|
4487
4494
|
return `${this.constructor.NAME} : ${this.valueBlock.toString() || "empty"}`;
|
|
4488
4495
|
}
|
|
@@ -4879,7 +4886,8 @@ var GeneralizedTime = class extends UTCTime {
|
|
|
4879
4886
|
this.millisecond = inputDate.getUTCMilliseconds();
|
|
4880
4887
|
}
|
|
4881
4888
|
toDate() {
|
|
4882
|
-
|
|
4889
|
+
const utcDate = Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minute, this.second, this.millisecond);
|
|
4890
|
+
return new Date(utcDate);
|
|
4883
4891
|
}
|
|
4884
4892
|
fromString(inputString) {
|
|
4885
4893
|
let isUTC = false;
|
|
@@ -5128,28 +5136,28 @@ var Repeated = class extends Any {
|
|
|
5128
5136
|
}
|
|
5129
5137
|
};
|
|
5130
5138
|
var RawData = class {
|
|
5131
|
-
constructor({ data = EMPTY_VIEW } = {}) {
|
|
5132
|
-
this.dataView = BufferSourceConverter.toUint8Array(data);
|
|
5133
|
-
}
|
|
5134
5139
|
get data() {
|
|
5135
5140
|
return this.dataView.slice().buffer;
|
|
5136
5141
|
}
|
|
5137
5142
|
set data(value) {
|
|
5138
5143
|
this.dataView = BufferSourceConverter.toUint8Array(value);
|
|
5139
5144
|
}
|
|
5145
|
+
constructor({ data = EMPTY_VIEW } = {}) {
|
|
5146
|
+
this.dataView = BufferSourceConverter.toUint8Array(data);
|
|
5147
|
+
}
|
|
5140
5148
|
fromBER(inputBuffer, inputOffset, inputLength) {
|
|
5141
5149
|
const endLength = inputOffset + inputLength;
|
|
5142
5150
|
this.dataView = BufferSourceConverter.toUint8Array(inputBuffer).subarray(inputOffset, endLength);
|
|
5143
5151
|
return endLength;
|
|
5144
5152
|
}
|
|
5145
|
-
toBER(
|
|
5153
|
+
toBER(_sizeOnly) {
|
|
5146
5154
|
return this.dataView.slice().buffer;
|
|
5147
5155
|
}
|
|
5148
5156
|
};
|
|
5149
5157
|
function compareSchema(root, inputData, inputSchema) {
|
|
5150
5158
|
if (inputSchema instanceof Choice) {
|
|
5151
|
-
for (
|
|
5152
|
-
const result = compareSchema(root, inputData,
|
|
5159
|
+
for (const element of inputSchema.value) {
|
|
5160
|
+
const result = compareSchema(root, inputData, element);
|
|
5153
5161
|
if (result.verified) {
|
|
5154
5162
|
return {
|
|
5155
5163
|
verified: true,
|
|
@@ -5160,9 +5168,7 @@ function compareSchema(root, inputData, inputSchema) {
|
|
|
5160
5168
|
{
|
|
5161
5169
|
const _result = {
|
|
5162
5170
|
verified: false,
|
|
5163
|
-
result: {
|
|
5164
|
-
error: "Wrong values for Choice type"
|
|
5165
|
-
}
|
|
5171
|
+
result: { error: "Wrong values for Choice type" }
|
|
5166
5172
|
};
|
|
5167
5173
|
if (inputSchema.hasOwnProperty(NAME))
|
|
5168
5174
|
_result.name = inputSchema.name;
|
|
@@ -5308,9 +5314,7 @@ function compareSchema(root, inputData, inputSchema) {
|
|
|
5308
5314
|
let admission = 0;
|
|
5309
5315
|
let result = {
|
|
5310
5316
|
verified: false,
|
|
5311
|
-
result: {
|
|
5312
|
-
error: "Unknown error"
|
|
5313
|
-
}
|
|
5317
|
+
result: { error: "Unknown error" }
|
|
5314
5318
|
};
|
|
5315
5319
|
let maxLength = inputSchema.valueBlock.value.length;
|
|
5316
5320
|
if (maxLength > 0) {
|
|
@@ -5687,10 +5691,7 @@ var AsnSchemaStorage = class {
|
|
|
5687
5691
|
}
|
|
5688
5692
|
}
|
|
5689
5693
|
createDefault(target) {
|
|
5690
|
-
const schema = {
|
|
5691
|
-
type: AsnTypeTypes.Sequence,
|
|
5692
|
-
items: {}
|
|
5693
|
-
};
|
|
5694
|
+
const schema = { type: AsnTypeTypes.Sequence, items: {} };
|
|
5694
5695
|
const parentSchema = this.findParentSchema(target);
|
|
5695
5696
|
if (parentSchema) {
|
|
5696
5697
|
Object.assign(schema, parentSchema);
|
|
@@ -5732,26 +5733,14 @@ var AsnSchemaStorage = class {
|
|
|
5732
5733
|
const Container = item.repeated === "set" ? Set : Sequence;
|
|
5733
5734
|
asn1Item = new Container({
|
|
5734
5735
|
name: "",
|
|
5735
|
-
value: [
|
|
5736
|
-
new Repeated({
|
|
5737
|
-
name,
|
|
5738
|
-
value: asn1Item
|
|
5739
|
-
})
|
|
5740
|
-
]
|
|
5736
|
+
value: [new Repeated({ name, value: asn1Item })]
|
|
5741
5737
|
});
|
|
5742
5738
|
}
|
|
5743
5739
|
if (item.context !== null && item.context !== void 0) {
|
|
5744
5740
|
if (item.implicit) {
|
|
5745
5741
|
if (typeof item.type === "number" || isConvertible(item.type)) {
|
|
5746
5742
|
const Container = item.repeated ? Constructed : Primitive;
|
|
5747
|
-
asn1Value.push(new Container({
|
|
5748
|
-
name,
|
|
5749
|
-
optional,
|
|
5750
|
-
idBlock: {
|
|
5751
|
-
tagClass: 3,
|
|
5752
|
-
tagNumber: item.context
|
|
5753
|
-
}
|
|
5754
|
-
}));
|
|
5743
|
+
asn1Value.push(new Container({ name, optional, idBlock: { tagClass: 3, tagNumber: item.context } }));
|
|
5755
5744
|
} else {
|
|
5756
5745
|
this.cache(item.type);
|
|
5757
5746
|
const isRepeated = !!item.repeated;
|
|
@@ -5760,20 +5749,14 @@ var AsnSchemaStorage = class {
|
|
|
5760
5749
|
asn1Value.push(new Constructed({
|
|
5761
5750
|
name: !isRepeated ? name : "",
|
|
5762
5751
|
optional,
|
|
5763
|
-
idBlock: {
|
|
5764
|
-
tagClass: 3,
|
|
5765
|
-
tagNumber: item.context
|
|
5766
|
-
},
|
|
5752
|
+
idBlock: { tagClass: 3, tagNumber: item.context },
|
|
5767
5753
|
value
|
|
5768
5754
|
}));
|
|
5769
5755
|
}
|
|
5770
5756
|
} else {
|
|
5771
5757
|
asn1Value.push(new Constructed({
|
|
5772
5758
|
optional,
|
|
5773
|
-
idBlock: {
|
|
5774
|
-
tagClass: 3,
|
|
5775
|
-
tagNumber: item.context
|
|
5776
|
-
},
|
|
5759
|
+
idBlock: { tagClass: 3, tagNumber: item.context },
|
|
5777
5760
|
value: [asn1Item]
|
|
5778
5761
|
}));
|
|
5779
5762
|
}
|
|
@@ -5829,7 +5812,6 @@ var AsnParser = class {
|
|
|
5829
5812
|
return res;
|
|
5830
5813
|
}
|
|
5831
5814
|
static fromASN(asn1Schema, target) {
|
|
5832
|
-
var _a2;
|
|
5833
5815
|
try {
|
|
5834
5816
|
if (isConvertible(target)) {
|
|
5835
5817
|
const value = new target();
|
|
@@ -5838,104 +5820,259 @@ var AsnParser = class {
|
|
|
5838
5820
|
const schema = schemaStorage.get(target);
|
|
5839
5821
|
schemaStorage.cache(target);
|
|
5840
5822
|
let targetSchema = schema.schema;
|
|
5841
|
-
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
tagClass: 3,
|
|
5845
|
-
tagNumber: asn1Schema.idBlock.tagNumber
|
|
5846
|
-
},
|
|
5847
|
-
value: schema.schema.valueBlock.value
|
|
5848
|
-
});
|
|
5849
|
-
for (const key in schema.items) {
|
|
5850
|
-
delete asn1Schema[key];
|
|
5851
|
-
}
|
|
5823
|
+
const choiceResult = this.handleChoiceTypes(asn1Schema, schema, target, targetSchema);
|
|
5824
|
+
if (choiceResult === null || choiceResult === void 0 ? void 0 : choiceResult.result) {
|
|
5825
|
+
return choiceResult.result;
|
|
5852
5826
|
}
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
throw new AsnSchemaValidationError(`Data does not match to ${target.name} ASN1 schema. ${asn1ComparedSchema.result.error}`);
|
|
5827
|
+
if (choiceResult === null || choiceResult === void 0 ? void 0 : choiceResult.targetSchema) {
|
|
5828
|
+
targetSchema = choiceResult.targetSchema;
|
|
5856
5829
|
}
|
|
5830
|
+
const sequenceResult = this.handleSequenceTypes(asn1Schema, schema, target, targetSchema);
|
|
5857
5831
|
const res = new target();
|
|
5858
5832
|
if (isTypeOfArray(target)) {
|
|
5859
|
-
|
|
5860
|
-
throw new Error(`Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.`);
|
|
5861
|
-
}
|
|
5862
|
-
const itemType = schema.itemType;
|
|
5863
|
-
if (typeof itemType === "number") {
|
|
5864
|
-
const converter = defaultConverter(itemType);
|
|
5865
|
-
if (!converter) {
|
|
5866
|
-
throw new Error(`Cannot get default converter for array item of ${target.name} ASN1 schema`);
|
|
5867
|
-
}
|
|
5868
|
-
return target.from(asn1Schema.valueBlock.value, (element) => converter.fromASN(element));
|
|
5869
|
-
} else {
|
|
5870
|
-
return target.from(asn1Schema.valueBlock.value, (element) => this.fromASN(element, itemType));
|
|
5871
|
-
}
|
|
5833
|
+
return this.handleArrayTypes(asn1Schema, schema, target);
|
|
5872
5834
|
}
|
|
5835
|
+
this.processSchemaItems(schema, sequenceResult, res);
|
|
5836
|
+
return res;
|
|
5837
|
+
} catch (error) {
|
|
5838
|
+
if (error instanceof AsnSchemaValidationError) {
|
|
5839
|
+
error.schemas.push(target.name);
|
|
5840
|
+
}
|
|
5841
|
+
throw error;
|
|
5842
|
+
}
|
|
5843
|
+
}
|
|
5844
|
+
static handleChoiceTypes(asn1Schema, schema, target, targetSchema) {
|
|
5845
|
+
if (asn1Schema.constructor === Constructed && schema.type === AsnTypeTypes.Choice && asn1Schema.idBlock.tagClass === 3) {
|
|
5873
5846
|
for (const key in schema.items) {
|
|
5874
|
-
const asn1SchemaValue = asn1ComparedSchema.result[key];
|
|
5875
|
-
if (!asn1SchemaValue) {
|
|
5876
|
-
continue;
|
|
5877
|
-
}
|
|
5878
5847
|
const schemaItem = schema.items[key];
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
const newItemAsn = fromBER(newItem.toBER(false));
|
|
5891
|
-
if (newItemAsn.offset === -1) {
|
|
5892
|
-
throw new Error(`Cannot parse the child item. ${newItemAsn.result.error}`);
|
|
5893
|
-
}
|
|
5894
|
-
if (!("value" in newItemAsn.result.valueBlock && Array.isArray(newItemAsn.result.valueBlock.value))) {
|
|
5895
|
-
throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");
|
|
5896
|
-
}
|
|
5897
|
-
const value = newItemAsn.result.valueBlock.value;
|
|
5898
|
-
res[key] = Array.from(value, (element) => converter.fromASN(element));
|
|
5899
|
-
} else {
|
|
5900
|
-
res[key] = Array.from(asn1SchemaValue, (element) => converter.fromASN(element));
|
|
5901
|
-
}
|
|
5902
|
-
} else {
|
|
5903
|
-
let value = asn1SchemaValue;
|
|
5904
|
-
if (schemaItem.implicit) {
|
|
5905
|
-
let newItem;
|
|
5906
|
-
if (isConvertible(schemaItemType)) {
|
|
5907
|
-
newItem = new schemaItemType().toSchema("");
|
|
5908
|
-
} else {
|
|
5909
|
-
const Asn1TypeName = AsnPropTypes[schemaItemType];
|
|
5910
|
-
const Asn1Type = index_es_exports[Asn1TypeName];
|
|
5911
|
-
if (!Asn1Type) {
|
|
5912
|
-
throw new Error(`Cannot get '${Asn1TypeName}' class from asn1js module`);
|
|
5913
|
-
}
|
|
5914
|
-
newItem = new Asn1Type();
|
|
5848
|
+
if (schemaItem.context === asn1Schema.idBlock.tagNumber && schemaItem.implicit) {
|
|
5849
|
+
if (typeof schemaItem.type === "function" && schemaStorage.has(schemaItem.type)) {
|
|
5850
|
+
const fieldSchema = schemaStorage.get(schemaItem.type);
|
|
5851
|
+
if (fieldSchema && fieldSchema.type === AsnTypeTypes.Sequence) {
|
|
5852
|
+
const newSeq = new Sequence();
|
|
5853
|
+
if ("value" in asn1Schema.valueBlock && Array.isArray(asn1Schema.valueBlock.value) && "value" in newSeq.valueBlock) {
|
|
5854
|
+
newSeq.valueBlock.value = asn1Schema.valueBlock.value;
|
|
5855
|
+
const fieldValue = this.fromASN(newSeq, schemaItem.type);
|
|
5856
|
+
const res = new target();
|
|
5857
|
+
res[key] = fieldValue;
|
|
5858
|
+
return { result: res };
|
|
5915
5859
|
}
|
|
5916
|
-
newItem.valueBlock = value.valueBlock;
|
|
5917
|
-
value = fromBER(newItem.toBER(false)).result;
|
|
5918
5860
|
}
|
|
5919
|
-
res[key] = converter.fromASN(value);
|
|
5920
5861
|
}
|
|
5921
|
-
}
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
|
|
5862
|
+
}
|
|
5863
|
+
}
|
|
5864
|
+
} else if (asn1Schema.constructor === Constructed && schema.type !== AsnTypeTypes.Choice) {
|
|
5865
|
+
const newTargetSchema = new Constructed({
|
|
5866
|
+
idBlock: {
|
|
5867
|
+
tagClass: 3,
|
|
5868
|
+
tagNumber: asn1Schema.idBlock.tagNumber
|
|
5869
|
+
},
|
|
5870
|
+
value: schema.schema.valueBlock.value
|
|
5871
|
+
});
|
|
5872
|
+
for (const key in schema.items) {
|
|
5873
|
+
delete asn1Schema[key];
|
|
5874
|
+
}
|
|
5875
|
+
return { targetSchema: newTargetSchema };
|
|
5876
|
+
}
|
|
5877
|
+
return null;
|
|
5878
|
+
}
|
|
5879
|
+
static handleSequenceTypes(asn1Schema, schema, target, targetSchema) {
|
|
5880
|
+
if (schema.type === AsnTypeTypes.Sequence) {
|
|
5881
|
+
const asn1ComparedSchema = compareSchema({}, asn1Schema, targetSchema);
|
|
5882
|
+
if (!asn1ComparedSchema.verified) {
|
|
5883
|
+
throw new AsnSchemaValidationError(`Data does not match to ${target.name} ASN1 schema.${asn1ComparedSchema.result.error ? ` ${asn1ComparedSchema.result.error}` : ""}`);
|
|
5884
|
+
}
|
|
5885
|
+
return asn1ComparedSchema;
|
|
5886
|
+
} else {
|
|
5887
|
+
const asn1ComparedSchema = compareSchema({}, asn1Schema, targetSchema);
|
|
5888
|
+
if (!asn1ComparedSchema.verified) {
|
|
5889
|
+
throw new AsnSchemaValidationError(`Data does not match to ${target.name} ASN1 schema.${asn1ComparedSchema.result.error ? ` ${asn1ComparedSchema.result.error}` : ""}`);
|
|
5890
|
+
}
|
|
5891
|
+
return asn1ComparedSchema;
|
|
5892
|
+
}
|
|
5893
|
+
}
|
|
5894
|
+
static processRepeatedField(asn1Elements, asn1Index, schemaItem) {
|
|
5895
|
+
let elementsToProcess = asn1Elements.slice(asn1Index);
|
|
5896
|
+
if (elementsToProcess.length === 1 && elementsToProcess[0].constructor.name === "Sequence") {
|
|
5897
|
+
const seq = elementsToProcess[0];
|
|
5898
|
+
if (seq.valueBlock && seq.valueBlock.value && Array.isArray(seq.valueBlock.value)) {
|
|
5899
|
+
elementsToProcess = seq.valueBlock.value;
|
|
5900
|
+
}
|
|
5901
|
+
}
|
|
5902
|
+
if (typeof schemaItem.type === "number") {
|
|
5903
|
+
const converter = defaultConverter(schemaItem.type);
|
|
5904
|
+
if (!converter)
|
|
5905
|
+
throw new Error(`No converter for ASN.1 type ${schemaItem.type}`);
|
|
5906
|
+
return elementsToProcess.filter((el) => el && el.valueBlock).map((el) => {
|
|
5907
|
+
try {
|
|
5908
|
+
return converter.fromASN(el);
|
|
5909
|
+
} catch {
|
|
5910
|
+
return void 0;
|
|
5911
|
+
}
|
|
5912
|
+
}).filter((v) => v !== void 0);
|
|
5913
|
+
} else {
|
|
5914
|
+
return elementsToProcess.filter((el) => el && el.valueBlock).map((el) => {
|
|
5915
|
+
try {
|
|
5916
|
+
return this.fromASN(el, schemaItem.type);
|
|
5917
|
+
} catch {
|
|
5918
|
+
return void 0;
|
|
5919
|
+
}
|
|
5920
|
+
}).filter((v) => v !== void 0);
|
|
5921
|
+
}
|
|
5922
|
+
}
|
|
5923
|
+
static processPrimitiveField(asn1Element, schemaItem) {
|
|
5924
|
+
const converter = defaultConverter(schemaItem.type);
|
|
5925
|
+
if (!converter)
|
|
5926
|
+
throw new Error(`No converter for ASN.1 type ${schemaItem.type}`);
|
|
5927
|
+
return converter.fromASN(asn1Element);
|
|
5928
|
+
}
|
|
5929
|
+
static isOptionalChoiceField(schemaItem) {
|
|
5930
|
+
return schemaItem.optional && typeof schemaItem.type === "function" && schemaStorage.has(schemaItem.type) && schemaStorage.get(schemaItem.type).type === AsnTypeTypes.Choice;
|
|
5931
|
+
}
|
|
5932
|
+
static processOptionalChoiceField(asn1Element, schemaItem) {
|
|
5933
|
+
try {
|
|
5934
|
+
const value = this.fromASN(asn1Element, schemaItem.type);
|
|
5935
|
+
return { processed: true, value };
|
|
5936
|
+
} catch (err) {
|
|
5937
|
+
if (err instanceof AsnSchemaValidationError && /Wrong values for Choice type/.test(err.message)) {
|
|
5938
|
+
return { processed: false };
|
|
5939
|
+
}
|
|
5940
|
+
throw err;
|
|
5941
|
+
}
|
|
5942
|
+
}
|
|
5943
|
+
static handleArrayTypes(asn1Schema, schema, target) {
|
|
5944
|
+
if (!("value" in asn1Schema.valueBlock && Array.isArray(asn1Schema.valueBlock.value))) {
|
|
5945
|
+
throw new Error(`Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.`);
|
|
5946
|
+
}
|
|
5947
|
+
const itemType = schema.itemType;
|
|
5948
|
+
if (typeof itemType === "number") {
|
|
5949
|
+
const converter = defaultConverter(itemType);
|
|
5950
|
+
if (!converter) {
|
|
5951
|
+
throw new Error(`Cannot get default converter for array item of ${target.name} ASN1 schema`);
|
|
5952
|
+
}
|
|
5953
|
+
return target.from(asn1Schema.valueBlock.value, (element) => converter.fromASN(element));
|
|
5954
|
+
} else {
|
|
5955
|
+
return target.from(asn1Schema.valueBlock.value, (element) => this.fromASN(element, itemType));
|
|
5956
|
+
}
|
|
5957
|
+
}
|
|
5958
|
+
static processSchemaItems(schema, asn1ComparedSchema, res) {
|
|
5959
|
+
for (const key in schema.items) {
|
|
5960
|
+
const asn1SchemaValue = asn1ComparedSchema.result[key];
|
|
5961
|
+
if (!asn1SchemaValue) {
|
|
5962
|
+
continue;
|
|
5963
|
+
}
|
|
5964
|
+
const schemaItem = schema.items[key];
|
|
5965
|
+
const schemaItemType = schemaItem.type;
|
|
5966
|
+
let parsedValue;
|
|
5967
|
+
if (typeof schemaItemType === "number" || isConvertible(schemaItemType)) {
|
|
5968
|
+
parsedValue = this.processPrimitiveSchemaItem(asn1SchemaValue, schemaItem, schemaItemType);
|
|
5969
|
+
} else {
|
|
5970
|
+
parsedValue = this.processComplexSchemaItem(asn1SchemaValue, schemaItem, schemaItemType);
|
|
5971
|
+
}
|
|
5972
|
+
if (parsedValue && typeof parsedValue === "object" && "value" in parsedValue && "raw" in parsedValue) {
|
|
5973
|
+
res[key] = parsedValue.value;
|
|
5974
|
+
res[`${key}Raw`] = parsedValue.raw;
|
|
5975
|
+
} else {
|
|
5976
|
+
res[key] = parsedValue;
|
|
5977
|
+
}
|
|
5978
|
+
}
|
|
5979
|
+
}
|
|
5980
|
+
static processPrimitiveSchemaItem(asn1SchemaValue, schemaItem, schemaItemType) {
|
|
5981
|
+
var _a2;
|
|
5982
|
+
const converter = (_a2 = schemaItem.converter) !== null && _a2 !== void 0 ? _a2 : isConvertible(schemaItemType) ? new schemaItemType() : null;
|
|
5983
|
+
if (!converter) {
|
|
5984
|
+
throw new Error("Converter is empty");
|
|
5985
|
+
}
|
|
5986
|
+
if (schemaItem.repeated) {
|
|
5987
|
+
return this.processRepeatedPrimitiveItem(asn1SchemaValue, schemaItem, converter);
|
|
5988
|
+
} else {
|
|
5989
|
+
return this.processSinglePrimitiveItem(asn1SchemaValue, schemaItem, schemaItemType, converter);
|
|
5990
|
+
}
|
|
5991
|
+
}
|
|
5992
|
+
static processRepeatedPrimitiveItem(asn1SchemaValue, schemaItem, converter) {
|
|
5993
|
+
if (schemaItem.implicit) {
|
|
5994
|
+
const Container = schemaItem.repeated === "sequence" ? Sequence : Set;
|
|
5995
|
+
const newItem = new Container();
|
|
5996
|
+
newItem.valueBlock = asn1SchemaValue.valueBlock;
|
|
5997
|
+
const newItemAsn = fromBER(newItem.toBER(false));
|
|
5998
|
+
if (newItemAsn.offset === -1) {
|
|
5999
|
+
throw new Error(`Cannot parse the child item. ${newItemAsn.result.error}`);
|
|
6000
|
+
}
|
|
6001
|
+
if (!("value" in newItemAsn.result.valueBlock && Array.isArray(newItemAsn.result.valueBlock.value))) {
|
|
6002
|
+
throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");
|
|
6003
|
+
}
|
|
6004
|
+
const value = newItemAsn.result.valueBlock.value;
|
|
6005
|
+
return Array.from(value, (element) => converter.fromASN(element));
|
|
6006
|
+
} else {
|
|
6007
|
+
return Array.from(asn1SchemaValue, (element) => converter.fromASN(element));
|
|
6008
|
+
}
|
|
6009
|
+
}
|
|
6010
|
+
static processSinglePrimitiveItem(asn1SchemaValue, schemaItem, schemaItemType, converter) {
|
|
6011
|
+
let value = asn1SchemaValue;
|
|
6012
|
+
if (schemaItem.implicit) {
|
|
6013
|
+
let newItem;
|
|
6014
|
+
if (isConvertible(schemaItemType)) {
|
|
6015
|
+
newItem = new schemaItemType().toSchema("");
|
|
6016
|
+
} else {
|
|
6017
|
+
const Asn1TypeName = AsnPropTypes[schemaItemType];
|
|
6018
|
+
const Asn1Type = index_es_exports[Asn1TypeName];
|
|
6019
|
+
if (!Asn1Type) {
|
|
6020
|
+
throw new Error(`Cannot get '${Asn1TypeName}' class from asn1js module`);
|
|
6021
|
+
}
|
|
6022
|
+
newItem = new Asn1Type();
|
|
6023
|
+
}
|
|
6024
|
+
newItem.valueBlock = value.valueBlock;
|
|
6025
|
+
value = fromBER(newItem.toBER(false)).result;
|
|
6026
|
+
}
|
|
6027
|
+
return converter.fromASN(value);
|
|
6028
|
+
}
|
|
6029
|
+
static processComplexSchemaItem(asn1SchemaValue, schemaItem, schemaItemType) {
|
|
6030
|
+
if (schemaItem.repeated) {
|
|
6031
|
+
if (!Array.isArray(asn1SchemaValue)) {
|
|
6032
|
+
throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");
|
|
6033
|
+
}
|
|
6034
|
+
return Array.from(asn1SchemaValue, (element) => this.fromASN(element, schemaItemType));
|
|
6035
|
+
} else {
|
|
6036
|
+
const valueToProcess = this.handleImplicitTagging(asn1SchemaValue, schemaItem, schemaItemType);
|
|
6037
|
+
if (this.isOptionalChoiceField(schemaItem)) {
|
|
6038
|
+
try {
|
|
6039
|
+
return this.fromASN(valueToProcess, schemaItemType);
|
|
6040
|
+
} catch (err) {
|
|
6041
|
+
if (err instanceof AsnSchemaValidationError && /Wrong values for Choice type/.test(err.message)) {
|
|
6042
|
+
return void 0;
|
|
5929
6043
|
}
|
|
6044
|
+
throw err;
|
|
6045
|
+
}
|
|
6046
|
+
} else {
|
|
6047
|
+
const parsedValue = this.fromASN(valueToProcess, schemaItemType);
|
|
6048
|
+
if (schemaItem.raw) {
|
|
6049
|
+
return {
|
|
6050
|
+
value: parsedValue,
|
|
6051
|
+
raw: asn1SchemaValue.valueBeforeDecodeView
|
|
6052
|
+
};
|
|
5930
6053
|
}
|
|
6054
|
+
return parsedValue;
|
|
5931
6055
|
}
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
6056
|
+
}
|
|
6057
|
+
}
|
|
6058
|
+
static handleImplicitTagging(asn1SchemaValue, schemaItem, schemaItemType) {
|
|
6059
|
+
if (schemaItem.implicit && typeof schemaItem.context === "number") {
|
|
6060
|
+
const schema = schemaStorage.get(schemaItemType);
|
|
6061
|
+
if (schema.type === AsnTypeTypes.Sequence) {
|
|
6062
|
+
const newSeq = new Sequence();
|
|
6063
|
+
if ("value" in asn1SchemaValue.valueBlock && Array.isArray(asn1SchemaValue.valueBlock.value) && "value" in newSeq.valueBlock) {
|
|
6064
|
+
newSeq.valueBlock.value = asn1SchemaValue.valueBlock.value;
|
|
6065
|
+
return newSeq;
|
|
6066
|
+
}
|
|
6067
|
+
} else if (schema.type === AsnTypeTypes.Set) {
|
|
6068
|
+
const newSet = new Set();
|
|
6069
|
+
if ("value" in asn1SchemaValue.valueBlock && Array.isArray(asn1SchemaValue.valueBlock.value) && "value" in newSet.valueBlock) {
|
|
6070
|
+
newSet.valueBlock.value = asn1SchemaValue.valueBlock.value;
|
|
6071
|
+
return newSet;
|
|
6072
|
+
}
|
|
5936
6073
|
}
|
|
5937
|
-
throw error;
|
|
5938
6074
|
}
|
|
6075
|
+
return asn1SchemaValue;
|
|
5939
6076
|
}
|
|
5940
6077
|
};
|
|
5941
6078
|
|
|
@@ -6232,7 +6369,7 @@ pvtsutils/build/index.es.js:
|
|
|
6232
6369
|
(*!
|
|
6233
6370
|
* MIT License
|
|
6234
6371
|
*
|
|
6235
|
-
* Copyright (c) 2017-
|
|
6372
|
+
* Copyright (c) 2017-2024 Peculiar Ventures, LLC
|
|
6236
6373
|
*
|
|
6237
6374
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6238
6375
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -6294,4 +6431,4 @@ asn1js/build/index.es.js:
|
|
|
6294
6431
|
*
|
|
6295
6432
|
*)
|
|
6296
6433
|
*/
|
|
6297
|
-
//# sourceMappingURL=chunk-
|
|
6434
|
+
//# sourceMappingURL=chunk-MGQCHN54.mjs.map
|