@wildboar/ocsp
Version:
Online Certificate Status Protocol PDUs in TypeScript
150 lines (149 loc) • 5.07 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_AlgorithmIdentifier, _encode_AlgorithmIdentifier, } from "@wildboar/pki-stub";
import { _decode_Certificate, _encode_Certificate, } from "@wildboar/pki-stub";
/**
* @summary Signature
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* Signature ::= SEQUENCE {
* signatureAlgorithm AlgorithmIdentifier
* { SIGNATURE-ALGORITHM, {...}},
* signature BIT STRING,
* certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }
* ```
*
*/
export class Signature {
signatureAlgorithm;
signature;
certs;
constructor(
/**
* @summary `signatureAlgorithm`.
* @public
* @readonly
*/
signatureAlgorithm,
/**
* @summary `signature`.
* @public
* @readonly
*/
signature,
/**
* @summary `certs`.
* @public
* @readonly
*/
certs) {
this.signatureAlgorithm = signatureAlgorithm;
this.signature = signature;
this.certs = certs;
}
/**
* @summary Restructures an object into a Signature
* @description
*
* This takes an `object` and converts it to a `Signature`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `Signature`.
* @returns {Signature}
*/
static _from_object(_o) {
return new Signature(_o.signatureAlgorithm, _o.signature, _o.certs);
}
}
/**
* @summary The Leading Root Component Types of Signature
* @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_Signature = [
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 Signature
* @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_Signature = [];
/**
* @summary The Extension Addition Component Types of Signature
* @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_Signature = [];
let _cached_decoder_for_Signature = null;
/**
* @summary Decodes an ASN.1 element into a(n) Signature
* @function
* @param {_Element} el The element being decoded.
* @returns {Signature} The decoded data structure.
*/
export function _decode_Signature(el) {
if (!_cached_decoder_for_Signature) {
_cached_decoder_for_Signature = function (el) {
let signatureAlgorithm;
let signature;
let certs;
const callbacks = {
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_Signature, _extension_additions_list_spec_for_Signature, _root_component_type_list_2_spec_for_Signature, undefined);
return new Signature(signatureAlgorithm, signature, certs);
};
}
return _cached_decoder_for_Signature(el);
}
let _cached_encoder_for_Signature = null;
/**
* @summary Encodes a(n) Signature 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 Signature, encoded as an ASN.1 Element.
*/
export function _encode_Signature(value, elGetter) {
if (!_cached_encoder_for_Signature) {
_cached_encoder_for_Signature = function (value) {
return $._encodeSequence([]
.concat([
/* 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_Signature(value, elGetter);
}
/* eslint-enable */