Comparing version 5.5.0 to 6.0.0
@@ -107,4 +107,4 @@ import { ASN1Construction, ASN1TagClass } from "./values"; | ||
sizeConstrainedBMPString(min: number, max?: number): BMPString; | ||
rangeConstrainedInteger(min: number, max?: number): INTEGER; | ||
rangeConstrainedReal(min: number, max?: number): REAL; | ||
rangeConstrainedInteger(min: bigint, max?: bigint): INTEGER; | ||
rangeConstrainedReal(min: bigint, max?: bigint): REAL; | ||
abstract deconstruct(dataType: string): Uint8Array; | ||
@@ -111,0 +111,0 @@ validateTag(permittedClasses: ASN1TagClass[], permittedConstruction: ASN1Construction[], permittedNumbers: number[]): number; |
@@ -40,3 +40,2 @@ "use strict"; | ||
validateRange(name, actualValue, min, max) { | ||
const effectiveMax = (typeof max === "undefined" ? Infinity : max); | ||
if (actualValue < min) { | ||
@@ -46,5 +45,8 @@ throw new errors.ASN1OverflowError(`${name} was ${actualValue} when the ` | ||
} | ||
if (actualValue > effectiveMax) { | ||
if (max === undefined) { | ||
return; | ||
} | ||
if (actualValue > max) { | ||
throw new errors.ASN1OverflowError(`${name} was ${actualValue} when the ` | ||
+ `maximum permissible is ${effectiveMax}.`); | ||
+ `maximum permissible is ${max}.`); | ||
} | ||
@@ -51,0 +53,0 @@ } |
@@ -276,3 +276,2 @@ "use strict"; | ||
encode(value) { | ||
var _a; | ||
switch (typeof value) { | ||
@@ -334,3 +333,3 @@ case ("undefined"): { | ||
} | ||
else if ((value instanceof ObjectIdentifier_1.default) || (((_a = value.constructor) === null || _a === void 0 ? void 0 : _a.name) === "ObjectIdentifier")) { | ||
else if ((value instanceof ObjectIdentifier_1.default) || (value.constructor?.name === "ObjectIdentifier")) { | ||
this.tagNumber = values_1.ASN1UniversalType.objectIdentifier; | ||
@@ -337,0 +336,0 @@ this.objectIdentifier = value; |
@@ -282,3 +282,2 @@ "use strict"; | ||
encode(value) { | ||
var _a; | ||
switch (typeof value) { | ||
@@ -340,3 +339,3 @@ case ("undefined"): { | ||
} | ||
else if ((value instanceof ObjectIdentifier_1.default) || (((_a = value.constructor) === null || _a === void 0 ? void 0 : _a.name) === "ObjectIdentifier")) { | ||
else if ((value instanceof ObjectIdentifier_1.default) || (value.constructor?.name === "ObjectIdentifier")) { | ||
this.tagNumber = values_1.ASN1UniversalType.objectIdentifier; | ||
@@ -343,0 +342,0 @@ this.objectIdentifier = value; |
@@ -286,3 +286,2 @@ "use strict"; | ||
encode(value) { | ||
var _a; | ||
switch (typeof value) { | ||
@@ -344,3 +343,3 @@ case ("undefined"): { | ||
} | ||
else if ((value instanceof ObjectIdentifier_1.default) || (((_a = value.constructor) === null || _a === void 0 ? void 0 : _a.name) === "ObjectIdentifier")) { | ||
else if ((value instanceof ObjectIdentifier_1.default) || (value.constructor?.name === "ObjectIdentifier")) { | ||
this.tagNumber = values_1.ASN1UniversalType.objectIdentifier; | ||
@@ -347,0 +346,0 @@ this.objectIdentifier = value; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const errors = (0, tslib_1.__importStar)(require("../../../errors")); | ||
const decodeSignedBigEndianInteger_1 = (0, tslib_1.__importDefault)(require("../../../utils/decodeSignedBigEndianInteger")); | ||
const bigint_1 = require("../../../utils/bigint"); | ||
function decodeInteger(value) { | ||
@@ -11,5 +11,2 @@ if (value.length === 0) { | ||
} | ||
if (value.length > 4) { | ||
throw new errors.ASN1OverflowError("INTEGER too long to decode."); | ||
} | ||
if (value.length > 2 | ||
@@ -20,5 +17,5 @@ && ((value[0] === 0xFF && value[1] >= 0b10000000) | ||
} | ||
return (0, decodeSignedBigEndianInteger_1.default)(value.subarray(0)); | ||
return (0, bigint_1.bufferToInteger)(value); | ||
} | ||
exports.default = decodeInteger; | ||
//# sourceMappingURL=decodeInteger.js.map |
@@ -12,4 +12,9 @@ "use strict"; | ||
const integralAmount = value.weeks; | ||
const fraction = value.fractional_part.fractional_value | ||
/ Math.pow(10, value.fractional_part.number_of_digits); | ||
const fractional_value = (typeof value.fractional_part.fractional_value === "bigint") | ||
? Number(value.fractional_part.fractional_value) | ||
: value.fractional_part.fractional_value; | ||
const number_of_digits = (typeof value.fractional_part.number_of_digits === "bigint") | ||
? Number(value.fractional_part.number_of_digits) | ||
: value.fractional_part.number_of_digits; | ||
const fraction = (fractional_value / Math.pow(10, number_of_digits)); | ||
return (0, convertTextToBytes_1.default)(integralAmount.toString() | ||
@@ -20,11 +25,28 @@ + fraction.toString().slice(1) | ||
} | ||
let years = value.years; | ||
let months = value.months; | ||
let days = value.days; | ||
let hours = value.hours; | ||
let minutes = value.minutes; | ||
let seconds = value.seconds; | ||
let years = (typeof value.years === "bigint") | ||
? Number(value.years) | ||
: value.years; | ||
let months = (typeof value.months === "bigint") | ||
? Number(value.months) | ||
: value.months; | ||
let days = (typeof value.days === "bigint") | ||
? Number(value.days) | ||
: value.days; | ||
let hours = (typeof value.hours === "bigint") | ||
? Number(value.hours) | ||
: value.hours; | ||
let minutes = (typeof value.minutes === "bigint") | ||
? Number(value.minutes) | ||
: value.minutes; | ||
let seconds = (typeof value.seconds === "bigint") | ||
? Number(value.seconds) | ||
: value.seconds; | ||
if (value.fractional_part) { | ||
const fraction = value.fractional_part.fractional_value | ||
/ Math.pow(10, value.fractional_part.number_of_digits); | ||
const fractional_value = (typeof value.fractional_part.fractional_value === "bigint") | ||
? Number(value.fractional_part.fractional_value) | ||
: value.fractional_part.fractional_value; | ||
const number_of_digits = (typeof value.fractional_part.number_of_digits === "bigint") | ||
? Number(value.fractional_part.number_of_digits) | ||
: value.fractional_part.number_of_digits; | ||
const fraction = fractional_value / Math.pow(10, number_of_digits); | ||
if (seconds !== undefined) { | ||
@@ -31,0 +53,0 @@ seconds += fraction; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const errors = (0, tslib_1.__importStar)(require("../../../errors")); | ||
const values_1 = require("../../../values"); | ||
const bigint_1 = require("../../../utils/bigint"); | ||
function encodeInteger(value) { | ||
if (value < values_1.MIN_SINT_32) { | ||
throw new errors.ASN1OverflowError(`Number ${value} too small to be converted.`); | ||
} | ||
if (value > values_1.MAX_SINT_32) { | ||
throw new errors.ASN1OverflowError(`Number ${value} too big to be converted.`); | ||
} | ||
if (value <= 127 && value >= -128) { | ||
return new Uint8Array([ | ||
(value & 255), | ||
]); | ||
} | ||
else if (value <= 32767 && value >= -32768) { | ||
return new Uint8Array([ | ||
((value >> 8) & 255), | ||
(value & 255), | ||
]); | ||
} | ||
else if (value <= 8388607 && value >= -8388608) { | ||
return new Uint8Array([ | ||
((value >> 16) & 255), | ||
((value >> 8) & 255), | ||
(value & 255), | ||
]); | ||
} | ||
else { | ||
return new Uint8Array([ | ||
((value >> 24) & 255), | ||
((value >> 16) & 255), | ||
((value >> 8) & 255), | ||
(value & 255), | ||
]); | ||
} | ||
return (0, bigint_1.integerToBuffer)(value); | ||
} | ||
exports.default = encodeInteger; | ||
//# sourceMappingURL=encodeInteger.js.map |
@@ -8,3 +8,3 @@ import type ObjectIdentifier from "./types/ObjectIdentifier"; | ||
export declare type BOOLEAN = boolean; | ||
export declare type INTEGER = number; | ||
export declare type INTEGER = number | bigint; | ||
export declare type BIT_STRING = Uint8ClampedArray; | ||
@@ -18,3 +18,3 @@ export declare type OCTET_STRING = Uint8Array; | ||
export declare type INSTANCE_OF = External; | ||
export declare type ENUMERATED = number; | ||
export declare type ENUMERATED = number | bigint; | ||
export declare type EMBEDDED_PDV = EmbeddedPDV; | ||
@@ -21,0 +21,0 @@ export declare type UTF8String = string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function compareSetOfElementsCanonically(a, b) { | ||
var _a, _b; | ||
const longestLength = (a.value.length > b.value.length) | ||
@@ -9,4 +8,4 @@ ? a.value.length | ||
for (let i = 0; i < longestLength; i++) { | ||
const x = (_a = a.value[i]) !== null && _a !== void 0 ? _a : 0; | ||
const y = (_b = b.value[i]) !== null && _b !== void 0 ? _b : 0; | ||
const x = a.value[i] ?? 0; | ||
const y = b.value[i] ?? 0; | ||
if (x !== y) { | ||
@@ -13,0 +12,0 @@ return (x - y); |
@@ -1,2 +0,3 @@ | ||
export default function datetimeComponentValidator(unitName: string, min: number, max: number): (dataType: string, value: number) => void; | ||
import { INTEGER } from "../macros"; | ||
export default function datetimeComponentValidator(unitName: string, min: INTEGER, max: INTEGER): (dataType: string, value: INTEGER) => void; | ||
//# sourceMappingURL=datetimeComponentValidator.d.ts.map |
@@ -57,5 +57,3 @@ { | ||
"breaking-update": "npx ncu -u && npm install", | ||
"build": "npx tsc && npx webpack", | ||
"build-node": "npx tsc", | ||
"build-web": "npx webpack", | ||
"build": "npx tsc", | ||
"clean": "rm -rf dist; mkdir -p dist", | ||
@@ -67,3 +65,3 @@ "line-count": "npx sloc source", | ||
"types": "./dist/node/index.d.ts", | ||
"version": "5.5.0" | ||
"version": "6.0.0" | ||
} |
@@ -80,2 +80,7 @@ # ASN.1 TypeScript Library | ||
In this library, you can use the Basic Encoding Rules, Canonical Encoding Rules, | ||
and Distinguished Encoding Rules via the `BERElement`, `CERElement`, and | ||
`DERElement` classes respectively. You should use `DERElement` for anything that | ||
will be cryptographically signed or hashed. | ||
## Future Development | ||
@@ -82,0 +87,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
692221
619
7680
115