UNPKG

@wildboar/pkcs

Version:
170 lines (169 loc) 5.72 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_Identifier, _encode_Identifier, } from "../PKCS-15/Identifier.ta.mjs"; import { _decode_Path, _encode_Path } from "../PKCS-15/Path.ta.mjs"; /** * @summary UnusedSpace * @description * * ### ASN.1 Definition: * * ```asn1 * UnusedSpace ::= SEQUENCE { * path Path (WITH COMPONENTS {..., index PRESENT, length PRESENT}), * authId Identifier OPTIONAL, * ..., * accessControlRules SEQUENCE OF AccessControlRule OPTIONAL * } * ``` * */ export class UnusedSpace { path; authId; accessControlRules; _unrecognizedExtensionsList; constructor( /** * @summary `path`. * @public * @readonly */ path, /** * @summary `authId`. * @public * @readonly */ authId, /** * @summary `accessControlRules`. * @public * @readonly */ accessControlRules, /** * @summary Extensions that are not recognized. * @public * @readonly */ _unrecognizedExtensionsList = []) { this.path = path; this.authId = authId; this.accessControlRules = accessControlRules; this._unrecognizedExtensionsList = _unrecognizedExtensionsList; } /** * @summary Restructures an object into a UnusedSpace * @description * * This takes an `object` and converts it to a `UnusedSpace`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `UnusedSpace`. * @returns {UnusedSpace} */ static _from_object(_o) { return new UnusedSpace(_o.path, _o.authId, _o.accessControlRules, _o._unrecognizedExtensionsList); } } /** * @summary The Leading Root Component Types of UnusedSpace * @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_UnusedSpace = [ new $.ComponentSpec("path", false, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("authId", true, $.hasTag(_TagClass.universal, 4)), ]; /** * @summary The Trailing Root Component Types of UnusedSpace * @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_UnusedSpace = []; /** * @summary The Extension Addition Component Types of UnusedSpace * @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_UnusedSpace = [ new $.ComponentSpec("accessControlRules", true, $.hasTag(_TagClass.universal, 16)), ]; let _cached_decoder_for_UnusedSpace = null; /** * @summary Decodes an ASN.1 element into a(n) UnusedSpace * @function * @param {_Element} el The element being decoded. * @returns {UnusedSpace} The decoded data structure. */ export function _decode_UnusedSpace(el) { if (!_cached_decoder_for_UnusedSpace) { _cached_decoder_for_UnusedSpace = function (el) { let path; let authId; let accessControlRules; let _unrecognizedExtensionsList = []; const callbacks = { path: (_el) => { path = _decode_Path(_el); }, authId: (_el) => { authId = _decode_Identifier(_el); }, accessControlRules: (_el) => { accessControlRules = $._decodeSequenceOf(() => _decode_AccessControlRule)(_el); }, }; $._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_UnusedSpace, _extension_additions_list_spec_for_UnusedSpace, _root_component_type_list_2_spec_for_UnusedSpace, (ext) => { _unrecognizedExtensionsList.push(ext); }); return new UnusedSpace(path, authId, accessControlRules, _unrecognizedExtensionsList); }; } return _cached_decoder_for_UnusedSpace(el); } let _cached_encoder_for_UnusedSpace = null; /** * @summary Encodes a(n) UnusedSpace 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 UnusedSpace, encoded as an ASN.1 Element. */ export function _encode_UnusedSpace(value, elGetter) { if (!_cached_encoder_for_UnusedSpace) { _cached_encoder_for_UnusedSpace = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ _encode_Path(value.path, $.BER), /* IF_ABSENT */ value.authId === undefined ? undefined : _encode_Identifier(value.authId, $.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_UnusedSpace(value, elGetter); } /* eslint-enable */