UNPKG

@wildboar/pki-stub

Version:
128 lines (127 loc) 3.83 kB
/* eslint-disable */ import { ASN1ConstructionError as _ConstructionError, ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; /** * @summary ScopeRestriction * @description * * ### ASN.1 Definition: * * ```asn1 * ScopeRestriction ::= SEQUENCE { * id SCOPE-RESTRICTION.&id, * restriction SCOPE-RESTRICTION.&Type, * ... } * ``` * */ export class ScopeRestriction { id; restriction; _unrecognizedExtensionsList; constructor( /** * @summary `id`. * @public * @readonly */ id, /** * @summary `restriction`. * @public * @readonly */ restriction, /** * @summary Extensions that are not recognized. * @public * @readonly */ _unrecognizedExtensionsList = []) { this.id = id; this.restriction = restriction; this._unrecognizedExtensionsList = _unrecognizedExtensionsList; } /** * @summary Restructures an object into a ScopeRestriction * @description * * This takes an `object` and converts it to a `ScopeRestriction`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `ScopeRestriction`. * @returns {ScopeRestriction} */ static _from_object(_o) { return new ScopeRestriction(_o.id, _o.restriction, _o._unrecognizedExtensionsList); } } /** * @summary The Leading Root Component Types of ScopeRestriction * @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_ScopeRestriction = [ new $.ComponentSpec("id", false, $.hasTag(_TagClass.universal, 6)), new $.ComponentSpec("restriction", false, $.hasAnyTag), ]; /** * @summary The Trailing Root Component Types of ScopeRestriction * @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_ScopeRestriction = []; /** * @summary The Extension Addition Component Types of ScopeRestriction * @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_ScopeRestriction = []; /** * @summary Decodes an ASN.1 element into a(n) ScopeRestriction * @function * @param {_Element} el The element being decoded. * @returns {ScopeRestriction} The decoded data structure. */ export function _decode_ScopeRestriction(el) { const sequence = el.sequence; if (sequence.length < 2) { throw new _ConstructionError("ScopeRestriction contained only " + sequence.length.toString() + " elements."); } sequence[0].name = "id"; sequence[1].name = "restriction"; let id; let restriction; id = $._decodeObjectIdentifier(sequence[0]); restriction = $._decodeAny(sequence[1]); return new ScopeRestriction(id, restriction, sequence.slice(2)); } /** * @summary Encodes a(n) ScopeRestriction 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 ScopeRestriction, encoded as an ASN.1 Element. */ export function _encode_ScopeRestriction(value) { const components = [ $._encodeObjectIdentifier(value.id, $.BER), $._encodeAny(value.restriction, $.BER), ...value._unrecognizedExtensionsList ?? [], ]; return $._encodeSequence(components, $.BER); } /* eslint-enable */