UNPKG

@wildboar/pkcs

Version:
148 lines (147 loc) 4.62 kB
/* eslint-disable */ import { ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; /** * @summary DHParameter * @description * * ### ASN.1 Definition: * * ```asn1 * DHParameter ::= SEQUENCE { * prime INTEGER, -- p * base INTEGER, -- g * privateValueLength INTEGER OPTIONAL * } * ``` * */ export class DHParameter { prime; base; privateValueLength; constructor( /** * @summary `prime`. * @public * @readonly */ prime, /** * @summary `base`. * @public * @readonly */ base, /** * @summary `privateValueLength`. * @public * @readonly */ privateValueLength) { this.prime = prime; this.base = base; this.privateValueLength = privateValueLength; } /** * @summary Restructures an object into a DHParameter * @description * * This takes an `object` and converts it to a `DHParameter`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `DHParameter`. * @returns {DHParameter} */ static _from_object(_o) { return new DHParameter(_o.prime, _o.base, _o.privateValueLength); } } /** * @summary The Leading Root Component Types of DHParameter * @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_DHParameter = [ new $.ComponentSpec("prime", false, $.hasTag(_TagClass.universal, 2)), new $.ComponentSpec("base", false, $.hasTag(_TagClass.universal, 2)), new $.ComponentSpec("privateValueLength", true, $.hasTag(_TagClass.universal, 2)), ]; /** * @summary The Trailing Root Component Types of DHParameter * @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_DHParameter = []; /** * @summary The Extension Addition Component Types of DHParameter * @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_DHParameter = []; let _cached_decoder_for_DHParameter = null; /** * @summary Decodes an ASN.1 element into a(n) DHParameter * @function * @param {_Element} el The element being decoded. * @returns {DHParameter} The decoded data structure. */ export function _decode_DHParameter(el) { if (!_cached_decoder_for_DHParameter) { _cached_decoder_for_DHParameter = function (el) { let prime; let base; let privateValueLength; const callbacks = { prime: (_el) => { prime = $._decodeBigInt(_el); }, base: (_el) => { base = $._decodeBigInt(_el); }, privateValueLength: (_el) => { privateValueLength = $._decodeInteger(_el); }, }; $._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_DHParameter, _extension_additions_list_spec_for_DHParameter, _root_component_type_list_2_spec_for_DHParameter, undefined); return new DHParameter(prime, base, privateValueLength); }; } return _cached_decoder_for_DHParameter(el); } let _cached_encoder_for_DHParameter = null; /** * @summary Encodes a(n) DHParameter 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 DHParameter, encoded as an ASN.1 Element. */ export function _encode_DHParameter(value, elGetter) { if (!_cached_encoder_for_DHParameter) { _cached_encoder_for_DHParameter = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ $._encodeBigInt(value.prime, $.BER), /* REQUIRED */ $._encodeBigInt(value.base, $.BER), /* IF_ABSENT */ value.privateValueLength === undefined ? undefined : $._encodeInteger(value.privateValueLength, $.BER), ]) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_DHParameter(value, elGetter); } /* eslint-enable */