UNPKG

@wildboar/pc

Version:

Trusted Computing Group Platform Certificate ASN.1 data structures in TypeScript

128 lines (127 loc) 4.95 kB
/* eslint-disable */ import { ASN1TagClass as _TagClass, ASN1ConstructionError as _ConstructionError, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _decode_AlgorithmIdentifier, _encode_AlgorithmIdentifier } from "@wildboar/x500/AuthenticationFramework"; /** * @summary AttributeCertificateIdentifier * @description * * ### ASN.1 Definition: * * ```asn1 * AttributeCertificateIdentifier ::= SEQUENCE { * hashAlgorithm AlgorithmIdentifier, * hashOverSignatureValue OCTET STRING } * ``` * */ export class AttributeCertificateIdentifier { hashAlgorithm; hashOverSignatureValue; constructor( /** * @summary `hashAlgorithm`. * @public * @readonly */ hashAlgorithm, /** * @summary `hashOverSignatureValue`. * @public * @readonly */ hashOverSignatureValue) { this.hashAlgorithm = hashAlgorithm; this.hashOverSignatureValue = hashOverSignatureValue; } /** * @summary Restructures an object into a AttributeCertificateIdentifier * @description * * This takes an `object` and converts it to a `AttributeCertificateIdentifier`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `AttributeCertificateIdentifier`. * @returns {AttributeCertificateIdentifier} */ static _from_object(_o) { return new AttributeCertificateIdentifier(_o.hashAlgorithm, _o.hashOverSignatureValue); } } /** * @summary The Leading Root Component Types of AttributeCertificateIdentifier * @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_AttributeCertificateIdentifier = [ new $.ComponentSpec("hashAlgorithm", false, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("hashOverSignatureValue", false, $.hasTag(_TagClass.universal, 4)) ]; /** * @summary The Trailing Root Component Types of AttributeCertificateIdentifier * @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_AttributeCertificateIdentifier = []; /** * @summary The Extension Addition Component Types of AttributeCertificateIdentifier * @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_AttributeCertificateIdentifier = []; let _cached_decoder_for_AttributeCertificateIdentifier = null; /** * @summary Decodes an ASN.1 element into a(n) AttributeCertificateIdentifier * @function * @param {_Element} el The element being decoded. * @returns {AttributeCertificateIdentifier} The decoded data structure. */ export function _decode_AttributeCertificateIdentifier(el) { if (!_cached_decoder_for_AttributeCertificateIdentifier) { _cached_decoder_for_AttributeCertificateIdentifier = function (el) { const sequence = el.sequence; if (sequence.length < 2) { throw new _ConstructionError("AttributeCertificateIdentifier contained only " + sequence.length.toString() + " elements."); } sequence[0].name = "hashAlgorithm"; sequence[1].name = "hashOverSignatureValue"; let hashAlgorithm; let hashOverSignatureValue; hashAlgorithm = _decode_AlgorithmIdentifier(sequence[0]); hashOverSignatureValue = $._decodeOctetString(sequence[1]); return new AttributeCertificateIdentifier(hashAlgorithm, hashOverSignatureValue); }; } return _cached_decoder_for_AttributeCertificateIdentifier(el); } let _cached_encoder_for_AttributeCertificateIdentifier = null; /** * @summary Encodes a(n) AttributeCertificateIdentifier 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 AttributeCertificateIdentifier, encoded as an ASN.1 Element. */ export function _encode_AttributeCertificateIdentifier(value, elGetter) { if (!_cached_encoder_for_AttributeCertificateIdentifier) { _cached_encoder_for_AttributeCertificateIdentifier = function (value) { return $._encodeSequence([].concat([ /* REQUIRED */ _encode_AlgorithmIdentifier(value.hashAlgorithm, $.DER), /* REQUIRED */ $._encodeOctetString(value.hashOverSignatureValue, $.DER) ]).filter((c) => (!!c)), $.DER); }; } return _cached_encoder_for_AttributeCertificateIdentifier(value, elGetter); } /* eslint-enable */