@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
182 lines (181 loc) • 6.01 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { algid_hmacWithSHA1 } from "../PKCS5v2-1/algid-hmacWithSHA1.va.mjs";
import { _decode_AlgorithmIdentifier, _encode_AlgorithmIdentifier, } from "../PKCS5v2-1/AlgorithmIdentifier.ta.mjs";
import { _decode_PBKDF2_params_salt, _encode_PBKDF2_params_salt, } from "../PKCS5v2-1/PBKDF2-params-salt.ta.mjs";
/**
* @summary PBKDF2_params
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* PBKDF2-params ::= SEQUENCE {
* salt CHOICE {
* specified OCTET STRING,
* otherSource AlgorithmIdentifier {{PBKDF2-SaltSources}}
* },
* iterationCount INTEGER (1..MAX),
* keyLength INTEGER (1..MAX) OPTIONAL,
* prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT
* algid-hmacWithSHA1
* }
* ```
*
*/
export class PBKDF2_params {
salt;
iterationCount;
keyLength;
prf;
constructor(
/**
* @summary `salt`.
* @public
* @readonly
*/
salt,
/**
* @summary `iterationCount`.
* @public
* @readonly
*/
iterationCount,
/**
* @summary `keyLength`.
* @public
* @readonly
*/
keyLength,
/**
* @summary `prf`.
* @public
* @readonly
*/
prf) {
this.salt = salt;
this.iterationCount = iterationCount;
this.keyLength = keyLength;
this.prf = prf;
}
/**
* @summary Restructures an object into a PBKDF2_params
* @description
*
* This takes an `object` and converts it to a `PBKDF2_params`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `PBKDF2_params`.
* @returns {PBKDF2_params}
*/
static _from_object(_o) {
return new PBKDF2_params(_o.salt, _o.iterationCount, _o.keyLength, _o.prf);
}
/**
* @summary Getter that returns the default value for `prf`.
* @public
* @static
* @method
*/
static get _default_value_for_prf() {
return algid_hmacWithSHA1;
}
}
/**
* @summary The Leading Root Component Types of PBKDF2_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_PBKDF2_params = [
new $.ComponentSpec("salt", false, $.hasAnyTag),
new $.ComponentSpec("iterationCount", false, $.hasTag(_TagClass.universal, 2)),
new $.ComponentSpec("keyLength", true, $.hasTag(_TagClass.universal, 2)),
new $.ComponentSpec("prf", true, $.hasTag(_TagClass.universal, 16)),
];
/**
* @summary The Trailing Root Component Types of PBKDF2_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_PBKDF2_params = [];
/**
* @summary The Extension Addition Component Types of PBKDF2_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_PBKDF2_params = [];
let _cached_decoder_for_PBKDF2_params = null;
/**
* @summary Decodes an ASN.1 element into a(n) PBKDF2_params
* @function
* @param {_Element} el The element being decoded.
* @returns {PBKDF2_params} The decoded data structure.
*/
export function _decode_PBKDF2_params(el) {
if (!_cached_decoder_for_PBKDF2_params) {
_cached_decoder_for_PBKDF2_params = function (el) {
let salt;
let iterationCount;
let keyLength;
let prf = PBKDF2_params._default_value_for_prf;
const callbacks = {
salt: (_el) => {
salt = _decode_PBKDF2_params_salt(_el);
},
iterationCount: (_el) => {
iterationCount = $._decodeInteger(_el);
},
keyLength: (_el) => {
keyLength = $._decodeInteger(_el);
},
prf: (_el) => {
prf = _decode_AlgorithmIdentifier(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_PBKDF2_params, _extension_additions_list_spec_for_PBKDF2_params, _root_component_type_list_2_spec_for_PBKDF2_params, undefined);
return new PBKDF2_params(salt, iterationCount, keyLength, prf);
};
}
return _cached_decoder_for_PBKDF2_params(el);
}
let _cached_encoder_for_PBKDF2_params = null;
/**
* @summary Encodes a(n) PBKDF2_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 PBKDF2_params, encoded as an ASN.1 Element.
*/
export function _encode_PBKDF2_params(value, elGetter) {
if (!_cached_encoder_for_PBKDF2_params) {
_cached_encoder_for_PBKDF2_params = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ _encode_PBKDF2_params_salt(value.salt, $.BER),
/* REQUIRED */ $._encodeInteger(value.iterationCount, $.BER),
/* IF_ABSENT */ value.keyLength === undefined
? undefined
: $._encodeInteger(value.keyLength, $.BER),
/* IF_DEFAULT */ value.prf === undefined ||
$.deepEq(value.prf, PBKDF2_params._default_value_for_prf)
? undefined
: _encode_AlgorithmIdentifier(value.prf, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_PBKDF2_params(value, elGetter);
}
/* eslint-enable */