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