@wildboar/ocsp
Version:
Online Certificate Status Protocol PDUs in TypeScript
185 lines (184 loc) • 6.61 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_CertID, _encode_CertID, } from "../OCSP-2013-08/CertID.ta.mjs";
import { _decode_CertStatus, _encode_CertStatus, } from "../OCSP-2013-08/CertStatus.ta.mjs";
/**
* @summary SingleResponse
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* SingleResponse ::= SEQUENCE {
* certID CertID,
* certStatus CertStatus,
* thisUpdate GeneralizedTime,
* nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL,
* singleExtensions [1] EXPLICIT Extensions{{re-ocsp-crl |
* re-ocsp-archive-cutoff |
* CrlEntryExtensions, ...}
* } OPTIONAL }
* ```
*
*/
export class SingleResponse {
certID;
certStatus;
thisUpdate;
nextUpdate;
singleExtensions;
constructor(
/**
* @summary `certID`.
* @public
* @readonly
*/
certID,
/**
* @summary `certStatus`.
* @public
* @readonly
*/
certStatus,
/**
* @summary `thisUpdate`.
* @public
* @readonly
*/
thisUpdate,
/**
* @summary `nextUpdate`.
* @public
* @readonly
*/
nextUpdate,
/**
* @summary `singleExtensions`.
* @public
* @readonly
*/
singleExtensions) {
this.certID = certID;
this.certStatus = certStatus;
this.thisUpdate = thisUpdate;
this.nextUpdate = nextUpdate;
this.singleExtensions = singleExtensions;
}
/**
* @summary Restructures an object into a SingleResponse
* @description
*
* This takes an `object` and converts it to a `SingleResponse`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `SingleResponse`.
* @returns {SingleResponse}
*/
static _from_object(_o) {
return new SingleResponse(_o.certID, _o.certStatus, _o.thisUpdate, _o.nextUpdate, _o.singleExtensions);
}
}
/**
* @summary The Leading Root Component Types of SingleResponse
* @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_SingleResponse = [
new $.ComponentSpec("certID", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("certStatus", false, $.hasAnyTag),
new $.ComponentSpec("thisUpdate", false, $.hasTag(_TagClass.universal, 24)),
new $.ComponentSpec("nextUpdate", true, $.hasTag(_TagClass.context, 0)),
new $.ComponentSpec("singleExtensions", true, $.hasTag(_TagClass.context, 1)),
];
/**
* @summary The Trailing Root Component Types of SingleResponse
* @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_SingleResponse = [];
/**
* @summary The Extension Addition Component Types of SingleResponse
* @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_SingleResponse = [];
let _cached_decoder_for_SingleResponse = null;
/**
* @summary Decodes an ASN.1 element into a(n) SingleResponse
* @function
* @param {_Element} el The element being decoded.
* @returns {SingleResponse} The decoded data structure.
*/
export function _decode_SingleResponse(el) {
if (!_cached_decoder_for_SingleResponse) {
_cached_decoder_for_SingleResponse = function (el) {
let certID;
let certStatus;
let thisUpdate;
let nextUpdate;
let singleExtensions;
const callbacks = {
certID: (_el) => {
certID = _decode_CertID(_el);
},
certStatus: (_el) => {
certStatus = _decode_CertStatus(_el);
},
thisUpdate: (_el) => {
thisUpdate = $._decodeGeneralizedTime(_el);
},
nextUpdate: (_el) => {
nextUpdate = $._decode_explicit(() => $._decodeGeneralizedTime)(_el);
},
singleExtensions: (_el) => {
singleExtensions = $._decode_explicit(() => _decode_Extensions)(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_SingleResponse, _extension_additions_list_spec_for_SingleResponse, _root_component_type_list_2_spec_for_SingleResponse, undefined);
return new SingleResponse(certID, certStatus, thisUpdate, nextUpdate, singleExtensions);
};
}
return _cached_decoder_for_SingleResponse(el);
}
let _cached_encoder_for_SingleResponse = null;
/**
* @summary Encodes a(n) SingleResponse 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 SingleResponse, encoded as an ASN.1 Element.
*/
export function _encode_SingleResponse(value, elGetter) {
if (!_cached_encoder_for_SingleResponse) {
_cached_encoder_for_SingleResponse = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ _encode_CertID(value.certID, $.DER),
/* REQUIRED */ _encode_CertStatus(value.certStatus, $.DER),
/* REQUIRED */ $._encodeGeneralizedTime(value.thisUpdate, $.DER),
/* IF_ABSENT */ value.nextUpdate === undefined
? undefined
: $._encode_explicit(_TagClass.context, 0, () => $._encodeGeneralizedTime, $.DER)(value.nextUpdate, $.DER),
/* IF_ABSENT */ value.singleExtensions === undefined
? undefined
: $._encode_explicit(_TagClass.context, 1, () => _encode_Extensions, $.DER)(value.singleExtensions, $.DER),
])
.filter((c) => !!c), $.DER);
};
}
return _cached_encoder_for_SingleResponse(value, elGetter);
}
/* eslint-enable */