UNPKG

@wildboar/ocsp

Version:
134 lines (133 loc) 4.54 kB
/* eslint-disable */ import { ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _decode_Signature, _encode_Signature, } from "../OCSP-2013-08/Signature.ta.mjs"; import { _decode_TBSRequest, _encode_TBSRequest, } from "../OCSP-2013-08/TBSRequest.ta.mjs"; /** * @summary OCSPRequest * @description * * ### ASN.1 Definition: * * ```asn1 * OCSPRequest ::= SEQUENCE { * tbsRequest TBSRequest, * optionalSignature [0] EXPLICIT Signature OPTIONAL } * ``` * */ export class OCSPRequest { tbsRequest; optionalSignature; constructor( /** * @summary `tbsRequest`. * @public * @readonly */ tbsRequest, /** * @summary `optionalSignature`. * @public * @readonly */ optionalSignature) { this.tbsRequest = tbsRequest; this.optionalSignature = optionalSignature; } /** * @summary Restructures an object into a OCSPRequest * @description * * This takes an `object` and converts it to a `OCSPRequest`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `OCSPRequest`. * @returns {OCSPRequest} */ static _from_object(_o) { return new OCSPRequest(_o.tbsRequest, _o.optionalSignature); } } /** * @summary The Leading Root Component Types of OCSPRequest * @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_OCSPRequest = [ new $.ComponentSpec("tbsRequest", false, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("optionalSignature", true, $.hasTag(_TagClass.context, 0)), ]; /** * @summary The Trailing Root Component Types of OCSPRequest * @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_OCSPRequest = []; /** * @summary The Extension Addition Component Types of OCSPRequest * @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_OCSPRequest = []; let _cached_decoder_for_OCSPRequest = null; /** * @summary Decodes an ASN.1 element into a(n) OCSPRequest * @function * @param {_Element} el The element being decoded. * @returns {OCSPRequest} The decoded data structure. */ export function _decode_OCSPRequest(el) { if (!_cached_decoder_for_OCSPRequest) { _cached_decoder_for_OCSPRequest = function (el) { let tbsRequest; let optionalSignature; const callbacks = { tbsRequest: (_el) => { tbsRequest = _decode_TBSRequest(_el); }, optionalSignature: (_el) => { optionalSignature = $._decode_explicit(() => _decode_Signature)(_el); }, }; $._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_OCSPRequest, _extension_additions_list_spec_for_OCSPRequest, _root_component_type_list_2_spec_for_OCSPRequest, undefined); return new OCSPRequest(tbsRequest, optionalSignature); }; } return _cached_decoder_for_OCSPRequest(el); } let _cached_encoder_for_OCSPRequest = null; /** * @summary Encodes a(n) OCSPRequest 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 OCSPRequest, encoded as an ASN.1 Element. */ export function _encode_OCSPRequest(value, elGetter) { if (!_cached_encoder_for_OCSPRequest) { _cached_encoder_for_OCSPRequest = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ _encode_TBSRequest(value.tbsRequest, $.DER), /* IF_ABSENT */ value.optionalSignature === undefined ? undefined : $._encode_explicit(_TagClass.context, 0, () => _encode_Signature, $.DER)(value.optionalSignature, $.DER), ]) .filter((c) => !!c), $.DER); }; } return _cached_encoder_for_OCSPRequest(value, elGetter); } /* eslint-enable */