UNPKG

@wildboar/pkcs

Version:
208 lines (207 loc) 7.59 kB
/* eslint-disable */ import { ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _decode_AccessControlRule, _encode_AccessControlRule, } from "../PKCS-15/AccessControlRule.ta.mjs"; import { _decode_CommonObjectFlags, _encode_CommonObjectFlags, } from "../PKCS-15/CommonObjectFlags.ta.mjs"; import { _decode_Identifier, _encode_Identifier, } from "../PKCS-15/Identifier.ta.mjs"; import { _decode_Label, _encode_Label } from "../PKCS-15/Label.ta.mjs"; /** * @summary CommonObjectAttributes * @description * * ### ASN.1 Definition: * * ```asn1 * CommonObjectAttributes ::= SEQUENCE { * label Label OPTIONAL, * flags CommonObjectFlags OPTIONAL, * authId Identifier OPTIONAL, * ..., * userConsent INTEGER (1..pkcs15-ub-userConsent) OPTIONAL, * accessControlRules SEQUENCE SIZE (1..MAX) OF AccessControlRule OPTIONAL * } (CONSTRAINED BY {-- authId should be present in the IC card case if flags.private is set. * -- It must equal an authID in one AuthRecord in the AODF -- }) * ``` * */ export class CommonObjectAttributes { label; flags; authId; userConsent; accessControlRules; _unrecognizedExtensionsList; constructor( /** * @summary `label`. * @public * @readonly */ label, /** * @summary `flags`. * @public * @readonly */ flags, /** * @summary `authId`. * @public * @readonly */ authId, /** * @summary `userConsent`. * @public * @readonly */ userConsent, /** * @summary `accessControlRules`. * @public * @readonly */ accessControlRules, /** * @summary Extensions that are not recognized. * @public * @readonly */ _unrecognizedExtensionsList = []) { this.label = label; this.flags = flags; this.authId = authId; this.userConsent = userConsent; this.accessControlRules = accessControlRules; this._unrecognizedExtensionsList = _unrecognizedExtensionsList; } /** * @summary Restructures an object into a CommonObjectAttributes * @description * * This takes an `object` and converts it to a `CommonObjectAttributes`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `CommonObjectAttributes`. * @returns {CommonObjectAttributes} */ static _from_object(_o) { return new CommonObjectAttributes(_o.label, _o.flags, _o.authId, _o.userConsent, _o.accessControlRules, _o._unrecognizedExtensionsList); } } /** * @summary The Leading Root Component Types of CommonObjectAttributes * @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_CommonObjectAttributes = [ new $.ComponentSpec("label", true, $.hasTag(_TagClass.universal, 12)), new $.ComponentSpec("flags", true, $.hasTag(_TagClass.universal, 3)), new $.ComponentSpec("authId", true, $.hasTag(_TagClass.universal, 4)), ]; /** * @summary The Trailing Root Component Types of CommonObjectAttributes * @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_CommonObjectAttributes = []; /** * @summary The Extension Addition Component Types of CommonObjectAttributes * @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_CommonObjectAttributes = [ new $.ComponentSpec("userConsent", true, $.hasTag(_TagClass.universal, 2)), new $.ComponentSpec("accessControlRules", true, $.hasTag(_TagClass.universal, 16)), ]; let _cached_decoder_for_CommonObjectAttributes = null; /** * @summary Decodes an ASN.1 element into a(n) CommonObjectAttributes * @function * @param {_Element} el The element being decoded. * @returns {CommonObjectAttributes} The decoded data structure. */ export function _decode_CommonObjectAttributes(el) { if (!_cached_decoder_for_CommonObjectAttributes) { _cached_decoder_for_CommonObjectAttributes = function (el) { let label; let flags; let authId; let userConsent; let accessControlRules; let _unrecognizedExtensionsList = []; const callbacks = { label: (_el) => { label = _decode_Label(_el); }, flags: (_el) => { flags = _decode_CommonObjectFlags(_el); }, authId: (_el) => { authId = _decode_Identifier(_el); }, userConsent: (_el) => { userConsent = $._decodeInteger(_el); }, accessControlRules: (_el) => { accessControlRules = $._decodeSequenceOf(() => _decode_AccessControlRule)(_el); }, }; $._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_CommonObjectAttributes, _extension_additions_list_spec_for_CommonObjectAttributes, _root_component_type_list_2_spec_for_CommonObjectAttributes, (ext) => { _unrecognizedExtensionsList.push(ext); }); return new CommonObjectAttributes(label, flags, authId, userConsent, accessControlRules, _unrecognizedExtensionsList); }; } return _cached_decoder_for_CommonObjectAttributes(el); } let _cached_encoder_for_CommonObjectAttributes = null; /** * @summary Encodes a(n) CommonObjectAttributes 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 CommonObjectAttributes, encoded as an ASN.1 Element. */ export function _encode_CommonObjectAttributes(value, elGetter) { if (!_cached_encoder_for_CommonObjectAttributes) { _cached_encoder_for_CommonObjectAttributes = function (value) { return $._encodeSequence([] .concat([ /* IF_ABSENT */ value.label === undefined ? undefined : _encode_Label(value.label, $.BER), /* IF_ABSENT */ value.flags === undefined ? undefined : _encode_CommonObjectFlags(value.flags, $.BER), /* IF_ABSENT */ value.authId === undefined ? undefined : _encode_Identifier(value.authId, $.BER), ], [ /* IF_ABSENT */ value.userConsent === undefined ? undefined : $._encodeInteger(value.userConsent, $.BER), /* IF_ABSENT */ value.accessControlRules === undefined ? undefined : $._encodeSequenceOf(() => _encode_AccessControlRule, $.BER)(value.accessControlRules, $.BER), ], value._unrecognizedExtensionsList ? value._unrecognizedExtensionsList : []) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_CommonObjectAttributes(value, elGetter); } /* eslint-enable */