@wildboar/pc
Version:
Trusted Computing Group Platform Certificate ASN.1 data structures in TypeScript
126 lines (125 loc) • 5.27 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_AttributeCertificateIdentifier, _encode_AttributeCertificateIdentifier } from "../PlatformCertificateProfile/AttributeCertificateIdentifier.ta.mjs";
import { _decode_IssuerSerial, _encode_IssuerSerial, } from "@wildboar/x500/AttributeCertificateDefinitions";
/**
* @summary CertificateIdentifier
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* CertificateIdentifier ::= SEQUENCE {
* attributeCertIdentifier [0] IMPLICIT AttributeCertificateIdentifier OPTIONAL,
* genericCertIdentifier [1] IMPLICIT IssuerSerial OPTIONAL }
* ```
*
*/
export class CertificateIdentifier {
attributeCertIdentifier;
genericCertIdentifier;
constructor(
/**
* @summary `attributeCertIdentifier`.
* @public
* @readonly
*/
attributeCertIdentifier,
/**
* @summary `genericCertIdentifier`.
* @public
* @readonly
*/
genericCertIdentifier) {
this.attributeCertIdentifier = attributeCertIdentifier;
this.genericCertIdentifier = genericCertIdentifier;
}
/**
* @summary Restructures an object into a CertificateIdentifier
* @description
*
* This takes an `object` and converts it to a `CertificateIdentifier`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `CertificateIdentifier`.
* @returns {CertificateIdentifier}
*/
static _from_object(_o) {
return new CertificateIdentifier(_o.attributeCertIdentifier, _o.genericCertIdentifier);
}
}
/**
* @summary The Leading Root Component Types of CertificateIdentifier
* @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_CertificateIdentifier = [
new $.ComponentSpec("attributeCertIdentifier", true, $.hasTag(_TagClass.context, 0)),
new $.ComponentSpec("genericCertIdentifier", true, $.hasTag(_TagClass.context, 1)),
];
/**
* @summary The Trailing Root Component Types of CertificateIdentifier
* @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_CertificateIdentifier = [];
/**
* @summary The Extension Addition Component Types of CertificateIdentifier
* @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_CertificateIdentifier = [];
let _cached_decoder_for_CertificateIdentifier = null;
/**
* @summary Decodes an ASN.1 element into a(n) CertificateIdentifier
* @function
* @param {_Element} el The element being decoded.
* @returns {CertificateIdentifier} The decoded data structure.
*/
export function _decode_CertificateIdentifier(el) {
if (!_cached_decoder_for_CertificateIdentifier) {
_cached_decoder_for_CertificateIdentifier = function (el) {
let attributeCertIdentifier;
let genericCertIdentifier;
const callbacks = {
"attributeCertIdentifier": (_el) => { attributeCertIdentifier = $._decode_implicit(() => _decode_AttributeCertificateIdentifier)(_el); },
"genericCertIdentifier": (_el) => { genericCertIdentifier = $._decode_implicit(() => _decode_IssuerSerial)(_el); }
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_CertificateIdentifier, _extension_additions_list_spec_for_CertificateIdentifier, _root_component_type_list_2_spec_for_CertificateIdentifier, undefined);
return new CertificateIdentifier(attributeCertIdentifier, genericCertIdentifier);
};
}
return _cached_decoder_for_CertificateIdentifier(el);
}
let _cached_encoder_for_CertificateIdentifier = null;
/**
* @summary Encodes a(n) CertificateIdentifier 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 CertificateIdentifier, encoded as an ASN.1 Element.
*/
export function _encode_CertificateIdentifier(value, elGetter) {
if (!_cached_encoder_for_CertificateIdentifier) {
_cached_encoder_for_CertificateIdentifier = function (value) {
return $._encodeSequence([].concat([
/* IF_ABSENT */ ((value.attributeCertIdentifier === undefined) ? undefined : $._encode_implicit(_TagClass.context, 0, () => _encode_AttributeCertificateIdentifier, $.DER)(value.attributeCertIdentifier, $.DER)),
/* IF_ABSENT */ ((value.genericCertIdentifier === undefined) ? undefined : $._encode_implicit(_TagClass.context, 1, () => _encode_IssuerSerial, $.DER)(value.genericCertIdentifier, $.DER))
]).filter((c) => (!!c)), $.DER);
};
}
return _cached_encoder_for_CertificateIdentifier(value, elGetter);
}
/* eslint-enable */