@wildboar/pki-stub
Version:
X.510 PKI-Stub ASN.1 data structures in TypeScript
236 lines (235 loc) • 7.95 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { v1 /* IMPORTED_SHORT_NAMED_INTEGER */, _decode_Version, _encode_Version, } from "../PKI-Stub/Version.ta.mjs";
import { _decode_AvlSerialNumber, _encode_AvlSerialNumber, } from "../PKI-Stub/AvlSerialNumber.ta.mjs";
import { _decode_AlgorithmIdentifier, _encode_AlgorithmIdentifier, } from "../PKI-Stub/AlgorithmIdentifier.ta.mjs";
import { _decode_Name, _encode_Name } from "../PKI-Stub/Name.ta.mjs";
import { _decode_TBSCertAVL_entries_Item, _encode_TBSCertAVL_entries_Item, } from "../PKI-Stub/TBSCertAVL-entries-Item.ta.mjs";
import { _decode_Extensions, _encode_Extensions, } from "../PKI-Stub/Extensions.ta.mjs";
/**
* @summary TBSCertAVL
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* TBSCertAVL ::= SEQUENCE {
* version [0] IMPLICIT Version DEFAULT v1,
* serialNumber AvlSerialNumber OPTIONAL,
* signature AlgorithmIdentifier {{SupportedAlgorithms}},
* issuer Name,
* constrained BOOLEAN,
* entries SEQUENCE (SIZE (1..MAX)) OF SEQUENCE {
* idType CHOICE {
* certIdentifier [0] PKCertIdentifier,
* entityGroup DistinguishedName, -- only for constrained = FALSE
* ... },
* scope [0] IMPLICIT ScopeRestrictions OPTIONAL,
* entryExtensions [1] IMPLICIT Extensions OPTIONAL,
* ... },
* ...,
* ...,
* avlExtensions Extensions OPTIONAL }
* ```
*
*/
export class TBSCertAVL {
version;
serialNumber;
signature;
issuer;
constrained;
entries;
_unrecognizedExtensionsList;
avlExtensions;
constructor(
/**
* @summary `version`.
* @public
* @readonly
*/
version,
/**
* @summary `serialNumber`.
* @public
* @readonly
*/
serialNumber,
/**
* @summary `signature`.
* @public
* @readonly
*/
signature,
/**
* @summary `issuer`.
* @public
* @readonly
*/
issuer,
/**
* @summary `constrained`.
* @public
* @readonly
*/
constrained,
/**
* @summary `entries`.
* @public
* @readonly
*/
entries,
/**
* @summary Extensions that are not recognized.
* @public
* @readonly
*/
_unrecognizedExtensionsList = [],
/**
* @summary `avlExtensions`.
* @public
* @readonly
*/
avlExtensions) {
this.version = version;
this.serialNumber = serialNumber;
this.signature = signature;
this.issuer = issuer;
this.constrained = constrained;
this.entries = entries;
this._unrecognizedExtensionsList = _unrecognizedExtensionsList;
this.avlExtensions = avlExtensions;
}
/**
* @summary Restructures an object into a TBSCertAVL
* @description
*
* This takes an `object` and converts it to a `TBSCertAVL`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `TBSCertAVL`.
* @returns {TBSCertAVL}
*/
static _from_object(_o) {
return new TBSCertAVL(_o.version, _o.serialNumber, _o.signature, _o.issuer, _o.constrained, _o.entries, _o._unrecognizedExtensionsList, _o.avlExtensions);
}
/**
* @summary Getter that returns the default value for `version`.
* @public
* @static
* @method
*/
static get _default_value_for_version() {
return v1;
}
}
/**
* @summary The Leading Root Component Types of TBSCertAVL
* @description
*
* This is an array of `ComponentSpec`s that define how to decode the leading root component type list of a SET or SEQUENCE.
*
* @constant
*/
export const _root_component_type_list_1_spec_for_TBSCertAVL = [
new $.ComponentSpec("version", true, $.hasTag(_TagClass.context, 0)),
new $.ComponentSpec("serialNumber", true, $.hasTag(_TagClass.universal, 2)),
new $.ComponentSpec("signature", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("issuer", false, $.hasAnyTag),
new $.ComponentSpec("constrained", false, $.hasTag(_TagClass.universal, 1)),
new $.ComponentSpec("entries", false, $.hasTag(_TagClass.universal, 16)),
];
/**
* @summary The Trailing Root Component Types of TBSCertAVL
* @description
*
* This is an array of `ComponentSpec`s that define how to decode the trailing root component type list of a SET or SEQUENCE.
*
* @constant
*/
export const _root_component_type_list_2_spec_for_TBSCertAVL = [
new $.ComponentSpec("avlExtensions", true, $.hasTag(_TagClass.universal, 16)),
];
/**
* @summary The Extension Addition Component Types of TBSCertAVL
* @description
*
* This is an array of `ComponentSpec`s that define how to decode the extension addition component type list of a SET or SEQUENCE.
*
* @constant
*/
export const _extension_additions_list_spec_for_TBSCertAVL = [];
/**
* @summary Decodes an ASN.1 element into a(n) TBSCertAVL
* @function
* @param {_Element} el The element being decoded.
* @returns {TBSCertAVL} The decoded data structure.
*/
export function _decode_TBSCertAVL(el) {
let version = TBSCertAVL._default_value_for_version;
let serialNumber;
let signature;
let issuer;
let constrained;
let entries;
let _unrecognizedExtensionsList = [];
let avlExtensions;
const callbacks = {
version: (_el) => {
version = $._decode_implicit(() => _decode_Version)(_el);
},
serialNumber: (_el) => {
serialNumber = _decode_AvlSerialNumber(_el);
},
signature: (_el) => {
signature = _decode_AlgorithmIdentifier(_el);
},
issuer: (_el) => {
issuer = _decode_Name(_el);
},
constrained: (_el) => {
constrained = $._decodeBoolean(_el);
},
entries: (_el) => {
entries = $._decodeSequenceOf(() => _decode_TBSCertAVL_entries_Item)(_el);
},
avlExtensions: (_el) => {
avlExtensions = _decode_Extensions(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_TBSCertAVL, _extension_additions_list_spec_for_TBSCertAVL, _root_component_type_list_2_spec_for_TBSCertAVL, (ext) => {
_unrecognizedExtensionsList.push(ext);
});
return new TBSCertAVL(version, serialNumber, signature, issuer, constrained, entries, _unrecognizedExtensionsList, avlExtensions);
}
/**
* @summary Encodes a(n) TBSCertAVL into an ASN.1 Element.
* @function
* @param value The element being encoded.
* @param elGetter A function that can be used to get new ASN.1 elements.
* @returns {_Element} The TBSCertAVL, encoded as an ASN.1 Element.
*/
export function _encode_TBSCertAVL(value) {
const components = [];
if (value.version != TBSCertAVL._default_value_for_version) {
const c = $._encode_implicit(_TagClass.context, 0, () => _encode_Version, $.BER)(value.version, $.BER);
components.push(c);
}
if (value.serialNumber !== undefined) {
const c = _encode_AvlSerialNumber(value.serialNumber, $.BER);
components.push(c);
}
components.push(_encode_AlgorithmIdentifier(value.signature, $.BER));
components.push(_encode_Name(value.issuer, $.BER));
components.push($._encodeBoolean(value.constrained, $.BER));
components.push($._encodeSequenceOf(() => _encode_TBSCertAVL_entries_Item, $.BER)(value.entries, $.BER));
components.push(...value._unrecognizedExtensionsList ?? []);
if (value.avlExtensions?.length) {
components.push(_encode_Extensions(value.avlExtensions, $.BER));
}
return $._encodeSequence(components, $.BER);
}
/* eslint-enable */