pkijs
Version:
Public Key Infrastructure (PKI) is the basis of how identity and key management is performed on the web today. PKIjs is a pure JavaScript library implementing the formats that are used in PKI applications. It is built on WebCrypto and aspires to make it p
1,390 lines (1,370 loc) • 801 kB
JavaScript
/*!
* Copyright (c) 2014, GlobalSign
* Copyright (c) 2015-2019, Peculiar Ventures
* All rights reserved.
*
* Author 2014-2019, Yury Strozhevsky
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* * Neither the name of the {organization} nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
'use strict';
var asn1js = require('asn1js');
var pvtsutils = require('pvtsutils');
var pvutils = require('pvutils');
var bs = require('bytestreamjs');
var sha1 = require('@noble/hashes/sha1');
var sha2 = require('@noble/hashes/sha2');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var asn1js__namespace = /*#__PURE__*/_interopNamespaceDefault(asn1js);
var pvtsutils__namespace = /*#__PURE__*/_interopNamespaceDefault(pvtsutils);
var pvutils__namespace = /*#__PURE__*/_interopNamespaceDefault(pvutils);
var bs__namespace = /*#__PURE__*/_interopNamespaceDefault(bs);
const EMPTY_BUFFER = new ArrayBuffer(0);
const EMPTY_STRING = "";
class ArgumentError extends TypeError {
constructor() {
super(...arguments);
this.name = ArgumentError.NAME;
}
static isType(value, type) {
if (typeof type === "string") {
if (type === "Array" && Array.isArray(value)) {
return true;
}
else if (type === "ArrayBuffer" && value instanceof ArrayBuffer) {
return true;
}
else if (type === "ArrayBufferView" && ArrayBuffer.isView(value)) {
return true;
}
else if (typeof value === type) {
return true;
}
}
else if (value instanceof type) {
return true;
}
return false;
}
static assert(value, name, ...types) {
for (const type of types) {
if (this.isType(value, type)) {
return;
}
}
const typeNames = types.map(o => o instanceof Function && "name" in o ? o.name : `${o}`);
throw new ArgumentError(`Parameter '${name}' is not of type ${typeNames.length > 1 ? `(${typeNames.join(" or ")})` : typeNames[0]}`);
}
}
ArgumentError.NAME = "ArgumentError";
class ParameterError extends TypeError {
static assert(...args) {
let target = null;
let params;
let fields;
if (typeof args[0] === "string") {
target = args[0];
params = args[1];
fields = args.slice(2);
}
else {
params = args[0];
fields = args.slice(1);
}
ArgumentError.assert(params, "parameters", "object");
for (const field of fields) {
const value = params[field];
if (value === undefined || value === null) {
throw new ParameterError(field, target);
}
}
}
static assertEmpty(value, name, target) {
if (value === undefined || value === null) {
throw new ParameterError(name, target);
}
}
constructor(field, target = null, message) {
super();
this.name = ParameterError.NAME;
this.field = field;
if (target) {
this.target = target;
}
if (message) {
this.message = message;
}
else {
this.message = `Absent mandatory parameter '${field}' ${target ? ` in '${target}'` : EMPTY_STRING}`;
}
}
}
ParameterError.NAME = "ParameterError";
class AsnError extends Error {
static assertSchema(asn1, target) {
if (!asn1.verified) {
throw new Error(`Object's schema was not verified against input data for ${target}`);
}
}
static assert(asn, target) {
if (asn.offset === -1) {
throw new AsnError(`Error during parsing of ASN.1 data. Data is not correct for '${target}'.`);
}
}
constructor(message) {
super(message);
this.name = "AsnError";
}
}
class PkiObject {
static blockName() {
return this.CLASS_NAME;
}
static fromBER(raw) {
const asn1 = asn1js__namespace.fromBER(raw);
AsnError.assert(asn1, this.name);
try {
return new this({ schema: asn1.result });
}
catch (e) {
throw new AsnError(`Cannot create '${this.CLASS_NAME}' from ASN.1 object`);
}
}
static defaultValues(memberName) {
throw new Error(`Invalid member name for ${this.CLASS_NAME} class: ${memberName}`);
}
static schema(parameters = {}) {
throw new Error(`Method '${this.CLASS_NAME}.schema' should be overridden`);
}
get className() {
return this.constructor.CLASS_NAME;
}
toString(encoding = "hex") {
let schema;
try {
schema = this.toSchema();
}
catch {
schema = this.toSchema(true);
}
return pvtsutils__namespace.Convert.ToString(schema.toBER(), encoding);
}
}
PkiObject.CLASS_NAME = "PkiObject";
function stringPrep(inputString) {
let isSpace = false;
let cutResult = EMPTY_STRING;
const result = inputString.trim();
for (let i = 0; i < result.length; i++) {
if (result.charCodeAt(i) === 32) {
if (isSpace === false)
isSpace = true;
}
else {
if (isSpace) {
cutResult += " ";
isSpace = false;
}
cutResult += result[i];
}
}
return cutResult.toLowerCase();
}
const TYPE$5 = "type";
const VALUE$6 = "value";
class AttributeTypeAndValue extends PkiObject {
constructor(parameters = {}) {
super();
this.type = pvutils__namespace.getParametersValue(parameters, TYPE$5, AttributeTypeAndValue.defaultValues(TYPE$5));
this.value = pvutils__namespace.getParametersValue(parameters, VALUE$6, AttributeTypeAndValue.defaultValues(VALUE$6));
if (parameters.schema) {
this.fromSchema(parameters.schema);
}
}
static defaultValues(memberName) {
switch (memberName) {
case TYPE$5:
return EMPTY_STRING;
case VALUE$6:
return {};
default:
return super.defaultValues(memberName);
}
}
static schema(parameters = {}) {
const names = pvutils__namespace.getParametersValue(parameters, "names", {});
return (new asn1js__namespace.Sequence({
name: (names.blockName || EMPTY_STRING),
value: [
new asn1js__namespace.ObjectIdentifier({ name: (names.type || EMPTY_STRING) }),
new asn1js__namespace.Any({ name: (names.value || EMPTY_STRING) })
]
}));
}
fromSchema(schema) {
pvutils__namespace.clearProps(schema, [
TYPE$5,
"typeValue"
]);
const asn1 = asn1js__namespace.compareSchema(schema, schema, AttributeTypeAndValue.schema({
names: {
type: TYPE$5,
value: "typeValue"
}
}));
AsnError.assertSchema(asn1, this.className);
this.type = asn1.result.type.valueBlock.toString();
this.value = asn1.result.typeValue;
}
toSchema() {
return (new asn1js__namespace.Sequence({
value: [
new asn1js__namespace.ObjectIdentifier({ value: this.type }),
this.value
]
}));
}
toJSON() {
const _object = {
type: this.type
};
if (Object.keys(this.value).length !== 0) {
_object.value = (this.value).toJSON();
}
else {
_object.value = this.value;
}
return _object;
}
isEqual(compareTo) {
const stringBlockNames = [
asn1js__namespace.Utf8String.blockName(),
asn1js__namespace.BmpString.blockName(),
asn1js__namespace.UniversalString.blockName(),
asn1js__namespace.NumericString.blockName(),
asn1js__namespace.PrintableString.blockName(),
asn1js__namespace.TeletexString.blockName(),
asn1js__namespace.VideotexString.blockName(),
asn1js__namespace.IA5String.blockName(),
asn1js__namespace.GraphicString.blockName(),
asn1js__namespace.VisibleString.blockName(),
asn1js__namespace.GeneralString.blockName(),
asn1js__namespace.CharacterString.blockName()
];
if (compareTo instanceof ArrayBuffer) {
return pvtsutils__namespace.BufferSourceConverter.isEqual(this.value.valueBeforeDecodeView, compareTo);
}
if (compareTo.constructor.blockName() === AttributeTypeAndValue.blockName()) {
if (this.type !== compareTo.type)
return false;
const isStringPair = [false, false];
const thisName = this.value.constructor.blockName();
for (const name of stringBlockNames) {
if (thisName === name) {
isStringPair[0] = true;
}
if (compareTo.value.constructor.blockName() === name) {
isStringPair[1] = true;
}
}
if (isStringPair[0] !== isStringPair[1]) {
return false;
}
const isString = (isStringPair[0] && isStringPair[1]);
if (isString) {
const value1 = stringPrep(this.value.valueBlock.value);
const value2 = stringPrep(compareTo.value.valueBlock.value);
if (value1.localeCompare(value2) !== 0)
return false;
}
else {
if (!pvtsutils__namespace.BufferSourceConverter.isEqual(this.value.valueBeforeDecodeView, compareTo.value.valueBeforeDecodeView))
return false;
}
return true;
}
return false;
}
}
AttributeTypeAndValue.CLASS_NAME = "AttributeTypeAndValue";
const TYPE_AND_VALUES = "typesAndValues";
const VALUE_BEFORE_DECODE = "valueBeforeDecode";
const RDN = "RDN";
class RelativeDistinguishedNames extends PkiObject {
constructor(parameters = {}) {
super();
this.typesAndValues = pvutils__namespace.getParametersValue(parameters, TYPE_AND_VALUES, RelativeDistinguishedNames.defaultValues(TYPE_AND_VALUES));
this.valueBeforeDecode = pvutils__namespace.getParametersValue(parameters, VALUE_BEFORE_DECODE, RelativeDistinguishedNames.defaultValues(VALUE_BEFORE_DECODE));
if (parameters.schema) {
this.fromSchema(parameters.schema);
}
}
static defaultValues(memberName) {
switch (memberName) {
case TYPE_AND_VALUES:
return [];
case VALUE_BEFORE_DECODE:
return EMPTY_BUFFER;
default:
return super.defaultValues(memberName);
}
}
static compareWithDefault(memberName, memberValue) {
switch (memberName) {
case TYPE_AND_VALUES:
return (memberValue.length === 0);
case VALUE_BEFORE_DECODE:
return (memberValue.byteLength === 0);
default:
return super.defaultValues(memberName);
}
}
static schema(parameters = {}) {
const names = pvutils__namespace.getParametersValue(parameters, "names", {});
return (new asn1js__namespace.Sequence({
name: (names.blockName || EMPTY_STRING),
value: [
new asn1js__namespace.Repeated({
name: (names.repeatedSequence || EMPTY_STRING),
value: new asn1js__namespace.Set({
value: [
new asn1js__namespace.Repeated({
name: (names.repeatedSet || EMPTY_STRING),
value: AttributeTypeAndValue.schema(names.typeAndValue || {})
})
]
})
})
]
}));
}
fromSchema(schema) {
pvutils__namespace.clearProps(schema, [
RDN,
TYPE_AND_VALUES
]);
const asn1 = asn1js__namespace.compareSchema(schema, schema, RelativeDistinguishedNames.schema({
names: {
blockName: RDN,
repeatedSet: TYPE_AND_VALUES
}
}));
AsnError.assertSchema(asn1, this.className);
if (TYPE_AND_VALUES in asn1.result) {
this.typesAndValues = Array.from(asn1.result.typesAndValues, element => new AttributeTypeAndValue({ schema: element }));
}
this.valueBeforeDecode = asn1.result.RDN.valueBeforeDecodeView.slice().buffer;
}
toSchema() {
if (this.valueBeforeDecode.byteLength === 0) {
return (new asn1js__namespace.Sequence({
value: [new asn1js__namespace.Set({
value: Array.from(this.typesAndValues, o => o.toSchema())
})]
}));
}
const asn1 = asn1js__namespace.fromBER(this.valueBeforeDecode);
AsnError.assert(asn1, "RelativeDistinguishedNames");
if (!(asn1.result instanceof asn1js__namespace.Sequence)) {
throw new Error("ASN.1 result should be SEQUENCE");
}
return asn1.result;
}
toJSON() {
return {
typesAndValues: Array.from(this.typesAndValues, o => o.toJSON())
};
}
isEqual(compareTo) {
if (compareTo instanceof RelativeDistinguishedNames) {
if (this.typesAndValues.length !== compareTo.typesAndValues.length)
return false;
for (const [index, typeAndValue] of this.typesAndValues.entries()) {
if (typeAndValue.isEqual(compareTo.typesAndValues[index]) === false)
return false;
}
return true;
}
if (compareTo instanceof ArrayBuffer) {
return pvutils__namespace.isEqualBuffer(this.valueBeforeDecode, compareTo);
}
return false;
}
}
RelativeDistinguishedNames.CLASS_NAME = "RelativeDistinguishedNames";
const TYPE$4 = "type";
const VALUE$5 = "value";
function builtInStandardAttributes(parameters = {}, optional = false) {
const names = pvutils__namespace.getParametersValue(parameters, "names", {});
return (new asn1js__namespace.Sequence({
optional,
value: [
new asn1js__namespace.Constructed({
optional: true,
idBlock: {
tagClass: 2,
tagNumber: 1
},
name: (names.country_name || EMPTY_STRING),
value: [
new asn1js__namespace.Choice({
value: [
new asn1js__namespace.NumericString(),
new asn1js__namespace.PrintableString()
]
})
]
}),
new asn1js__namespace.Constructed({
optional: true,
idBlock: {
tagClass: 2,
tagNumber: 2
},
name: (names.administration_domain_name || EMPTY_STRING),
value: [
new asn1js__namespace.Choice({
value: [
new asn1js__namespace.NumericString(),
new asn1js__namespace.PrintableString()
]
})
]
}),
new asn1js__namespace.Primitive({
optional: true,
idBlock: {
tagClass: 3,
tagNumber: 0
},
name: (names.network_address || EMPTY_STRING),
isHexOnly: true
}),
new asn1js__namespace.Primitive({
optional: true,
idBlock: {
tagClass: 3,
tagNumber: 1
},
name: (names.terminal_identifier || EMPTY_STRING),
isHexOnly: true
}),
new asn1js__namespace.Constructed({
optional: true,
idBlock: {
tagClass: 3,
tagNumber: 2
},
name: (names.private_domain_name || EMPTY_STRING),
value: [
new asn1js__namespace.Choice({
value: [
new asn1js__namespace.NumericString(),
new asn1js__namespace.PrintableString()
]
})
]
}),
new asn1js__namespace.Primitive({
optional: true,
idBlock: {
tagClass: 3,
tagNumber: 3
},
name: (names.organization_name || EMPTY_STRING),
isHexOnly: true
}),
new asn1js__namespace.Primitive({
optional: true,
name: (names.numeric_user_identifier || EMPTY_STRING),
idBlock: {
tagClass: 3,
tagNumber: 4
},
isHexOnly: true
}),
new asn1js__namespace.Constructed({
optional: true,
name: (names.personal_name || EMPTY_STRING),
idBlock: {
tagClass: 3,
tagNumber: 5
},
value: [
new asn1js__namespace.Primitive({
idBlock: {
tagClass: 3,
tagNumber: 0
},
isHexOnly: true
}),
new asn1js__namespace.Primitive({
optional: true,
idBlock: {
tagClass: 3,
tagNumber: 1
},
isHexOnly: true
}),
new asn1js__namespace.Primitive({
optional: true,
idBlock: {
tagClass: 3,
tagNumber: 2
},
isHexOnly: true
}),
new asn1js__namespace.Primitive({
optional: true,
idBlock: {
tagClass: 3,
tagNumber: 3
},
isHexOnly: true
})
]
}),
new asn1js__namespace.Constructed({
optional: true,
name: (names.organizational_unit_names || EMPTY_STRING),
idBlock: {
tagClass: 3,
tagNumber: 6
},
value: [
new asn1js__namespace.Repeated({
value: new asn1js__namespace.PrintableString()
})
]
})
]
}));
}
function builtInDomainDefinedAttributes(optional = false) {
return (new asn1js__namespace.Sequence({
optional,
value: [
new asn1js__namespace.PrintableString(),
new asn1js__namespace.PrintableString()
]
}));
}
function extensionAttributes(optional = false) {
return (new asn1js__namespace.Set({
optional,
value: [
new asn1js__namespace.Primitive({
optional: true,
idBlock: {
tagClass: 3,
tagNumber: 0
},
isHexOnly: true
}),
new asn1js__namespace.Constructed({
optional: true,
idBlock: {
tagClass: 3,
tagNumber: 1
},
value: [new asn1js__namespace.Any()]
})
]
}));
}
class GeneralName extends PkiObject {
constructor(parameters = {}) {
super();
this.type = pvutils__namespace.getParametersValue(parameters, TYPE$4, GeneralName.defaultValues(TYPE$4));
this.value = pvutils__namespace.getParametersValue(parameters, VALUE$5, GeneralName.defaultValues(VALUE$5));
if (parameters.schema) {
this.fromSchema(parameters.schema);
}
}
static defaultValues(memberName) {
switch (memberName) {
case TYPE$4:
return 9;
case VALUE$5:
return {};
default:
return super.defaultValues(memberName);
}
}
static compareWithDefault(memberName, memberValue) {
switch (memberName) {
case TYPE$4:
return (memberValue === GeneralName.defaultValues(memberName));
case VALUE$5:
return (Object.keys(memberValue).length === 0);
default:
return super.defaultValues(memberName);
}
}
static schema(parameters = {}) {
const names = pvutils__namespace.getParametersValue(parameters, "names", {});
return (new asn1js__namespace.Choice({
value: [
new asn1js__namespace.Constructed({
idBlock: {
tagClass: 3,
tagNumber: 0
},
name: (names.blockName || EMPTY_STRING),
value: [
new asn1js__namespace.ObjectIdentifier(),
new asn1js__namespace.Constructed({
idBlock: {
tagClass: 3,
tagNumber: 0
},
value: [new asn1js__namespace.Any()]
})
]
}),
new asn1js__namespace.Primitive({
name: (names.blockName || EMPTY_STRING),
idBlock: {
tagClass: 3,
tagNumber: 1
}
}),
new asn1js__namespace.Primitive({
name: (names.blockName || EMPTY_STRING),
idBlock: {
tagClass: 3,
tagNumber: 2
}
}),
new asn1js__namespace.Constructed({
idBlock: {
tagClass: 3,
tagNumber: 3
},
name: (names.blockName || EMPTY_STRING),
value: [
builtInStandardAttributes((names.builtInStandardAttributes || {}), false),
builtInDomainDefinedAttributes(true),
extensionAttributes(true)
]
}),
new asn1js__namespace.Constructed({
idBlock: {
tagClass: 3,
tagNumber: 4
},
name: (names.blockName || EMPTY_STRING),
value: [RelativeDistinguishedNames.schema(names.directoryName || {})]
}),
new asn1js__namespace.Constructed({
idBlock: {
tagClass: 3,
tagNumber: 5
},
name: (names.blockName || EMPTY_STRING),
value: [
new asn1js__namespace.Constructed({
optional: true,
idBlock: {
tagClass: 3,
tagNumber: 0
},
value: [
new asn1js__namespace.Choice({
value: [
new asn1js__namespace.TeletexString(),
new asn1js__namespace.PrintableString(),
new asn1js__namespace.UniversalString(),
new asn1js__namespace.Utf8String(),
new asn1js__namespace.BmpString()
]
})
]
}),
new asn1js__namespace.Constructed({
idBlock: {
tagClass: 3,
tagNumber: 1
},
value: [
new asn1js__namespace.Choice({
value: [
new asn1js__namespace.TeletexString(),
new asn1js__namespace.PrintableString(),
new asn1js__namespace.UniversalString(),
new asn1js__namespace.Utf8String(),
new asn1js__namespace.BmpString()
]
})
]
})
]
}),
new asn1js__namespace.Primitive({
name: (names.blockName || EMPTY_STRING),
idBlock: {
tagClass: 3,
tagNumber: 6
}
}),
new asn1js__namespace.Primitive({
name: (names.blockName || EMPTY_STRING),
idBlock: {
tagClass: 3,
tagNumber: 7
}
}),
new asn1js__namespace.Primitive({
name: (names.blockName || EMPTY_STRING),
idBlock: {
tagClass: 3,
tagNumber: 8
}
})
]
}));
}
fromSchema(schema) {
pvutils__namespace.clearProps(schema, [
"blockName",
"otherName",
"rfc822Name",
"dNSName",
"x400Address",
"directoryName",
"ediPartyName",
"uniformResourceIdentifier",
"iPAddress",
"registeredID"
]);
const asn1 = asn1js__namespace.compareSchema(schema, schema, GeneralName.schema({
names: {
blockName: "blockName",
otherName: "otherName",
rfc822Name: "rfc822Name",
dNSName: "dNSName",
x400Address: "x400Address",
directoryName: {
names: {
blockName: "directoryName"
}
},
ediPartyName: "ediPartyName",
uniformResourceIdentifier: "uniformResourceIdentifier",
iPAddress: "iPAddress",
registeredID: "registeredID"
}
}));
AsnError.assertSchema(asn1, this.className);
this.type = asn1.result.blockName.idBlock.tagNumber;
switch (this.type) {
case 0:
this.value = asn1.result.blockName;
break;
case 1:
case 2:
case 6:
{
const value = asn1.result.blockName;
value.idBlock.tagClass = 1;
value.idBlock.tagNumber = 22;
const valueBER = value.toBER(false);
const asnValue = asn1js__namespace.fromBER(valueBER);
AsnError.assert(asnValue, "GeneralName value");
this.value = asnValue.result.valueBlock.value;
}
break;
case 3:
this.value = asn1.result.blockName;
break;
case 4:
this.value = new RelativeDistinguishedNames({ schema: asn1.result.directoryName });
break;
case 5:
this.value = asn1.result.ediPartyName;
break;
case 7:
this.value = new asn1js__namespace.OctetString({ valueHex: asn1.result.blockName.valueBlock.valueHex });
break;
case 8:
{
const value = asn1.result.blockName;
value.idBlock.tagClass = 1;
value.idBlock.tagNumber = 6;
const valueBER = value.toBER(false);
const asnValue = asn1js__namespace.fromBER(valueBER);
AsnError.assert(asnValue, "GeneralName registeredID");
this.value = asnValue.result.valueBlock.toString();
}
break;
}
}
toSchema() {
switch (this.type) {
case 0:
case 3:
case 5:
return new asn1js__namespace.Constructed({
idBlock: {
tagClass: 3,
tagNumber: this.type
},
value: [
this.value
]
});
case 1:
case 2:
case 6:
{
const value = new asn1js__namespace.IA5String({ value: this.value });
value.idBlock.tagClass = 3;
value.idBlock.tagNumber = this.type;
return value;
}
case 4:
return new asn1js__namespace.Constructed({
idBlock: {
tagClass: 3,
tagNumber: 4
},
value: [this.value.toSchema()]
});
case 7:
{
const value = this.value;
value.idBlock.tagClass = 3;
value.idBlock.tagNumber = this.type;
return value;
}
case 8:
{
const value = new asn1js__namespace.ObjectIdentifier({ value: this.value });
value.idBlock.tagClass = 3;
value.idBlock.tagNumber = this.type;
return value;
}
default:
return GeneralName.schema();
}
}
toJSON() {
const _object = {
type: this.type,
value: EMPTY_STRING
};
if ((typeof this.value) === "string")
_object.value = this.value;
else {
try {
_object.value = this.value.toJSON();
}
catch {
}
}
return _object;
}
}
GeneralName.CLASS_NAME = "GeneralName";
const ACCESS_METHOD = "accessMethod";
const ACCESS_LOCATION = "accessLocation";
const CLEAR_PROPS$1v = [
ACCESS_METHOD,
ACCESS_LOCATION,
];
class AccessDescription extends PkiObject {
constructor(parameters = {}) {
super();
this.accessMethod = pvutils__namespace.getParametersValue(parameters, ACCESS_METHOD, AccessDescription.defaultValues(ACCESS_METHOD));
this.accessLocation = pvutils__namespace.getParametersValue(parameters, ACCESS_LOCATION, AccessDescription.defaultValues(ACCESS_LOCATION));
if (parameters.schema) {
this.fromSchema(parameters.schema);
}
}
static defaultValues(memberName) {
switch (memberName) {
case ACCESS_METHOD:
return EMPTY_STRING;
case ACCESS_LOCATION:
return new GeneralName();
default:
return super.defaultValues(memberName);
}
}
static schema(parameters = {}) {
const names = pvutils__namespace.getParametersValue(parameters, "names", {});
return (new asn1js__namespace.Sequence({
name: (names.blockName || EMPTY_STRING),
value: [
new asn1js__namespace.ObjectIdentifier({ name: (names.accessMethod || EMPTY_STRING) }),
GeneralName.schema(names.accessLocation || {})
]
}));
}
fromSchema(schema) {
pvutils__namespace.clearProps(schema, CLEAR_PROPS$1v);
const asn1 = asn1js__namespace.compareSchema(schema, schema, AccessDescription.schema({
names: {
accessMethod: ACCESS_METHOD,
accessLocation: {
names: {
blockName: ACCESS_LOCATION
}
}
}
}));
AsnError.assertSchema(asn1, this.className);
this.accessMethod = asn1.result.accessMethod.valueBlock.toString();
this.accessLocation = new GeneralName({ schema: asn1.result.accessLocation });
}
toSchema() {
return (new asn1js__namespace.Sequence({
value: [
new asn1js__namespace.ObjectIdentifier({ value: this.accessMethod }),
this.accessLocation.toSchema()
]
}));
}
toJSON() {
return {
accessMethod: this.accessMethod,
accessLocation: this.accessLocation.toJSON()
};
}
}
AccessDescription.CLASS_NAME = "AccessDescription";
const SECONDS = "seconds";
const MILLIS = "millis";
const MICROS = "micros";
class Accuracy extends PkiObject {
constructor(parameters = {}) {
super();
if (SECONDS in parameters) {
this.seconds = pvutils__namespace.getParametersValue(parameters, SECONDS, Accuracy.defaultValues(SECONDS));
}
if (MILLIS in parameters) {
this.millis = pvutils__namespace.getParametersValue(parameters, MILLIS, Accuracy.defaultValues(MILLIS));
}
if (MICROS in parameters) {
this.micros = pvutils__namespace.getParametersValue(parameters, MICROS, Accuracy.defaultValues(MICROS));
}
if (parameters.schema) {
this.fromSchema(parameters.schema);
}
}
static defaultValues(memberName) {
switch (memberName) {
case SECONDS:
case MILLIS:
case MICROS:
return 0;
default:
return super.defaultValues(memberName);
}
}
static compareWithDefault(memberName, memberValue) {
switch (memberName) {
case SECONDS:
case MILLIS:
case MICROS:
return (memberValue === Accuracy.defaultValues(memberName));
default:
return super.defaultValues(memberName);
}
}
static schema(parameters = {}) {
const names = pvutils__namespace.getParametersValue(parameters, "names", {});
return (new asn1js__namespace.Sequence({
name: (names.blockName || EMPTY_STRING),
optional: true,
value: [
new asn1js__namespace.Integer({
optional: true,
name: (names.seconds || EMPTY_STRING)
}),
new asn1js__namespace.Primitive({
name: (names.millis || EMPTY_STRING),
optional: true,
idBlock: {
tagClass: 3,
tagNumber: 0
}
}),
new asn1js__namespace.Primitive({
name: (names.micros || EMPTY_STRING),
optional: true,
idBlock: {
tagClass: 3,
tagNumber: 1
}
})
]
}));
}
fromSchema(schema) {
pvutils__namespace.clearProps(schema, [
SECONDS,
MILLIS,
MICROS,
]);
const asn1 = asn1js__namespace.compareSchema(schema, schema, Accuracy.schema({
names: {
seconds: SECONDS,
millis: MILLIS,
micros: MICROS,
}
}));
AsnError.assertSchema(asn1, this.className);
if ("seconds" in asn1.result) {
this.seconds = asn1.result.seconds.valueBlock.valueDec;
}
if ("millis" in asn1.result) {
const intMillis = new asn1js__namespace.Integer({ valueHex: asn1.result.millis.valueBlock.valueHex });
this.millis = intMillis.valueBlock.valueDec;
}
if ("micros" in asn1.result) {
const intMicros = new asn1js__namespace.Integer({ valueHex: asn1.result.micros.valueBlock.valueHex });
this.micros = intMicros.valueBlock.valueDec;
}
}
toSchema() {
const outputArray = [];
if (this.seconds !== undefined)
outputArray.push(new asn1js__namespace.Integer({ value: this.seconds }));
if (this.millis !== undefined) {
const intMillis = new asn1js__namespace.Integer({ value: this.millis });
outputArray.push(new asn1js__namespace.Primitive({
idBlock: {
tagClass: 3,
tagNumber: 0
},
valueHex: intMillis.valueBlock.valueHexView
}));
}
if (this.micros !== undefined) {
const intMicros = new asn1js__namespace.Integer({ value: this.micros });
outputArray.push(new asn1js__namespace.Primitive({
idBlock: {
tagClass: 3,
tagNumber: 1
},
valueHex: intMicros.valueBlock.valueHexView
}));
}
return (new asn1js__namespace.Sequence({
value: outputArray
}));
}
toJSON() {
const _object = {};
if (this.seconds !== undefined)
_object.seconds = this.seconds;
if (this.millis !== undefined)
_object.millis = this.millis;
if (this.micros !== undefined)
_object.micros = this.micros;
return _object;
}
}
Accuracy.CLASS_NAME = "Accuracy";
const ALGORITHM_ID = "algorithmId";
const ALGORITHM_PARAMS = "algorithmParams";
const ALGORITHM$2 = "algorithm";
const PARAMS = "params";
const CLEAR_PROPS$1u = [
ALGORITHM$2,
PARAMS
];
class AlgorithmIdentifier extends PkiObject {
constructor(parameters = {}) {
super();
this.algorithmId = pvutils__namespace.getParametersValue(parameters, ALGORITHM_ID, AlgorithmIdentifier.defaultValues(ALGORITHM_ID));
if (ALGORITHM_PARAMS in parameters) {
this.algorithmParams = pvutils__namespace.getParametersValue(parameters, ALGORITHM_PARAMS, AlgorithmIdentifier.defaultValues(ALGORITHM_PARAMS));
}
if (parameters.schema) {
this.fromSchema(parameters.schema);
}
}
static defaultValues(memberName) {
switch (memberName) {
case ALGORITHM_ID:
return EMPTY_STRING;
case ALGORITHM_PARAMS:
return new asn1js__namespace.Any();
default:
return super.defaultValues(memberName);
}
}
static compareWithDefault(memberName, memberValue) {
switch (memberName) {
case ALGORITHM_ID:
return (memberValue === EMPTY_STRING);
case ALGORITHM_PARAMS:
return (memberValue instanceof asn1js__namespace.Any);
default:
return super.defaultValues(memberName);
}
}
static schema(parameters = {}) {
const names = pvutils__namespace.getParametersValue(parameters, "names", {});
return (new asn1js__namespace.Sequence({
name: (names.blockName || EMPTY_STRING),
optional: (names.optional || false),
value: [
new asn1js__namespace.ObjectIdentifier({ name: (names.algorithmIdentifier || EMPTY_STRING) }),
new asn1js__namespace.Any({ name: (names.algorithmParams || EMPTY_STRING), optional: true })
]
}));
}
fromSchema(schema) {
pvutils__namespace.clearProps(schema, CLEAR_PROPS$1u);
const asn1 = asn1js__namespace.compareSchema(schema, schema, AlgorithmIdentifier.schema({
names: {
algorithmIdentifier: ALGORITHM$2,
algorithmParams: PARAMS
}
}));
AsnError.assertSchema(asn1, this.className);
this.algorithmId = asn1.result.algorithm.valueBlock.toString();
if (PARAMS in asn1.result) {
this.algorithmParams = asn1.result.params;
}
}
toSchema() {
const outputArray = [];
outputArray.push(new asn1js__namespace.ObjectIdentifier({ value: this.algorithmId }));
if (this.algorithmParams && !(this.algorithmParams instanceof asn1js__namespace.Any)) {
outputArray.push(this.algorithmParams);
}
return (new asn1js__namespace.Sequence({
value: outputArray
}));
}
toJSON() {
const object = {
algorithmId: this.algorithmId
};
if (this.algorithmParams && !(this.algorithmParams instanceof asn1js__namespace.Any)) {
object.algorithmParams = this.algorithmParams.toJSON();
}
return object;
}
isEqual(algorithmIdentifier) {
if (!(algorithmIdentifier instanceof AlgorithmIdentifier)) {
return false;
}
if (this.algorithmId !== algorithmIdentifier.algorithmId) {
return false;
}
if (this.algorithmParams) {
if (algorithmIdentifier.algorithmParams) {
return JSON.stringify(this.algorithmParams) === JSON.stringify(algorithmIdentifier.algorithmParams);
}
return false;
}
if (algorithmIdentifier.algorithmParams) {
return false;
}
return true;
}
}
AlgorithmIdentifier.CLASS_NAME = "AlgorithmIdentifier";
const ALT_NAMES = "altNames";
const CLEAR_PROPS$1t = [
ALT_NAMES
];
class AltName extends PkiObject {
constructor(parameters = {}) {
super();
this.altNames = pvutils__namespace.getParametersValue(parameters, ALT_NAMES, AltName.defaultValues(ALT_NAMES));
if (parameters.schema) {
this.fromSchema(parameters.schema);
}
}
static defaultValues(memberName) {
switch (memberName) {
case ALT_NAMES:
return [];
default:
return super.defaultValues(memberName);
}
}
static schema(parameters = {}) {
const names = pvutils__namespace.getParametersValue(parameters, "names", {});
return (new asn1js__namespace.Sequence({
name: (names.blockName || EMPTY_STRING),
value: [
new asn1js__namespace.Repeated({
name: (names.altNames || EMPTY_STRING),
value: GeneralName.schema()
})
]
}));
}
fromSchema(schema) {
pvutils__namespace.clearProps(schema, CLEAR_PROPS$1t);
const asn1 = asn1js__namespace.compareSchema(schema, schema, AltName.schema({
names: {
altNames: ALT_NAMES
}
}));
AsnError.assertSchema(asn1, this.className);
if (ALT_NAMES in asn1.result) {
this.altNames = Array.from(asn1.result.altNames, element => new GeneralName({ schema: element }));
}
}
toSchema() {
return (new asn1js__namespace.Sequence({
value: Array.from(this.altNames, o => o.toSchema())
}));
}
toJSON() {
return {
altNames: Array.from(this.altNames, o => o.toJSON())
};
}
}
AltName.CLASS_NAME = "AltName";
const TYPE$3 = "type";
const VALUES$1 = "values";
const CLEAR_PROPS$1s = [
TYPE$3,
VALUES$1
];
class Attribute extends PkiObject {
constructor(parameters = {}) {
super();
this.type = pvutils__namespace.getParametersValue(parameters, TYPE$3, Attribute.defaultValues(TYPE$3));
this.values = pvutils__namespace.getParametersValue(parameters, VALUES$1, Attribute.defaultValues(VALUES$1));
if (parameters.schema) {
this.fromSchema(parameters.schema);
}
}
static defaultValues(memberName) {
switch (memberName) {
case TYPE$3:
return EMPTY_STRING;
case VALUES$1:
return [];
default:
return super.defaultValues(memberName);
}
}
static compareWithDefault(memberName, memberValue) {
switch (memberName) {
case TYPE$3:
return (memberValue === EMPTY_STRING);
case VALUES$1:
return (memberValue.length === 0);
default:
return super.defaultValues(memberName);
}
}
static schema(parameters = {}) {
const names = pvutils__namespace.getParametersValue(parameters, "names", {});
return (new asn1js__namespace.Sequence({
name: (names.blockName || EMPTY_STRING),
value: [
new asn1js__namespace.ObjectIdentifier({ name: (names.type || EMPTY_STRING) }),
new asn1js__namespace.Set({
name: (names.setName || EMPTY_STRING),
value: [
new asn1js__namespace.Repeated({
name: (names.values || EMPTY_STRING),
value: new asn1js__namespace.Any()
})
]
})
]
}));
}
fromSchema(schema) {
pvutils__namespace.clearProps(schema, CLEAR_PROPS$1s);
const asn1 = asn1js__namespace.compareSchema(schema, schema, Attribute.schema({
names: {
type: TYPE$3,
values: VALUES$1
}
}));
AsnError.assertSchema(asn1, this.className);
this.type = asn1.result.type.valueBlock.toString();
this.values = asn1.result.values;
}
toSchema() {
return (new asn1js__namespace.Sequence({
value: [
new asn1js__namespace.ObjectIdentifier({ value: this.type }),
new asn1js__namespace.Set({
value: this.values
})
]
}));
}
toJSON() {
return {
type: this.type,
values: Array.from(this.values, o => o.toJSON())
};
}
}
Attribute.CLASS_NAME = "Attribute";
const NOT_BEFORE_TIME = "notBeforeTime";
const NOT_AFTER_TIME = "notAfterTime";
const CLEAR_PROPS$1r = [
NOT_BEFORE_TIME,
NOT_AFTER_TIME,
];
class AttCertValidityPeriod extends PkiObject {
constructor(parameters = {}) {
super();
this.notBeforeTime = pvutils__namespace.getParametersValue(parameters, NOT_BEFORE_TIME, AttCertValidityPeriod.defaultValues(NOT_BEFORE_TIME));
this.notAfterTime = pvutils__namespace.getParametersValue(parameters, NOT_AFTER_TIME, AttCertValidityPeriod.defaultValues(NOT_AFTER_TIME));
if (parameters.schema) {
this.fromSchema(parameters.schema);
}
}
static defaultValues(memberName) {
switch (memberName) {
case NOT_BEFORE_TIME:
case NOT_AFTER_TIME:
return new Date(0, 0, 0);