@wildboar/pc
Version:
Trusted Computing Group Platform Certificate ASN.1 data structures in TypeScript
138 lines (137 loc) • 5 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_AlgorithmIdentifier, _encode_AlgorithmIdentifier, } from "@wildboar/x500/AuthenticationFramework";
/**
* @summary URIReference
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* URIReference ::= SEQUENCE {
* uniformResourceIdentifier IA5String (SIZE (1..urimax)),
* hashAlgorithm AlgorithmIdentifier OPTIONAL,
* hashValue BIT STRING OPTIONAL }
* ```
*
*/
export class URIReference {
uniformResourceIdentifier;
hashAlgorithm;
hashValue;
constructor(
/**
* @summary `uniformResourceIdentifier`.
* @public
* @readonly
*/
uniformResourceIdentifier,
/**
* @summary `hashAlgorithm`.
* @public
* @readonly
*/
hashAlgorithm,
/**
* @summary `hashValue`.
* @public
* @readonly
*/
hashValue) {
this.uniformResourceIdentifier = uniformResourceIdentifier;
this.hashAlgorithm = hashAlgorithm;
this.hashValue = hashValue;
}
/**
* @summary Restructures an object into a URIReference
* @description
*
* This takes an `object` and converts it to a `URIReference`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `URIReference`.
* @returns {URIReference}
*/
static _from_object(_o) {
return new URIReference(_o.uniformResourceIdentifier, _o.hashAlgorithm, _o.hashValue);
}
}
/**
* @summary The Leading Root Component Types of URIReference
* @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_URIReference = [
new $.ComponentSpec("uniformResourceIdentifier", false, $.hasTag(_TagClass.universal, 22)),
new $.ComponentSpec("hashAlgorithm", true, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("hashValue", true, $.hasTag(_TagClass.universal, 3))
];
/**
* @summary The Trailing Root Component Types of URIReference
* @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_URIReference = [];
/**
* @summary The Extension Addition Component Types of URIReference
* @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_URIReference = [];
let _cached_decoder_for_URIReference = null;
/**
* @summary Decodes an ASN.1 element into a(n) URIReference
* @function
* @param {_Element} el The element being decoded.
* @returns {URIReference} The decoded data structure.
*/
export function _decode_URIReference(el) {
if (!_cached_decoder_for_URIReference) {
_cached_decoder_for_URIReference = function (el) {
let uniformResourceIdentifier;
let hashAlgorithm;
let hashValue;
const callbacks = {
"uniformResourceIdentifier": (_el) => { uniformResourceIdentifier = $._decodeIA5String(_el); },
"hashAlgorithm": (_el) => { hashAlgorithm = _decode_AlgorithmIdentifier(_el); },
"hashValue": (_el) => { hashValue = $._decodeBitString(_el); }
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_URIReference, _extension_additions_list_spec_for_URIReference, _root_component_type_list_2_spec_for_URIReference, undefined);
return new URIReference(uniformResourceIdentifier, hashAlgorithm, hashValue);
};
}
return _cached_decoder_for_URIReference(el);
}
let _cached_encoder_for_URIReference = null;
/**
* @summary Encodes a(n) URIReference 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 URIReference, encoded as an ASN.1 Element.
*/
export function _encode_URIReference(value, elGetter) {
if (!_cached_encoder_for_URIReference) {
_cached_encoder_for_URIReference = function (value) {
return $._encodeSequence([].concat([
/* REQUIRED */ $._encodeIA5String(value.uniformResourceIdentifier, $.DER),
/* IF_ABSENT */ ((value.hashAlgorithm === undefined) ? undefined : _encode_AlgorithmIdentifier(value.hashAlgorithm, $.DER)),
/* IF_ABSENT */ ((value.hashValue === undefined) ? undefined : $._encodeBitString(value.hashValue, $.DER))
]).filter((c) => (!!c)), $.DER);
};
}
return _cached_encoder_for_URIReference(value, elGetter);
}
/* eslint-enable */