@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
133 lines (132 loc) • 4.54 kB
JavaScript
/* eslint-disable */
import { ASN1ConstructionError as _ConstructionError, ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_AlgorithmIdentifier, _encode_AlgorithmIdentifier, } from "../PKCS5v2-1/AlgorithmIdentifier.ta.mjs";
/**
* @summary PBMAC1_params
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* PBMAC1-params ::= SEQUENCE {
* keyDerivationFunc AlgorithmIdentifier {{PBMAC1-KDFs}},
* messageAuthScheme AlgorithmIdentifier {{PBMAC1-MACs}}
* }
* ```
*
*/
export class PBMAC1_params {
keyDerivationFunc;
messageAuthScheme;
constructor(
/**
* @summary `keyDerivationFunc`.
* @public
* @readonly
*/
keyDerivationFunc,
/**
* @summary `messageAuthScheme`.
* @public
* @readonly
*/
messageAuthScheme) {
this.keyDerivationFunc = keyDerivationFunc;
this.messageAuthScheme = messageAuthScheme;
}
/**
* @summary Restructures an object into a PBMAC1_params
* @description
*
* This takes an `object` and converts it to a `PBMAC1_params`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `PBMAC1_params`.
* @returns {PBMAC1_params}
*/
static _from_object(_o) {
return new PBMAC1_params(_o.keyDerivationFunc, _o.messageAuthScheme);
}
}
/**
* @summary The Leading Root Component Types of PBMAC1_params
* @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_PBMAC1_params = [
new $.ComponentSpec("keyDerivationFunc", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("messageAuthScheme", false, $.hasTag(_TagClass.universal, 16)),
];
/**
* @summary The Trailing Root Component Types of PBMAC1_params
* @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_PBMAC1_params = [];
/**
* @summary The Extension Addition Component Types of PBMAC1_params
* @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_PBMAC1_params = [];
let _cached_decoder_for_PBMAC1_params = null;
/**
* @summary Decodes an ASN.1 element into a(n) PBMAC1_params
* @function
* @param {_Element} el The element being decoded.
* @returns {PBMAC1_params} The decoded data structure.
*/
export function _decode_PBMAC1_params(el) {
if (!_cached_decoder_for_PBMAC1_params) {
_cached_decoder_for_PBMAC1_params = function (el) {
const sequence = el.sequence;
if (sequence.length < 2) {
throw new _ConstructionError("PBMAC1-params contained only " +
sequence.length.toString() +
" elements.");
}
sequence[0].name = "keyDerivationFunc";
sequence[1].name = "messageAuthScheme";
let keyDerivationFunc;
let messageAuthScheme;
keyDerivationFunc = _decode_AlgorithmIdentifier(sequence[0]);
messageAuthScheme = _decode_AlgorithmIdentifier(sequence[1]);
return new PBMAC1_params(keyDerivationFunc, messageAuthScheme);
};
}
return _cached_decoder_for_PBMAC1_params(el);
}
let _cached_encoder_for_PBMAC1_params = null;
/**
* @summary Encodes a(n) PBMAC1_params 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 PBMAC1_params, encoded as an ASN.1 Element.
*/
export function _encode_PBMAC1_params(value, elGetter) {
if (!_cached_encoder_for_PBMAC1_params) {
_cached_encoder_for_PBMAC1_params = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ _encode_AlgorithmIdentifier(value.keyDerivationFunc, $.BER),
/* REQUIRED */ _encode_AlgorithmIdentifier(value.messageAuthScheme, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_PBMAC1_params(value, elGetter);
}
/* eslint-enable */