@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
186 lines • 6.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports._encode_MacData = exports._decode_MacData = exports._extension_additions_list_spec_for_MacData = exports._root_component_type_list_2_spec_for_MacData = exports._root_component_type_list_1_spec_for_MacData = exports.MacData = void 0;
/* eslint-disable */
const asn1_ts_1 = require("asn1-ts");
const $ = require("asn1-ts/dist/node/functional");
const DigestInfo_ta_1 = require("../PKCS7/DigestInfo.ta");
/* START_OF_SYMBOL_DEFINITION MacData */
/**
* @summary MacData
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* MacData ::= SEQUENCE {
* mac DigestInfo,
* macSalt OCTET STRING,
* iterations INTEGER DEFAULT 1
* -- Note: The default is for historical reasons and its use is
* -- deprecated.
* }
* ```
*
* @class
*/
class MacData {
constructor(
/**
* @summary `mac`.
* @public
* @readonly
*/
mac,
/**
* @summary `macSalt`.
* @public
* @readonly
*/
macSalt,
/**
* @summary `iterations`.
* @public
* @readonly
*/
iterations) {
this.mac = mac;
this.macSalt = macSalt;
this.iterations = iterations;
}
/**
* @summary Restructures an object into a MacData
* @description
*
* This takes an `object` and converts it to a `MacData`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `MacData`.
* @returns {MacData}
*/
static _from_object(_o) {
return new MacData(_o.mac, _o.macSalt, _o.iterations);
}
/**
* @summary Getter that returns the default value for `iterations`.
* @public
* @static
* @method
*/
static get _default_value_for_iterations() {
return 1;
}
}
exports.MacData = MacData;
/* END_OF_SYMBOL_DEFINITION MacData */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_MacData */
/**
* @summary The Leading Root Component Types of MacData
* @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
*/
exports._root_component_type_list_1_spec_for_MacData = [
new $.ComponentSpec("mac", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 16), undefined, undefined),
new $.ComponentSpec("macSalt", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 4), undefined, undefined),
new $.ComponentSpec("iterations", true, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 2), undefined, undefined),
];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_MacData */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_MacData */
/**
* @summary The Trailing Root Component Types of MacData
* @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
*/
exports._root_component_type_list_2_spec_for_MacData = [];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_MacData */
/* START_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_MacData */
/**
* @summary The Extension Addition Component Types of MacData
* @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
*/
exports._extension_additions_list_spec_for_MacData = [];
/* END_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_MacData */
/* START_OF_SYMBOL_DEFINITION _cached_decoder_for_MacData */
let _cached_decoder_for_MacData = null;
/* END_OF_SYMBOL_DEFINITION _cached_decoder_for_MacData */
/* START_OF_SYMBOL_DEFINITION _decode_MacData */
/**
* @summary Decodes an ASN.1 element into a(n) MacData
* @function
* @param {_Element} el The element being decoded.
* @returns {MacData} The decoded data structure.
*/
function _decode_MacData(el) {
if (!_cached_decoder_for_MacData) {
_cached_decoder_for_MacData = function (el) {
/* START_OF_SEQUENCE_COMPONENT_DECLARATIONS */
let mac;
let macSalt;
let iterations = MacData._default_value_for_iterations;
/* END_OF_SEQUENCE_COMPONENT_DECLARATIONS */
/* START_OF_CALLBACKS_MAP */
const callbacks = {
mac: (_el) => {
mac = DigestInfo_ta_1._decode_DigestInfo(_el);
},
macSalt: (_el) => {
macSalt = $._decodeOctetString(_el);
},
iterations: (_el) => {
iterations = $._decodeInteger(_el);
},
};
/* END_OF_CALLBACKS_MAP */
$._parse_sequence(el, callbacks, exports._root_component_type_list_1_spec_for_MacData, exports._extension_additions_list_spec_for_MacData, exports._root_component_type_list_2_spec_for_MacData, undefined);
return new MacData(
/* SEQUENCE_CONSTRUCTOR_CALL */ mac, macSalt, iterations);
};
}
return _cached_decoder_for_MacData(el);
}
exports._decode_MacData = _decode_MacData;
/* END_OF_SYMBOL_DEFINITION _decode_MacData */
/* START_OF_SYMBOL_DEFINITION _cached_encoder_for_MacData */
let _cached_encoder_for_MacData = null;
/* END_OF_SYMBOL_DEFINITION _cached_encoder_for_MacData */
/* START_OF_SYMBOL_DEFINITION _encode_MacData */
/**
* @summary Encodes a(n) MacData into an ASN.1 Element.
* @function
* @param {value} el The element being decoded.
* @param elGetter A function that can be used to get new ASN.1 elements.
* @returns {_Element} The MacData, encoded as an ASN.1 Element.
*/
function _encode_MacData(value, elGetter) {
if (!_cached_encoder_for_MacData) {
_cached_encoder_for_MacData = function (value, elGetter) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ DigestInfo_ta_1._encode_DigestInfo(value.mac, $.BER),
/* REQUIRED */ $._encodeOctetString(value.macSalt, $.BER),
/* IF_DEFAULT */ value.iterations === undefined ||
$.deepEq(value.iterations, MacData._default_value_for_iterations)
? undefined
: $._encodeInteger(value.iterations, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_MacData(value, elGetter);
}
exports._encode_MacData = _encode_MacData;
/* END_OF_SYMBOL_DEFINITION _encode_MacData */
/* eslint-enable */
//# sourceMappingURL=MacData.ta.js.map