@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
146 lines (145 loc) • 4.62 kB
JavaScript
/* eslint-disable */
import { ASN1ConstructionError as _ConstructionError, ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
/**
* @summary OtherPrimeInfo
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* OtherPrimeInfo ::= SEQUENCE {
* prime INTEGER, -- ri
* exponent INTEGER, -- di
* coefficient INTEGER -- ti
* }
* ```
*
*/
export class OtherPrimeInfo {
prime;
exponent;
coefficient;
constructor(
/**
* @summary `prime`.
* @public
* @readonly
*/
prime,
/**
* @summary `exponent`.
* @public
* @readonly
*/
exponent,
/**
* @summary `coefficient`.
* @public
* @readonly
*/
coefficient) {
this.prime = prime;
this.exponent = exponent;
this.coefficient = coefficient;
}
/**
* @summary Restructures an object into a OtherPrimeInfo
* @description
*
* This takes an `object` and converts it to a `OtherPrimeInfo`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `OtherPrimeInfo`.
* @returns {OtherPrimeInfo}
*/
static _from_object(_o) {
return new OtherPrimeInfo(_o.prime, _o.exponent, _o.coefficient);
}
}
/**
* @summary The Leading Root Component Types of OtherPrimeInfo
* @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_OtherPrimeInfo = [
new $.ComponentSpec("prime", false, $.hasTag(_TagClass.universal, 2)),
new $.ComponentSpec("exponent", false, $.hasTag(_TagClass.universal, 2)),
new $.ComponentSpec("coefficient", false, $.hasTag(_TagClass.universal, 2)),
];
/**
* @summary The Trailing Root Component Types of OtherPrimeInfo
* @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_OtherPrimeInfo = [];
/**
* @summary The Extension Addition Component Types of OtherPrimeInfo
* @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_OtherPrimeInfo = [];
let _cached_decoder_for_OtherPrimeInfo = null;
/**
* @summary Decodes an ASN.1 element into a(n) OtherPrimeInfo
* @function
* @param {_Element} el The element being decoded.
* @returns {OtherPrimeInfo} The decoded data structure.
*/
export function _decode_OtherPrimeInfo(el) {
if (!_cached_decoder_for_OtherPrimeInfo) {
_cached_decoder_for_OtherPrimeInfo = function (el) {
const sequence = el.sequence;
if (sequence.length < 3) {
throw new _ConstructionError("OtherPrimeInfo contained only " +
sequence.length.toString() +
" elements.");
}
sequence[0].name = "prime";
sequence[1].name = "exponent";
sequence[2].name = "coefficient";
let prime;
let exponent;
let coefficient;
prime = $._decodeBigInt(sequence[0]);
exponent = $._decodeBigInt(sequence[1]);
coefficient = $._decodeBigInt(sequence[2]);
return new OtherPrimeInfo(prime, exponent, coefficient);
};
}
return _cached_decoder_for_OtherPrimeInfo(el);
}
let _cached_encoder_for_OtherPrimeInfo = null;
/**
* @summary Encodes a(n) OtherPrimeInfo 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 OtherPrimeInfo, encoded as an ASN.1 Element.
*/
export function _encode_OtherPrimeInfo(value, elGetter) {
if (!_cached_encoder_for_OtherPrimeInfo) {
_cached_encoder_for_OtherPrimeInfo = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ $._encodeBigInt(value.prime, $.BER),
/* REQUIRED */ $._encodeBigInt(value.exponent, $.BER),
/* REQUIRED */ $._encodeBigInt(value.coefficient, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_OtherPrimeInfo(value, elGetter);
}
/* eslint-enable */