UNPKG

@wildboar/pkcs

Version:
185 lines (184 loc) 6.78 kB
/* eslint-disable */ import { ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _decode_Certificate, _encode_Certificate, } from "@wildboar/x500/AuthenticationFramework"; import { _decode_CertificateSerialNumber, _encode_CertificateSerialNumber, } from "@wildboar/x500/AuthenticationFramework"; import { _decode_Name, _encode_Name, } from "@wildboar/x500/InformationFramework"; import { _get_decoder_for_ObjectValue, _get_encoder_for_ObjectValue, } from "../PKCS-15/ObjectValue.ta.mjs"; /** * @summary X509CertificateAttributes * @description * * ### ASN.1 Definition: * * ```asn1 * X509CertificateAttributes ::= SEQUENCE { * value ObjectValue { Certificate }, * subject Name OPTIONAL, * issuer [0] Name OPTIONAL, * serialNumber CertificateSerialNumber OPTIONAL, * ... -- For future extensions * } * ``` * */ export class X509CertificateAttributes { value; subject; issuer; serialNumber; _unrecognizedExtensionsList; constructor( /** * @summary `value`. * @public * @readonly */ value, /** * @summary `subject`. * @public * @readonly */ subject, /** * @summary `issuer`. * @public * @readonly */ issuer, /** * @summary `serialNumber`. * @public * @readonly */ serialNumber, /** * @summary Extensions that are not recognized. * @public * @readonly */ _unrecognizedExtensionsList = []) { this.value = value; this.subject = subject; this.issuer = issuer; this.serialNumber = serialNumber; this._unrecognizedExtensionsList = _unrecognizedExtensionsList; } /** * @summary Restructures an object into a X509CertificateAttributes * @description * * This takes an `object` and converts it to a `X509CertificateAttributes`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `X509CertificateAttributes`. * @returns {X509CertificateAttributes} */ static _from_object(_o) { return new X509CertificateAttributes(_o.value, _o.subject, _o.issuer, _o.serialNumber, _o._unrecognizedExtensionsList); } } /** * @summary The Leading Root Component Types of X509CertificateAttributes * @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_X509CertificateAttributes = [ new $.ComponentSpec("value", false, $.hasAnyTag), new $.ComponentSpec("subject", true, $.hasAnyTag), new $.ComponentSpec("issuer", true, $.hasTag(_TagClass.context, 0)), new $.ComponentSpec("serialNumber", true, $.hasTag(_TagClass.universal, 2)), ]; /** * @summary The Trailing Root Component Types of X509CertificateAttributes * @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_X509CertificateAttributes = []; /** * @summary The Extension Addition Component Types of X509CertificateAttributes * @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_X509CertificateAttributes = []; let _cached_decoder_for_X509CertificateAttributes = null; /** * @summary Decodes an ASN.1 element into a(n) X509CertificateAttributes * @function * @param {_Element} el The element being decoded. * @returns {X509CertificateAttributes} The decoded data structure. */ export function _decode_X509CertificateAttributes(el) { if (!_cached_decoder_for_X509CertificateAttributes) { _cached_decoder_for_X509CertificateAttributes = function (el) { let value; let subject; let issuer; let serialNumber; let _unrecognizedExtensionsList = []; const callbacks = { value: (_el) => { value = _get_decoder_for_ObjectValue(_decode_Certificate)(_el); }, subject: (_el) => { subject = _decode_Name(_el); }, issuer: (_el) => { issuer = $._decode_explicit(() => _decode_Name)(_el); }, serialNumber: (_el) => { serialNumber = _decode_CertificateSerialNumber(_el); }, }; $._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_X509CertificateAttributes, _extension_additions_list_spec_for_X509CertificateAttributes, _root_component_type_list_2_spec_for_X509CertificateAttributes, (ext) => { _unrecognizedExtensionsList.push(ext); }); return new X509CertificateAttributes(value, subject, issuer, serialNumber, _unrecognizedExtensionsList); }; } return _cached_decoder_for_X509CertificateAttributes(el); } let _cached_encoder_for_X509CertificateAttributes = null; /** * @summary Encodes a(n) X509CertificateAttributes 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 X509CertificateAttributes, encoded as an ASN.1 Element. */ export function _encode_X509CertificateAttributes(value, elGetter) { if (!_cached_encoder_for_X509CertificateAttributes) { _cached_encoder_for_X509CertificateAttributes = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ _get_encoder_for_ObjectValue(_encode_Certificate)(value.value, $.BER), /* IF_ABSENT */ value.subject === undefined ? undefined : _encode_Name(value.subject, $.BER), /* IF_ABSENT */ value.issuer === undefined ? undefined : $._encode_explicit(_TagClass.context, 0, () => _encode_Name, $.BER)(value.issuer, $.BER), /* IF_ABSENT */ value.serialNumber === undefined ? undefined : _encode_CertificateSerialNumber(value.serialNumber, $.BER), ], value._unrecognizedExtensionsList ? value._unrecognizedExtensionsList : []) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_X509CertificateAttributes(value, elGetter); } /* eslint-enable */