UNPKG

@wildboar/ocsp

Version:
133 lines (132 loc) 4.28 kB
/* eslint-disable */ import { ASN1ConstructionError as _ConstructionError, ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _decode_Name, _encode_Name, } from "@wildboar/pki-stub"; import { _decode_AuthorityInfoAccessSyntax, _encode_AuthorityInfoAccessSyntax, } from "@wildboar/x500/PkiPmiExternalDataTypes"; /** * @summary ServiceLocator * @description * * ### ASN.1 Definition: * * ```asn1 * ServiceLocator ::= SEQUENCE { * issuer Name, * locator AuthorityInfoAccessSyntax } * ``` * */ export class ServiceLocator { issuer; locator; constructor( /** * @summary `issuer`. * @public * @readonly */ issuer, /** * @summary `locator`. * @public * @readonly */ locator) { this.issuer = issuer; this.locator = locator; } /** * @summary Restructures an object into a ServiceLocator * @description * * This takes an `object` and converts it to a `ServiceLocator`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `ServiceLocator`. * @returns {ServiceLocator} */ static _from_object(_o) { return new ServiceLocator(_o.issuer, _o.locator); } } /** * @summary The Leading Root Component Types of ServiceLocator * @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_ServiceLocator = [ new $.ComponentSpec("issuer", false, $.hasAnyTag), new $.ComponentSpec("locator", false, $.hasTag(_TagClass.universal, 16)), ]; /** * @summary The Trailing Root Component Types of ServiceLocator * @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_ServiceLocator = []; /** * @summary The Extension Addition Component Types of ServiceLocator * @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_ServiceLocator = []; let _cached_decoder_for_ServiceLocator = null; /** * @summary Decodes an ASN.1 element into a(n) ServiceLocator * @function * @param {_Element} el The element being decoded. * @returns {ServiceLocator} The decoded data structure. */ export function _decode_ServiceLocator(el) { if (!_cached_decoder_for_ServiceLocator) { _cached_decoder_for_ServiceLocator = function (el) { const sequence = el.sequence; if (sequence.length < 2) { throw new _ConstructionError("ServiceLocator contained only " + sequence.length.toString() + " elements."); } sequence[0].name = "issuer"; sequence[1].name = "locator"; let issuer; let locator; issuer = _decode_Name(sequence[0]); locator = _decode_AuthorityInfoAccessSyntax(sequence[1]); return new ServiceLocator(issuer, locator); }; } return _cached_decoder_for_ServiceLocator(el); } let _cached_encoder_for_ServiceLocator = null; /** * @summary Encodes a(n) ServiceLocator 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 ServiceLocator, encoded as an ASN.1 Element. */ export function _encode_ServiceLocator(value, elGetter) { if (!_cached_encoder_for_ServiceLocator) { _cached_encoder_for_ServiceLocator = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ _encode_Name(value.issuer, $.DER), /* REQUIRED */ _encode_AuthorityInfoAccessSyntax(value.locator, $.DER), ]) .filter((c) => !!c), $.DER); }; } return _cached_encoder_for_ServiceLocator(value, elGetter); } /* eslint-enable */