UNPKG

@wildboar/pkcs

Version:
164 lines (163 loc) 6.08 kB
/* eslint-disable */ import { ASN1ConstructionError as _ConstructionError, ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _decode_Name, _encode_Name, } from "@wildboar/x500/InformationFramework"; import { _decode_Attributes, _encode_Attributes, } from "../PKCS-10/Attributes.ta.mjs"; import { _decode_CertificationRequestInfo_version, _encode_CertificationRequestInfo_version, } from "../PKCS-10/CertificationRequestInfo-version.ta.mjs"; import { _decode_SubjectPublicKeyInfo, _encode_SubjectPublicKeyInfo, } from "../PKCS-10/SubjectPublicKeyInfo.ta.mjs"; /** * @summary CertificationRequestInfo * @description * * ### ASN.1 Definition: * * ```asn1 * CertificationRequestInfo ::= SEQUENCE { * version INTEGER { v1(0) } (v1,...), * subject Name, * subjectPKInfo SubjectPublicKeyInfo{{ PKInfoAlgorithms }}, * attributes [0] Attributes{{ CRIAttributes }} * } * ``` * */ export class CertificationRequestInfo { version; subject; subjectPKInfo; attributes; constructor( /** * @summary `version`. * @public * @readonly */ version, /** * @summary `subject`. * @public * @readonly */ subject, /** * @summary `subjectPKInfo`. * @public * @readonly */ subjectPKInfo, /** * @summary `attributes`. * @public * @readonly */ attributes) { this.version = version; this.subject = subject; this.subjectPKInfo = subjectPKInfo; this.attributes = attributes; } /** * @summary Restructures an object into a CertificationRequestInfo * @description * * This takes an `object` and converts it to a `CertificationRequestInfo`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `CertificationRequestInfo`. * @returns {CertificationRequestInfo} */ static _from_object(_o) { return new CertificationRequestInfo(_o.version, _o.subject, _o.subjectPKInfo, _o.attributes); } } /** * @summary The Leading Root Component Types of CertificationRequestInfo * @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_CertificationRequestInfo = [ new $.ComponentSpec("version", false, $.hasTag(_TagClass.universal, 2)), new $.ComponentSpec("subject", false, $.hasAnyTag), new $.ComponentSpec("subjectPKInfo", false, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("attributes", false, $.hasTag(_TagClass.context, 0)), ]; /** * @summary The Trailing Root Component Types of CertificationRequestInfo * @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_CertificationRequestInfo = []; /** * @summary The Extension Addition Component Types of CertificationRequestInfo * @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_CertificationRequestInfo = []; let _cached_decoder_for_CertificationRequestInfo = null; /** * @summary Decodes an ASN.1 element into a(n) CertificationRequestInfo * @function * @param {_Element} el The element being decoded. * @returns {CertificationRequestInfo} The decoded data structure. */ export function _decode_CertificationRequestInfo(el) { if (!_cached_decoder_for_CertificationRequestInfo) { _cached_decoder_for_CertificationRequestInfo = function (el) { const sequence = el.sequence; if (sequence.length < 4) { throw new _ConstructionError("CertificationRequestInfo contained only " + sequence.length.toString() + " elements."); } sequence[0].name = "version"; sequence[1].name = "subject"; sequence[2].name = "subjectPKInfo"; sequence[3].name = "attributes"; let version; let subject; let subjectPKInfo; let attributes; version = _decode_CertificationRequestInfo_version(sequence[0]); subject = _decode_Name(sequence[1]); subjectPKInfo = _decode_SubjectPublicKeyInfo(sequence[2]); attributes = $._decode_implicit(() => _decode_Attributes)(sequence[3]); return new CertificationRequestInfo(version, subject, subjectPKInfo, attributes); }; } return _cached_decoder_for_CertificationRequestInfo(el); } let _cached_encoder_for_CertificationRequestInfo = null; /** * @summary Encodes a(n) CertificationRequestInfo 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 CertificationRequestInfo, encoded as an ASN.1 Element. */ export function _encode_CertificationRequestInfo(value, elGetter) { if (!_cached_encoder_for_CertificationRequestInfo) { _cached_encoder_for_CertificationRequestInfo = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ _encode_CertificationRequestInfo_version(value.version, $.BER), /* REQUIRED */ _encode_Name(value.subject, $.BER), /* REQUIRED */ _encode_SubjectPublicKeyInfo(value.subjectPKInfo, $.BER), /* REQUIRED */ $._encode_implicit(_TagClass.context, 0, () => _encode_Attributes, $.BER)(value.attributes, $.BER), ]) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_CertificationRequestInfo(value, elGetter); } /* eslint-enable */