@wildboar/ocsp
Version:
Online Certificate Status Protocol PDUs in TypeScript
166 lines (165 loc) • 6.08 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_AlgorithmIdentifier, _encode_AlgorithmIdentifier, _decode_Certificate, _encode_Certificate, } from "@wildboar/x500/AuthenticationFramework";
import { _decode_ResponseData, _encode_ResponseData, } from "../OCSP-2013-08/ResponseData.ta.mjs";
/**
* @summary BasicOCSPResponse
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* BasicOCSPResponse ::= SEQUENCE {
* tbsResponseData ResponseData,
* signatureAlgorithm AlgorithmIdentifier{SIGNATURE-ALGORITHM,
* {sa-dsaWithSHA1 | sa-rsaWithSHA1 |
* sa-rsaWithMD5 | sa-rsaWithMD2, ...}},
* signature BIT STRING,
* certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }
* ```
*
*/
export class BasicOCSPResponse {
tbsResponseData;
signatureAlgorithm;
signature;
certs;
constructor(
/**
* @summary `tbsResponseData`.
* @public
* @readonly
*/
tbsResponseData,
/**
* @summary `signatureAlgorithm`.
* @public
* @readonly
*/
signatureAlgorithm,
/**
* @summary `signature`.
* @public
* @readonly
*/
signature,
/**
* @summary `certs`.
* @public
* @readonly
*/
certs) {
this.tbsResponseData = tbsResponseData;
this.signatureAlgorithm = signatureAlgorithm;
this.signature = signature;
this.certs = certs;
}
/**
* @summary Restructures an object into a BasicOCSPResponse
* @description
*
* This takes an `object` and converts it to a `BasicOCSPResponse`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `BasicOCSPResponse`.
* @returns {BasicOCSPResponse}
*/
static _from_object(_o) {
return new BasicOCSPResponse(_o.tbsResponseData, _o.signatureAlgorithm, _o.signature, _o.certs);
}
}
/**
* @summary The Leading Root Component Types of BasicOCSPResponse
* @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_BasicOCSPResponse = [
new $.ComponentSpec("tbsResponseData", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("signatureAlgorithm", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("signature", false, $.hasTag(_TagClass.universal, 3)),
new $.ComponentSpec("certs", true, $.hasTag(_TagClass.context, 0)),
];
/**
* @summary The Trailing Root Component Types of BasicOCSPResponse
* @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_BasicOCSPResponse = [];
/**
* @summary The Extension Addition Component Types of BasicOCSPResponse
* @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_BasicOCSPResponse = [];
let _cached_decoder_for_BasicOCSPResponse = null;
/**
* @summary Decodes an ASN.1 element into a(n) BasicOCSPResponse
* @function
* @param {_Element} el The element being decoded.
* @returns {BasicOCSPResponse} The decoded data structure.
*/
export function _decode_BasicOCSPResponse(el) {
if (!_cached_decoder_for_BasicOCSPResponse) {
_cached_decoder_for_BasicOCSPResponse = function (el) {
let tbsResponseData;
let signatureAlgorithm;
let signature;
let certs;
const callbacks = {
tbsResponseData: (_el) => {
tbsResponseData = _decode_ResponseData(_el);
},
signatureAlgorithm: (_el) => {
signatureAlgorithm = _decode_AlgorithmIdentifier(_el);
},
signature: (_el) => {
signature = $._decodeBitString(_el);
},
certs: (_el) => {
certs = $._decode_explicit(() => $._decodeSequenceOf(() => _decode_Certificate))(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_BasicOCSPResponse, _extension_additions_list_spec_for_BasicOCSPResponse, _root_component_type_list_2_spec_for_BasicOCSPResponse, undefined);
return new BasicOCSPResponse(tbsResponseData, signatureAlgorithm, signature, certs);
};
}
return _cached_decoder_for_BasicOCSPResponse(el);
}
let _cached_encoder_for_BasicOCSPResponse = null;
/**
* @summary Encodes a(n) BasicOCSPResponse 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 BasicOCSPResponse, encoded as an ASN.1 Element.
*/
export function _encode_BasicOCSPResponse(value, elGetter) {
if (!_cached_encoder_for_BasicOCSPResponse) {
_cached_encoder_for_BasicOCSPResponse = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ _encode_ResponseData(value.tbsResponseData, $.DER),
/* REQUIRED */ _encode_AlgorithmIdentifier(value.signatureAlgorithm, $.DER),
/* REQUIRED */ $._encodeBitString(value.signature, $.DER),
/* IF_ABSENT */ value.certs === undefined
? undefined
: $._encode_explicit(_TagClass.context, 0, () => $._encodeSequenceOf(() => _encode_Certificate, $.DER), $.DER)(value.certs, $.DER),
])
.filter((c) => !!c), $.DER);
};
}
return _cached_encoder_for_BasicOCSPResponse(value, elGetter);
}
/* eslint-enable */