UNPKG

@wildboar/pkcs

Version:
148 lines (147 loc) 5.49 kB
/* eslint-disable */ import { ASN1ConstructionError as _ConstructionError, ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _decode_AlgorithmIdentifier, _encode_AlgorithmIdentifier, } from "../PKCS-10/AlgorithmIdentifier.ta.mjs"; import { _decode_CertificationRequestInfo, _encode_CertificationRequestInfo, } from "../PKCS-10/CertificationRequestInfo.ta.mjs"; /** * @summary CertificationRequest * @description * * ### ASN.1 Definition: * * ```asn1 * CertificationRequest ::= SEQUENCE { * certificationRequestInfo CertificationRequestInfo, * signatureAlgorithm AlgorithmIdentifier{{ SignatureAlgorithms }}, * signature BIT STRING * } * ``` * */ export class CertificationRequest { certificationRequestInfo; signatureAlgorithm; signature; constructor( /** * @summary `certificationRequestInfo`. * @public * @readonly */ certificationRequestInfo, /** * @summary `signatureAlgorithm`. * @public * @readonly */ signatureAlgorithm, /** * @summary `signature`. * @public * @readonly */ signature) { this.certificationRequestInfo = certificationRequestInfo; this.signatureAlgorithm = signatureAlgorithm; this.signature = signature; } /** * @summary Restructures an object into a CertificationRequest * @description * * This takes an `object` and converts it to a `CertificationRequest`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `CertificationRequest`. * @returns {CertificationRequest} */ static _from_object(_o) { return new CertificationRequest(_o.certificationRequestInfo, _o.signatureAlgorithm, _o.signature); } } /** * @summary The Leading Root Component Types of CertificationRequest * @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_CertificationRequest = [ new $.ComponentSpec("certificationRequestInfo", false, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("signatureAlgorithm", false, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("signature", false, $.hasTag(_TagClass.universal, 3)), ]; /** * @summary The Trailing Root Component Types of CertificationRequest * @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_CertificationRequest = []; /** * @summary The Extension Addition Component Types of CertificationRequest * @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_CertificationRequest = []; let _cached_decoder_for_CertificationRequest = null; /** * @summary Decodes an ASN.1 element into a(n) CertificationRequest * @function * @param {_Element} el The element being decoded. * @returns {CertificationRequest} The decoded data structure. */ export function _decode_CertificationRequest(el) { if (!_cached_decoder_for_CertificationRequest) { _cached_decoder_for_CertificationRequest = function (el) { const sequence = el.sequence; if (sequence.length < 3) { throw new _ConstructionError("CertificationRequest contained only " + sequence.length.toString() + " elements."); } sequence[0].name = "certificationRequestInfo"; sequence[1].name = "signatureAlgorithm"; sequence[2].name = "signature"; let certificationRequestInfo; let signatureAlgorithm; let signature; certificationRequestInfo = _decode_CertificationRequestInfo(sequence[0]); signatureAlgorithm = _decode_AlgorithmIdentifier(sequence[1]); signature = $._decodeBitString(sequence[2]); return new CertificationRequest(certificationRequestInfo, signatureAlgorithm, signature); }; } return _cached_decoder_for_CertificationRequest(el); } let _cached_encoder_for_CertificationRequest = null; /** * @summary Encodes a(n) CertificationRequest 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 CertificationRequest, encoded as an ASN.1 Element. */ export function _encode_CertificationRequest(value, elGetter) { if (!_cached_encoder_for_CertificationRequest) { _cached_encoder_for_CertificationRequest = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ _encode_CertificationRequestInfo(value.certificationRequestInfo, $.BER), /* REQUIRED */ _encode_AlgorithmIdentifier(value.signatureAlgorithm, $.BER), /* REQUIRED */ $._encodeBitString(value.signature, $.BER), ]) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_CertificationRequest(value, elGetter); } /* eslint-enable */