@wildboar/pc
Version:
Trusted Computing Group Platform Certificate ASN.1 data structures in TypeScript
151 lines (150 loc) • 4.92 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _enum_for_SecurityLevel, _decode_SecurityLevel, _encode_SecurityLevel } from "../PlatformCertificateProfile/SecurityLevel.ta.mjs";
/**
* @summary FIPSLevel
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* FIPSLevel ::= SEQUENCE {
* version IA5String (SIZE (1..strmax)), -- “140-1”, “140-2”, or “140-3”
* level SecurityLevel,
* plus BOOLEAN DEFAULT FALSE }
* ```
*
*/
export class FIPSLevel {
version;
level;
plus;
constructor(
/**
* @summary `version`.
* @public
* @readonly
*/
version,
/**
* @summary `level`.
* @public
* @readonly
*/
level,
/**
* @summary `plus`.
* @public
* @readonly
*/
plus) {
this.version = version;
this.level = level;
this.plus = plus;
}
/**
* @summary Restructures an object into a FIPSLevel
* @description
*
* This takes an `object` and converts it to a `FIPSLevel`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `FIPSLevel`.
* @returns {FIPSLevel}
*/
static _from_object(_o) {
return new FIPSLevel(_o.version, _o.level, _o.plus);
}
/**
* @summary Getter that returns the default value for `plus`.
* @public
* @static
* @method
*/
static get _default_value_for_plus() { return false; }
/**
* @summary The enum used as the type of the component `level`
* @public
* @static
*/
static _enum_for_level = _enum_for_SecurityLevel;
}
/**
* @summary The Leading Root Component Types of FIPSLevel
* @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_FIPSLevel = [
new $.ComponentSpec("version", false, $.hasTag(_TagClass.universal, 22)),
new $.ComponentSpec("level", false, $.hasTag(_TagClass.universal, 10)),
new $.ComponentSpec("plus", true, $.hasTag(_TagClass.universal, 1))
];
/**
* @summary The Trailing Root Component Types of FIPSLevel
* @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_FIPSLevel = [];
/**
* @summary The Extension Addition Component Types of FIPSLevel
* @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_FIPSLevel = [];
let _cached_decoder_for_FIPSLevel = null;
/**
* @summary Decodes an ASN.1 element into a(n) FIPSLevel
* @function
* @param {_Element} el The element being decoded.
* @returns {FIPSLevel} The decoded data structure.
*/
export function _decode_FIPSLevel(el) {
if (!_cached_decoder_for_FIPSLevel) {
_cached_decoder_for_FIPSLevel = function (el) {
let version;
let level;
let plus = FIPSLevel._default_value_for_plus;
const callbacks = {
"version": (_el) => { version = $._decodeIA5String(_el); },
"level": (_el) => { level = _decode_SecurityLevel(_el); },
"plus": (_el) => { plus = $._decodeBoolean(_el); }
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_FIPSLevel, _extension_additions_list_spec_for_FIPSLevel, _root_component_type_list_2_spec_for_FIPSLevel, undefined);
return new FIPSLevel(version, level, plus);
};
}
return _cached_decoder_for_FIPSLevel(el);
}
let _cached_encoder_for_FIPSLevel = null;
/**
* @summary Encodes a(n) FIPSLevel 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 FIPSLevel, encoded as an ASN.1 Element.
*/
export function _encode_FIPSLevel(value, elGetter) {
if (!_cached_encoder_for_FIPSLevel) {
_cached_encoder_for_FIPSLevel = function (value) {
return $._encodeSequence([].concat([
/* REQUIRED */ $._encodeIA5String(value.version, $.DER),
/* REQUIRED */ _encode_SecurityLevel(value.level, $.DER),
/* IF_DEFAULT */ (value.plus === undefined || $.deepEq(value.plus, FIPSLevel._default_value_for_plus) ? undefined : $._encodeBoolean(value.plus, $.DER))
]).filter((c) => (!!c)), $.DER);
};
}
return _cached_encoder_for_FIPSLevel(value, elGetter);
}
/* eslint-enable */