@wildboar/pki-stub
Version:
X.510 PKI-Stub ASN.1 data structures in TypeScript
146 lines (145 loc) • 4.94 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_IssuerSerial, _encode_IssuerSerial, } from "../PKI-Stub/IssuerSerial.ta.mjs";
import { _decode_GeneralNames, _encode_GeneralNames, } from "../PKI-Stub/GeneralNames.ta.mjs";
import { _decode_ObjectDigestInfo, _encode_ObjectDigestInfo, } from "../PKI-Stub/ObjectDigestInfo.ta.mjs";
/**
* @summary Holder
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* Holder ::= SEQUENCE {
* baseCertificateID [0] IssuerSerial OPTIONAL,
* entityName [1] GeneralNames OPTIONAL,
* objectDigestInfo [2] ObjectDigestInfo OPTIONAL }
* (WITH COMPONENTS {..., baseCertificateID PRESENT } |
* WITH COMPONENTS {..., entityName PRESENT } |
* WITH COMPONENTS {..., objectDigestInfo PRESENT } )
* ```
*
*/
export class Holder {
baseCertificateID;
entityName;
objectDigestInfo;
constructor(
/**
* @summary `baseCertificateID`.
* @public
* @readonly
*/
baseCertificateID,
/**
* @summary `entityName`.
* @public
* @readonly
*/
entityName,
/**
* @summary `objectDigestInfo`.
* @public
* @readonly
*/
objectDigestInfo) {
this.baseCertificateID = baseCertificateID;
this.entityName = entityName;
this.objectDigestInfo = objectDigestInfo;
}
/**
* @summary Restructures an object into a Holder
* @description
*
* This takes an `object` and converts it to a `Holder`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `Holder`.
* @returns {Holder}
*/
static _from_object(_o) {
return new Holder(_o.baseCertificateID, _o.entityName, _o.objectDigestInfo);
}
}
/**
* @summary The Leading Root Component Types of Holder
* @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_Holder = [
new $.ComponentSpec("baseCertificateID", true, $.hasTag(_TagClass.context, 0)),
new $.ComponentSpec("entityName", true, $.hasTag(_TagClass.context, 1)),
new $.ComponentSpec("objectDigestInfo", true, $.hasTag(_TagClass.context, 2)),
];
/**
* @summary The Trailing Root Component Types of Holder
* @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_Holder = [];
/**
* @summary The Extension Addition Component Types of Holder
* @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_Holder = [];
/**
* @summary Decodes an ASN.1 element into a(n) Holder
* @function
* @param {_Element} el The element being decoded.
* @returns {Holder} The decoded data structure.
*/
export function _decode_Holder(el) {
let baseCertificateID;
let entityName;
let objectDigestInfo;
const callbacks = {
baseCertificateID: (_el) => {
baseCertificateID = $._decode_implicit(() => _decode_IssuerSerial)(_el);
},
entityName: (_el) => {
entityName = $._decode_implicit(() => _decode_GeneralNames)(_el);
},
objectDigestInfo: (_el) => {
objectDigestInfo = $._decode_implicit(() => _decode_ObjectDigestInfo)(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_Holder, _extension_additions_list_spec_for_Holder, _root_component_type_list_2_spec_for_Holder, undefined);
return new Holder(baseCertificateID, entityName, objectDigestInfo);
}
/**
* @summary Encodes a(n) Holder 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 Holder, encoded as an ASN.1 Element.
*/
export function _encode_Holder(value, _elGetter) {
const components = [];
if (value.baseCertificateID) {
const c = $._encode_implicit(_TagClass.context, 0, () => _encode_IssuerSerial, $.BER)(value.baseCertificateID, $.BER);
components.push(c);
}
if (value.entityName) {
const c = $._encode_implicit(_TagClass.context, 1, () => _encode_GeneralNames, $.BER)(value.entityName, $.BER);
components.push(c);
}
if (value.objectDigestInfo) {
const c = $._encode_implicit(_TagClass.context, 2, () => _encode_ObjectDigestInfo, $.BER)(value.objectDigestInfo, $.BER);
components.push(c);
}
return $._encodeSequence(components, $.BER);
}
/* eslint-enable */