@wildboar/ocsp
Version:
Online Certificate Status Protocol PDUs in TypeScript
195 lines (194 loc) • 7.02 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_Extensions, _encode_Extensions, } from "@wildboar/pki-stub";
import { _decode_ResponderID, _encode_ResponderID, } from "../OCSP-2013-08/ResponderID.ta.mjs";
import { _decode_SingleResponse, _encode_SingleResponse, } from "../OCSP-2013-08/SingleResponse.ta.mjs";
import { v1 /* IMPORTED_SHORT_NAMED_INTEGER */, _decode_Version, _encode_Version, } from "../OCSP-2013-08/Version.ta.mjs";
/**
* @summary ResponseData
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* ResponseData ::= SEQUENCE {
* version [0] EXPLICIT Version DEFAULT v1,
* responderID ResponderID,
* producedAt GeneralizedTime,
* responses SEQUENCE OF SingleResponse,
* responseExtensions [1] EXPLICIT Extensions
* {{re-ocsp-nonce, ...,
* re-ocsp-extended-revoke}} OPTIONAL }
* ```
*
*/
export class ResponseData {
version;
responderID;
producedAt;
responses;
responseExtensions;
constructor(
/**
* @summary `version`.
* @public
* @readonly
*/
version,
/**
* @summary `responderID`.
* @public
* @readonly
*/
responderID,
/**
* @summary `producedAt`.
* @public
* @readonly
*/
producedAt,
/**
* @summary `responses`.
* @public
* @readonly
*/
responses,
/**
* @summary `responseExtensions`.
* @public
* @readonly
*/
responseExtensions) {
this.version = version;
this.responderID = responderID;
this.producedAt = producedAt;
this.responses = responses;
this.responseExtensions = responseExtensions;
}
/**
* @summary Restructures an object into a ResponseData
* @description
*
* This takes an `object` and converts it to a `ResponseData`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `ResponseData`.
* @returns {ResponseData}
*/
static _from_object(_o) {
return new ResponseData(_o.version, _o.responderID, _o.producedAt, _o.responses, _o.responseExtensions);
}
/**
* @summary Getter that returns the default value for `version`.
* @public
* @static
* @method
*/
static get _default_value_for_version() {
return v1;
}
}
/**
* @summary The Leading Root Component Types of ResponseData
* @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_ResponseData = [
new $.ComponentSpec("version", true, $.hasTag(_TagClass.context, 0)),
new $.ComponentSpec("responderID", false, $.hasAnyTag),
new $.ComponentSpec("producedAt", false, $.hasTag(_TagClass.universal, 24)),
new $.ComponentSpec("responses", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("responseExtensions", true, $.hasTag(_TagClass.context, 1)),
];
/**
* @summary The Trailing Root Component Types of ResponseData
* @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_ResponseData = [];
/**
* @summary The Extension Addition Component Types of ResponseData
* @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_ResponseData = [];
let _cached_decoder_for_ResponseData = null;
/**
* @summary Decodes an ASN.1 element into a(n) ResponseData
* @function
* @param {_Element} el The element being decoded.
* @returns {ResponseData} The decoded data structure.
*/
export function _decode_ResponseData(el) {
if (!_cached_decoder_for_ResponseData) {
_cached_decoder_for_ResponseData = function (el) {
let version = ResponseData._default_value_for_version;
let responderID;
let producedAt;
let responses;
let responseExtensions;
const callbacks = {
version: (_el) => {
version = $._decode_explicit(() => _decode_Version)(_el);
},
responderID: (_el) => {
responderID = _decode_ResponderID(_el);
},
producedAt: (_el) => {
producedAt = $._decodeGeneralizedTime(_el);
},
responses: (_el) => {
responses = $._decodeSequenceOf(() => _decode_SingleResponse)(_el);
},
responseExtensions: (_el) => {
responseExtensions = $._decode_explicit(() => _decode_Extensions)(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_ResponseData, _extension_additions_list_spec_for_ResponseData, _root_component_type_list_2_spec_for_ResponseData, undefined);
return new ResponseData(version, responderID, producedAt, responses, responseExtensions);
};
}
return _cached_decoder_for_ResponseData(el);
}
let _cached_encoder_for_ResponseData = null;
/**
* @summary Encodes a(n) ResponseData 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 ResponseData, encoded as an ASN.1 Element.
*/
export function _encode_ResponseData(value, elGetter) {
if (!_cached_encoder_for_ResponseData) {
_cached_encoder_for_ResponseData = function (value) {
return $._encodeSequence([]
.concat([
/* IF_DEFAULT */ value.version === undefined ||
$.deepEq(value.version, ResponseData._default_value_for_version)
? undefined
: $._encode_explicit(_TagClass.context, 0, () => _encode_Version, $.DER)(value.version, $.DER),
/* REQUIRED */ _encode_ResponderID(value.responderID, $.DER),
/* REQUIRED */ $._encodeGeneralizedTime(value.producedAt, $.DER),
/* REQUIRED */ $._encodeSequenceOf(() => _encode_SingleResponse, $.DER)(value.responses, $.DER),
/* IF_ABSENT */ value.responseExtensions === undefined
? undefined
: $._encode_explicit(_TagClass.context, 1, () => _encode_Extensions, $.DER)(value.responseExtensions, $.DER),
])
.filter((c) => !!c), $.DER);
};
}
return _cached_encoder_for_ResponseData(value, elGetter);
}
/* eslint-enable */