@wildboar/pc
Version:
Trusted Computing Group Platform Certificate ASN.1 data structures in TypeScript
128 lines (127 loc) • 4.34 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, ASN1ConstructionError as _ConstructionError, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_AddressType, _encode_AddressType } from "../PlatformCertificateProfile/AddressType.ta.mjs";
/**
* @summary ComponentAddress
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* ComponentAddress ::= SEQUENCE {
* addressType AddressType,
* addressValue UTF8String (SIZE (1..strmax)) }
* ```
*
*/
export class ComponentAddress {
addressType;
addressValue;
constructor(
/**
* @summary `addressType`.
* @public
* @readonly
*/
addressType,
/**
* @summary `addressValue`.
* @public
* @readonly
*/
addressValue) {
this.addressType = addressType;
this.addressValue = addressValue;
}
/**
* @summary Restructures an object into a ComponentAddress
* @description
*
* This takes an `object` and converts it to a `ComponentAddress`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `ComponentAddress`.
* @returns {ComponentAddress}
*/
static _from_object(_o) {
return new ComponentAddress(_o.addressType, _o.addressValue);
}
}
/**
* @summary The Leading Root Component Types of ComponentAddress
* @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_ComponentAddress = [
new $.ComponentSpec("addressType", false, $.hasTag(_TagClass.universal, 6)),
new $.ComponentSpec("addressValue", false, $.hasTag(_TagClass.universal, 12))
];
/**
* @summary The Trailing Root Component Types of ComponentAddress
* @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_ComponentAddress = [];
/**
* @summary The Extension Addition Component Types of ComponentAddress
* @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_ComponentAddress = [];
let _cached_decoder_for_ComponentAddress = null;
/**
* @summary Decodes an ASN.1 element into a(n) ComponentAddress
* @function
* @param {_Element} el The element being decoded.
* @returns {ComponentAddress} The decoded data structure.
*/
export function _decode_ComponentAddress(el) {
if (!_cached_decoder_for_ComponentAddress) {
_cached_decoder_for_ComponentAddress = function (el) {
const sequence = el.sequence;
if (sequence.length < 2) {
throw new _ConstructionError("ComponentAddress contained only " + sequence.length.toString() + " elements.");
}
sequence[0].name = "addressType";
sequence[1].name = "addressValue";
let addressType;
let addressValue;
addressType = _decode_AddressType(sequence[0]);
addressValue = $._decodeUTF8String(sequence[1]);
return new ComponentAddress(addressType, addressValue);
};
}
return _cached_decoder_for_ComponentAddress(el);
}
let _cached_encoder_for_ComponentAddress = null;
/**
* @summary Encodes a(n) ComponentAddress 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 ComponentAddress, encoded as an ASN.1 Element.
*/
export function _encode_ComponentAddress(value, elGetter) {
if (!_cached_encoder_for_ComponentAddress) {
_cached_encoder_for_ComponentAddress = function (value) {
return $._encodeSequence([].concat([
/* REQUIRED */ _encode_AddressType(value.addressType, $.DER),
/* REQUIRED */ $._encodeUTF8String(value.addressValue, $.DER)
]).filter((c) => (!!c)), $.DER);
};
}
return _cached_encoder_for_ComponentAddress(value, elGetter);
}
/* eslint-enable */