UNPKG

@wildboar/pkcs

Version:
185 lines (184 loc) 7.33 kB
/* eslint-disable */ import { ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _decode_AttributeCertificate, _encode_AttributeCertificate, } from "@wildboar/x500/AttributeCertificateDefinitions"; import { _decode_CertificateSerialNumber, _encode_CertificateSerialNumber, } from "@wildboar/x500/AuthenticationFramework"; import { _decode_GeneralNames, _encode_GeneralNames, } from "@wildboar/x500/CertificateExtensions"; import { _get_decoder_for_ObjectValue, _get_encoder_for_ObjectValue, } from "../PKCS-15/ObjectValue.ta.mjs"; /** * @summary X509AttributeCertificateAttributes * @description * * ### ASN.1 Definition: * * ```asn1 * X509AttributeCertificateAttributes ::= SEQUENCE { * value ObjectValue { AttributeCertificate }, * issuer GeneralNames OPTIONAL, * serialNumber CertificateSerialNumber OPTIONAL, * attrTypes [0] SEQUENCE OF OBJECT IDENTIFIER OPTIONAL, * ... -- For future extensions * } * ``` * */ export class X509AttributeCertificateAttributes { value; issuer; serialNumber; attrTypes; _unrecognizedExtensionsList; constructor( /** * @summary `value`. * @public * @readonly */ value, /** * @summary `issuer`. * @public * @readonly */ issuer, /** * @summary `serialNumber`. * @public * @readonly */ serialNumber, /** * @summary `attrTypes`. * @public * @readonly */ attrTypes, /** * @summary Extensions that are not recognized. * @public * @readonly */ _unrecognizedExtensionsList = []) { this.value = value; this.issuer = issuer; this.serialNumber = serialNumber; this.attrTypes = attrTypes; this._unrecognizedExtensionsList = _unrecognizedExtensionsList; } /** * @summary Restructures an object into a X509AttributeCertificateAttributes * @description * * This takes an `object` and converts it to a `X509AttributeCertificateAttributes`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `X509AttributeCertificateAttributes`. * @returns {X509AttributeCertificateAttributes} */ static _from_object(_o) { return new X509AttributeCertificateAttributes(_o.value, _o.issuer, _o.serialNumber, _o.attrTypes, _o._unrecognizedExtensionsList); } } /** * @summary The Leading Root Component Types of X509AttributeCertificateAttributes * @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_X509AttributeCertificateAttributes = [ new $.ComponentSpec("value", false, $.hasAnyTag), new $.ComponentSpec("issuer", true, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("serialNumber", true, $.hasTag(_TagClass.universal, 2)), new $.ComponentSpec("attrTypes", true, $.hasTag(_TagClass.context, 0)), ]; /** * @summary The Trailing Root Component Types of X509AttributeCertificateAttributes * @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_X509AttributeCertificateAttributes = []; /** * @summary The Extension Addition Component Types of X509AttributeCertificateAttributes * @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_X509AttributeCertificateAttributes = []; let _cached_decoder_for_X509AttributeCertificateAttributes = null; /** * @summary Decodes an ASN.1 element into a(n) X509AttributeCertificateAttributes * @function * @param {_Element} el The element being decoded. * @returns {X509AttributeCertificateAttributes} The decoded data structure. */ export function _decode_X509AttributeCertificateAttributes(el) { if (!_cached_decoder_for_X509AttributeCertificateAttributes) { _cached_decoder_for_X509AttributeCertificateAttributes = function (el) { let value; let issuer; let serialNumber; let attrTypes; let _unrecognizedExtensionsList = []; const callbacks = { value: (_el) => { value = _get_decoder_for_ObjectValue(_decode_AttributeCertificate)(_el); }, issuer: (_el) => { issuer = _decode_GeneralNames(_el); }, serialNumber: (_el) => { serialNumber = _decode_CertificateSerialNumber(_el); }, attrTypes: (_el) => { attrTypes = $._decode_implicit(() => $._decodeSequenceOf(() => $._decodeObjectIdentifier))(_el); }, }; $._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_X509AttributeCertificateAttributes, _extension_additions_list_spec_for_X509AttributeCertificateAttributes, _root_component_type_list_2_spec_for_X509AttributeCertificateAttributes, (ext) => { _unrecognizedExtensionsList.push(ext); }); return new X509AttributeCertificateAttributes(value, issuer, serialNumber, attrTypes, _unrecognizedExtensionsList); }; } return _cached_decoder_for_X509AttributeCertificateAttributes(el); } let _cached_encoder_for_X509AttributeCertificateAttributes = null; /** * @summary Encodes a(n) X509AttributeCertificateAttributes 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 X509AttributeCertificateAttributes, encoded as an ASN.1 Element. */ export function _encode_X509AttributeCertificateAttributes(value, elGetter) { if (!_cached_encoder_for_X509AttributeCertificateAttributes) { _cached_encoder_for_X509AttributeCertificateAttributes = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ _get_encoder_for_ObjectValue(_encode_AttributeCertificate)(value.value, $.BER), /* IF_ABSENT */ value.issuer === undefined ? undefined : _encode_GeneralNames(value.issuer, $.BER), /* IF_ABSENT */ value.serialNumber === undefined ? undefined : _encode_CertificateSerialNumber(value.serialNumber, $.BER), /* IF_ABSENT */ value.attrTypes === undefined ? undefined : $._encode_implicit(_TagClass.context, 0, () => $._encodeSequenceOf(() => $._encodeObjectIdentifier, $.BER), $.BER)(value.attrTypes, $.BER), ], value._unrecognizedExtensionsList ? value._unrecognizedExtensionsList : []) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_X509AttributeCertificateAttributes(value, elGetter); } /* eslint-enable */