@wildboar/ocsp
Version:
Online Certificate Status Protocol PDUs in TypeScript
140 lines (139 loc) • 4.86 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_OCSPResponseStatus, _encode_OCSPResponseStatus, _enum_for_OCSPResponseStatus, } from "../OCSP-2013-08/OCSPResponseStatus.ta.mjs";
import { _decode_ResponseBytes, _encode_ResponseBytes, } from "../OCSP-2013-08/ResponseBytes.ta.mjs";
/**
* @summary OCSPResponse
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* OCSPResponse ::= SEQUENCE {
* responseStatus OCSPResponseStatus,
* responseBytes [0] EXPLICIT ResponseBytes OPTIONAL }
* ```
*
*/
export class OCSPResponse {
responseStatus;
responseBytes;
constructor(
/**
* @summary `responseStatus`.
* @public
* @readonly
*/
responseStatus,
/**
* @summary `responseBytes`.
* @public
* @readonly
*/
responseBytes) {
this.responseStatus = responseStatus;
this.responseBytes = responseBytes;
}
/**
* @summary Restructures an object into a OCSPResponse
* @description
*
* This takes an `object` and converts it to a `OCSPResponse`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `OCSPResponse`.
* @returns {OCSPResponse}
*/
static _from_object(_o) {
return new OCSPResponse(_o.responseStatus, _o.responseBytes);
}
/**
* @summary The enum used as the type of the component `responseStatus`
* @public
* @static
*/
static _enum_for_responseStatus = _enum_for_OCSPResponseStatus;
}
/**
* @summary The Leading Root Component Types of OCSPResponse
* @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_OCSPResponse = [
new $.ComponentSpec("responseStatus", false, $.hasTag(_TagClass.universal, 10)),
new $.ComponentSpec("responseBytes", true, $.hasTag(_TagClass.context, 0)),
];
/**
* @summary The Trailing Root Component Types of OCSPResponse
* @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_OCSPResponse = [];
/**
* @summary The Extension Addition Component Types of OCSPResponse
* @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_OCSPResponse = [];
let _cached_decoder_for_OCSPResponse = null;
/**
* @summary Decodes an ASN.1 element into a(n) OCSPResponse
* @function
* @param {_Element} el The element being decoded.
* @returns {OCSPResponse} The decoded data structure.
*/
export function _decode_OCSPResponse(el) {
if (!_cached_decoder_for_OCSPResponse) {
_cached_decoder_for_OCSPResponse = function (el) {
let responseStatus;
let responseBytes;
const callbacks = {
responseStatus: (_el) => {
responseStatus = _decode_OCSPResponseStatus(_el);
},
responseBytes: (_el) => {
responseBytes = $._decode_explicit(() => _decode_ResponseBytes)(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_OCSPResponse, _extension_additions_list_spec_for_OCSPResponse, _root_component_type_list_2_spec_for_OCSPResponse, undefined);
return new OCSPResponse(responseStatus, responseBytes);
};
}
return _cached_decoder_for_OCSPResponse(el);
}
let _cached_encoder_for_OCSPResponse = null;
/**
* @summary Encodes a(n) OCSPResponse 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 OCSPResponse, encoded as an ASN.1 Element.
*/
export function _encode_OCSPResponse(value, elGetter) {
if (!_cached_encoder_for_OCSPResponse) {
_cached_encoder_for_OCSPResponse = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ _encode_OCSPResponseStatus(value.responseStatus, $.DER),
/* IF_ABSENT */ value.responseBytes === undefined
? undefined
: $._encode_explicit(_TagClass.context, 0, () => _encode_ResponseBytes, $.DER)(value.responseBytes, $.DER),
])
.filter((c) => !!c), $.DER);
};
}
return _cached_encoder_for_OCSPResponse(value, elGetter);
}
/* eslint-enable */