UNPKG

@wildboar/pkcs

Version:
157 lines (156 loc) 5.1 kB
/* eslint-disable */ import { ASN1ConstructionError as _ConstructionError, ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _decode_FingerPrint_finger, _encode_FingerPrint_finger, _enum_for_FingerPrint_finger, } from "../PKCS-15/FingerPrint-finger.ta.mjs"; import { _decode_FingerPrint_hand, _encode_FingerPrint_hand, _enum_for_FingerPrint_hand, } from "../PKCS-15/FingerPrint-hand.ta.mjs"; /** * @summary FingerPrint * @description * * ### ASN.1 Definition: * * ```asn1 * FingerPrint ::= SEQUENCE { * hand ENUMERATED {left, right}, * finger ENUMERATED {thumb, pointerFinger, middleFinger, ringFinger, littleFinger}, * ... * } * ``` * */ export class FingerPrint { hand; finger; _unrecognizedExtensionsList; constructor( /** * @summary `hand`. * @public * @readonly */ hand, /** * @summary `finger`. * @public * @readonly */ finger, /** * @summary Extensions that are not recognized. * @public * @readonly */ _unrecognizedExtensionsList = []) { this.hand = hand; this.finger = finger; this._unrecognizedExtensionsList = _unrecognizedExtensionsList; } /** * @summary Restructures an object into a FingerPrint * @description * * This takes an `object` and converts it to a `FingerPrint`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `FingerPrint`. * @returns {FingerPrint} */ static _from_object(_o) { return new FingerPrint(_o.hand, _o.finger, _o._unrecognizedExtensionsList); } /** * @summary The enum used as the type of the component `hand` * @public * @static */ static _enum_for_hand = _enum_for_FingerPrint_hand; /** * @summary The enum used as the type of the component `finger` * @public * @static */ static _enum_for_finger = _enum_for_FingerPrint_finger; } /** * @summary The Leading Root Component Types of FingerPrint * @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_FingerPrint = [ new $.ComponentSpec("hand", false, $.hasTag(_TagClass.universal, 10)), new $.ComponentSpec("finger", false, $.hasTag(_TagClass.universal, 10)), ]; /** * @summary The Trailing Root Component Types of FingerPrint * @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_FingerPrint = []; /** * @summary The Extension Addition Component Types of FingerPrint * @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_FingerPrint = []; let _cached_decoder_for_FingerPrint = null; /** * @summary Decodes an ASN.1 element into a(n) FingerPrint * @function * @param {_Element} el The element being decoded. * @returns {FingerPrint} The decoded data structure. */ export function _decode_FingerPrint(el) { if (!_cached_decoder_for_FingerPrint) { _cached_decoder_for_FingerPrint = function (el) { const sequence = el.sequence; if (sequence.length < 2) { throw new _ConstructionError("FingerPrint contained only " + sequence.length.toString() + " elements."); } sequence[0].name = "hand"; sequence[1].name = "finger"; let hand; let finger; hand = _decode_FingerPrint_hand(sequence[0]); finger = _decode_FingerPrint_finger(sequence[1]); return new FingerPrint(hand, finger, sequence.slice(2)); }; } return _cached_decoder_for_FingerPrint(el); } let _cached_encoder_for_FingerPrint = null; /** * @summary Encodes a(n) FingerPrint 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 FingerPrint, encoded as an ASN.1 Element. */ export function _encode_FingerPrint(value, elGetter) { if (!_cached_encoder_for_FingerPrint) { _cached_encoder_for_FingerPrint = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ _encode_FingerPrint_hand(value.hand, $.BER), /* REQUIRED */ _encode_FingerPrint_finger(value.finger, $.BER), ], value._unrecognizedExtensionsList ? value._unrecognizedExtensionsList : []) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_FingerPrint(value, elGetter); } /* eslint-enable */