@peculiar/asn1-schema
Advanced tools
Comparing version 2.3.13 to 2.3.15
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultConverter = exports.AsnNullConverter = exports.AsnGeneralizedTimeConverter = exports.AsnUTCTimeConverter = exports.AsnCharacterStringConverter = exports.AsnGeneralStringConverter = exports.AsnVisibleStringConverter = exports.AsnGraphicStringConverter = exports.AsnIA5StringConverter = exports.AsnVideotexStringConverter = exports.AsnTeletexStringConverter = exports.AsnPrintableStringConverter = exports.AsnNumericStringConverter = exports.AsnUniversalStringConverter = exports.AsnBmpStringConverter = exports.AsnUtf8StringConverter = exports.AsnConstructedOctetStringConverter = exports.AsnOctetStringConverter = exports.AsnBooleanConverter = exports.AsnObjectIdentifierConverter = exports.AsnBitStringConverter = exports.AsnIntegerBigIntConverter = exports.AsnIntegerArrayBufferConverter = exports.AsnEnumeratedConverter = exports.AsnIntegerConverter = exports.AsnAnyConverter = void 0; | ||
exports.AsnNullConverter = exports.AsnGeneralizedTimeConverter = exports.AsnUTCTimeConverter = exports.AsnCharacterStringConverter = exports.AsnGeneralStringConverter = exports.AsnVisibleStringConverter = exports.AsnGraphicStringConverter = exports.AsnIA5StringConverter = exports.AsnVideotexStringConverter = exports.AsnTeletexStringConverter = exports.AsnPrintableStringConverter = exports.AsnNumericStringConverter = exports.AsnUniversalStringConverter = exports.AsnBmpStringConverter = exports.AsnUtf8StringConverter = exports.AsnConstructedOctetStringConverter = exports.AsnOctetStringConverter = exports.AsnBooleanConverter = exports.AsnObjectIdentifierConverter = exports.AsnBitStringConverter = exports.AsnIntegerBigIntConverter = exports.AsnIntegerArrayBufferConverter = exports.AsnEnumeratedConverter = exports.AsnIntegerConverter = exports.AsnAnyConverter = void 0; | ||
exports.defaultConverter = defaultConverter; | ||
const asn1js = require("asn1js"); | ||
@@ -140,2 +141,1 @@ const enums_1 = require("./enums"); | ||
} | ||
exports.defaultConverter = defaultConverter; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isArrayEqual = exports.isTypeOfArray = exports.isConvertible = void 0; | ||
exports.isConvertible = isConvertible; | ||
exports.isTypeOfArray = isTypeOfArray; | ||
exports.isArrayEqual = isArrayEqual; | ||
function isConvertible(target) { | ||
@@ -17,3 +19,2 @@ if (typeof target === "function" && target.prototype) { | ||
} | ||
exports.isConvertible = isConvertible; | ||
function isTypeOfArray(target) { | ||
@@ -30,3 +31,2 @@ var _a; | ||
} | ||
exports.isTypeOfArray = isTypeOfArray; | ||
function isArrayEqual(bytes1, bytes2) { | ||
@@ -48,2 +48,1 @@ if (!(bytes1 && bytes2)) { | ||
} | ||
exports.isArrayEqual = isArrayEqual; |
@@ -78,5 +78,3 @@ "use strict"; | ||
if (schemaItem.implicit) { | ||
const Container = schemaItem.repeated === "sequence" | ||
? asn1js.Sequence | ||
: asn1js.Set; | ||
const Container = schemaItem.repeated === "sequence" ? asn1js.Sequence : asn1js.Set; | ||
const newItem = new Container(); | ||
@@ -88,3 +86,4 @@ newItem.valueBlock = asn1SchemaValue.valueBlock; | ||
} | ||
if (!("value" in newItemAsn.result.valueBlock && Array.isArray(newItemAsn.result.valueBlock.value))) { | ||
if (!("value" in newItemAsn.result.valueBlock && | ||
Array.isArray(newItemAsn.result.valueBlock.value))) { | ||
throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed."); | ||
@@ -91,0 +90,0 @@ } |
@@ -49,3 +49,3 @@ "use strict"; | ||
let asn1Item; | ||
if (typeof (item.type) === "number") { | ||
if (typeof item.type === "number") { | ||
const Asn1TypeName = enums_1.AsnPropTypes[item.type]; | ||
@@ -78,5 +78,3 @@ const Asn1Type = asn1js[Asn1TypeName]; | ||
asn1Item.name = ""; | ||
const Container = item.repeated === "set" | ||
? asn1js.Set | ||
: asn1js.Sequence; | ||
const Container = item.repeated === "set" ? asn1js.Set : asn1js.Sequence; | ||
asn1Item = new Container({ | ||
@@ -95,5 +93,3 @@ name: "", | ||
if (typeof item.type === "number" || (0, helper_1.isConvertible)(item.type)) { | ||
const Container = item.repeated | ||
? asn1js.Constructed | ||
: asn1js.Primitive; | ||
const Container = item.repeated ? asn1js.Constructed : asn1js.Primitive; | ||
asn1Value.push(new Container({ | ||
@@ -111,6 +107,7 @@ name, | ||
const isRepeated = !!item.repeated; | ||
let value = !isRepeated | ||
? this.get(item.type, true).schema | ||
: asn1Item; | ||
value = "valueBlock" in value ? value.valueBlock.value : value.value; | ||
let value = !isRepeated ? this.get(item.type, true).schema : asn1Item; | ||
value = | ||
"valueBlock" in value | ||
? value.valueBlock.value | ||
: value.value; | ||
asn1Value.push(new asn1js.Constructed({ | ||
@@ -117,0 +114,0 @@ name: !isRepeated ? name : "", |
@@ -46,6 +46,7 @@ "use strict"; | ||
const objProp = obj[key]; | ||
if (objProp === undefined | ||
|| schemaItem.defaultValue === objProp | ||
|| (typeof schemaItem.defaultValue === "object" && typeof objProp === "object" | ||
&& (0, helper_1.isArrayEqual)(this.serialize(schemaItem.defaultValue), this.serialize(objProp)))) { | ||
if (objProp === undefined || | ||
schemaItem.defaultValue === objProp || | ||
(typeof schemaItem.defaultValue === "object" && | ||
typeof objProp === "object" && | ||
(0, helper_1.isArrayEqual)(this.serialize(schemaItem.defaultValue), this.serialize(objProp)))) { | ||
continue; | ||
@@ -56,6 +57,9 @@ } | ||
if (schemaItem.implicit) { | ||
if (!schemaItem.repeated | ||
&& (typeof schemaItem.type === "number" || (0, helper_1.isConvertible)(schemaItem.type))) { | ||
if (!schemaItem.repeated && | ||
(typeof schemaItem.type === "number" || (0, helper_1.isConvertible)(schemaItem.type))) { | ||
const value = {}; | ||
value.valueHex = asn1Item instanceof asn1js.Null ? asn1Item.valueBeforeDecodeView : asn1Item.valueBlock.toBER(); | ||
value.valueHex = | ||
asn1Item instanceof asn1js.Null | ||
? asn1Item.valueBeforeDecodeView | ||
: asn1Item.valueBlock.toBER(); | ||
asn1Value.push(new asn1js.Primitive({ | ||
@@ -119,3 +123,3 @@ optional: schemaItem.optional, | ||
let asn1Item; | ||
if (typeof (schemaItem.type) === "number") { | ||
if (typeof schemaItem.type === "number") { | ||
const converter = schemaItem.converter; | ||
@@ -130,5 +134,3 @@ if (!converter) { | ||
const items = Array.from(objProp, (element) => converter.toASN(element)); | ||
const Container = schemaItem.repeated === "sequence" | ||
? asn1js.Sequence | ||
: asn1js.Set; | ||
const Container = schemaItem.repeated === "sequence" ? asn1js.Sequence : asn1js.Set; | ||
asn1Item = new Container({ | ||
@@ -148,5 +150,3 @@ value: items, | ||
const items = Array.from(objProp, (element) => this.toASN(element)); | ||
const Container = schemaItem.repeated === "sequence" | ||
? asn1js.Sequence | ||
: asn1js.Set; | ||
const Container = schemaItem.repeated === "sequence" ? asn1js.Sequence : asn1js.Set; | ||
asn1Item = new Container({ | ||
@@ -153,0 +153,0 @@ value: items, |
@@ -54,3 +54,7 @@ "use strict"; | ||
const octets = new Uint8Array(octetSize); | ||
bits = bits.padStart(octetSize << 3, "0").split("").reverse().join(""); | ||
bits = bits | ||
.padStart(octetSize << 3, "0") | ||
.split("") | ||
.reverse() | ||
.join(""); | ||
let index = 0; | ||
@@ -57,0 +61,0 @@ while (index < octetSize) { |
@@ -75,5 +75,3 @@ import * as asn1js from "asn1js"; | ||
if (schemaItem.implicit) { | ||
const Container = schemaItem.repeated === "sequence" | ||
? asn1js.Sequence | ||
: asn1js.Set; | ||
const Container = schemaItem.repeated === "sequence" ? asn1js.Sequence : asn1js.Set; | ||
const newItem = new Container(); | ||
@@ -85,3 +83,4 @@ newItem.valueBlock = asn1SchemaValue.valueBlock; | ||
} | ||
if (!("value" in newItemAsn.result.valueBlock && Array.isArray(newItemAsn.result.valueBlock.value))) { | ||
if (!("value" in newItemAsn.result.valueBlock && | ||
Array.isArray(newItemAsn.result.valueBlock.value))) { | ||
throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed."); | ||
@@ -88,0 +87,0 @@ } |
@@ -46,3 +46,3 @@ import * as asn1js from "asn1js"; | ||
let asn1Item; | ||
if (typeof (item.type) === "number") { | ||
if (typeof item.type === "number") { | ||
const Asn1TypeName = AsnPropTypes[item.type]; | ||
@@ -75,5 +75,3 @@ const Asn1Type = asn1js[Asn1TypeName]; | ||
asn1Item.name = ""; | ||
const Container = item.repeated === "set" | ||
? asn1js.Set | ||
: asn1js.Sequence; | ||
const Container = item.repeated === "set" ? asn1js.Set : asn1js.Sequence; | ||
asn1Item = new Container({ | ||
@@ -92,5 +90,3 @@ name: "", | ||
if (typeof item.type === "number" || isConvertible(item.type)) { | ||
const Container = item.repeated | ||
? asn1js.Constructed | ||
: asn1js.Primitive; | ||
const Container = item.repeated ? asn1js.Constructed : asn1js.Primitive; | ||
asn1Value.push(new Container({ | ||
@@ -108,6 +104,7 @@ name, | ||
const isRepeated = !!item.repeated; | ||
let value = !isRepeated | ||
? this.get(item.type, true).schema | ||
: asn1Item; | ||
value = "valueBlock" in value ? value.valueBlock.value : value.value; | ||
let value = !isRepeated ? this.get(item.type, true).schema : asn1Item; | ||
value = | ||
"valueBlock" in value | ||
? value.valueBlock.value | ||
: value.value; | ||
asn1Value.push(new asn1js.Constructed({ | ||
@@ -114,0 +111,0 @@ name: !isRepeated ? name : "", |
@@ -43,6 +43,7 @@ import * as asn1js from "asn1js"; | ||
const objProp = obj[key]; | ||
if (objProp === undefined | ||
|| schemaItem.defaultValue === objProp | ||
|| (typeof schemaItem.defaultValue === "object" && typeof objProp === "object" | ||
&& isArrayEqual(this.serialize(schemaItem.defaultValue), this.serialize(objProp)))) { | ||
if (objProp === undefined || | ||
schemaItem.defaultValue === objProp || | ||
(typeof schemaItem.defaultValue === "object" && | ||
typeof objProp === "object" && | ||
isArrayEqual(this.serialize(schemaItem.defaultValue), this.serialize(objProp)))) { | ||
continue; | ||
@@ -53,6 +54,9 @@ } | ||
if (schemaItem.implicit) { | ||
if (!schemaItem.repeated | ||
&& (typeof schemaItem.type === "number" || isConvertible(schemaItem.type))) { | ||
if (!schemaItem.repeated && | ||
(typeof schemaItem.type === "number" || isConvertible(schemaItem.type))) { | ||
const value = {}; | ||
value.valueHex = asn1Item instanceof asn1js.Null ? asn1Item.valueBeforeDecodeView : asn1Item.valueBlock.toBER(); | ||
value.valueHex = | ||
asn1Item instanceof asn1js.Null | ||
? asn1Item.valueBeforeDecodeView | ||
: asn1Item.valueBlock.toBER(); | ||
asn1Value.push(new asn1js.Primitive({ | ||
@@ -116,3 +120,3 @@ optional: schemaItem.optional, | ||
let asn1Item; | ||
if (typeof (schemaItem.type) === "number") { | ||
if (typeof schemaItem.type === "number") { | ||
const converter = schemaItem.converter; | ||
@@ -127,5 +131,3 @@ if (!converter) { | ||
const items = Array.from(objProp, (element) => converter.toASN(element)); | ||
const Container = schemaItem.repeated === "sequence" | ||
? asn1js.Sequence | ||
: asn1js.Set; | ||
const Container = schemaItem.repeated === "sequence" ? asn1js.Sequence : asn1js.Set; | ||
asn1Item = new Container({ | ||
@@ -145,5 +147,3 @@ value: items, | ||
const items = Array.from(objProp, (element) => this.toASN(element)); | ||
const Container = schemaItem.repeated === "sequence" | ||
? asn1js.Sequence | ||
: asn1js.Set; | ||
const Container = schemaItem.repeated === "sequence" ? asn1js.Sequence : asn1js.Set; | ||
asn1Item = new Container({ | ||
@@ -150,0 +150,0 @@ value: items, |
@@ -51,3 +51,7 @@ import * as asn1js from "asn1js"; | ||
const octets = new Uint8Array(octetSize); | ||
bits = bits.padStart(octetSize << 3, "0").split("").reverse().join(""); | ||
bits = bits | ||
.padStart(octetSize << 3, "0") | ||
.split("") | ||
.reverse() | ||
.join(""); | ||
let index = 0; | ||
@@ -54,0 +58,0 @@ while (index < octetSize) { |
import { IAsnConvertible, IEmptyConstructor } from "./types"; | ||
export declare function isConvertible(target: IEmptyConstructor): target is (new () => IAsnConvertible); | ||
export declare function isConvertible(target: IEmptyConstructor): target is new () => IAsnConvertible; | ||
export declare function isConvertible(target: unknown): target is IAsnConvertible; | ||
export declare function isTypeOfArray(target: unknown): target is typeof Array; | ||
export declare function isArrayEqual(bytes1: ArrayBuffer, bytes2: ArrayBuffer): boolean; |
{ | ||
"name": "@peculiar/asn1-schema", | ||
"version": "2.3.13", | ||
"version": "2.3.15", | ||
"description": "Decorators for ASN.1 schemas building", | ||
@@ -42,4 +42,4 @@ "files": [ | ||
"asn1js": "^3.0.5", | ||
"pvtsutils": "^1.3.5", | ||
"tslib": "^2.6.2" | ||
"pvtsutils": "^1.3.6", | ||
"tslib": "^2.8.1" | ||
}, | ||
@@ -56,3 +56,3 @@ "contributors": [ | ||
], | ||
"gitHead": "c0a11836bb6ffcc71607099c8de936b6ab86d164" | ||
"gitHead": "b6c7130efa9bc3ee5e2ea1da5d01aede5182921f" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
93075
2143
Updatedpvtsutils@^1.3.6
Updatedtslib@^2.8.1