@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
161 lines • 6.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports._encode_DigestInfo = exports._decode_DigestInfo = exports._extension_additions_list_spec_for_DigestInfo = exports._root_component_type_list_2_spec_for_DigestInfo = exports._root_component_type_list_1_spec_for_DigestInfo = exports.DigestInfo = exports._encode_DigestAlgorithmIdentifier = exports._decode_DigestAlgorithmIdentifier = exports._encode_Digest = exports._decode_Digest = void 0;
/* eslint-disable */
const asn1_ts_1 = require("asn1-ts");
const $ = require("asn1-ts/dist/node/functional");
const Digest_ta_1 = require("../PKCS7/Digest.ta");
const DigestAlgorithmIdentifier_ta_1 = require("../PKCS7/DigestAlgorithmIdentifier.ta");
var Digest_ta_2 = require("../PKCS7/Digest.ta");
Object.defineProperty(exports, "_decode_Digest", { enumerable: true, get: function () { return Digest_ta_2._decode_Digest; } });
Object.defineProperty(exports, "_encode_Digest", { enumerable: true, get: function () { return Digest_ta_2._encode_Digest; } });
var DigestAlgorithmIdentifier_ta_2 = require("../PKCS7/DigestAlgorithmIdentifier.ta");
Object.defineProperty(exports, "_decode_DigestAlgorithmIdentifier", { enumerable: true, get: function () { return DigestAlgorithmIdentifier_ta_2._decode_DigestAlgorithmIdentifier; } });
Object.defineProperty(exports, "_encode_DigestAlgorithmIdentifier", { enumerable: true, get: function () { return DigestAlgorithmIdentifier_ta_2._encode_DigestAlgorithmIdentifier; } });
/* START_OF_SYMBOL_DEFINITION DigestInfo */
/**
* @summary DigestInfo
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* DigestInfo ::= SEQUENCE {
* digestAlgorithm DigestAlgorithmIdentifier,
* digest Digest
* }
* ```
*
* @class
*/
class DigestInfo {
constructor(
/**
* @summary `digestAlgorithm`.
* @public
* @readonly
*/
digestAlgorithm,
/**
* @summary `digest`.
* @public
* @readonly
*/
digest) {
this.digestAlgorithm = digestAlgorithm;
this.digest = digest;
}
/**
* @summary Restructures an object into a DigestInfo
* @description
*
* This takes an `object` and converts it to a `DigestInfo`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `DigestInfo`.
* @returns {DigestInfo}
*/
static _from_object(_o) {
return new DigestInfo(_o.digestAlgorithm, _o.digest);
}
}
exports.DigestInfo = DigestInfo;
/* END_OF_SYMBOL_DEFINITION DigestInfo */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_DigestInfo */
/**
* @summary The Leading Root Component Types of DigestInfo
* @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_DigestInfo = [
new $.ComponentSpec("digestAlgorithm", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 16), undefined, undefined),
new $.ComponentSpec("digest", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 16), undefined, undefined),
];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_DigestInfo */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_DigestInfo */
/**
* @summary The Trailing Root Component Types of DigestInfo
* @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_DigestInfo = [];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_DigestInfo */
/* START_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_DigestInfo */
/**
* @summary The Extension Addition Component Types of DigestInfo
* @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_DigestInfo = [];
/* END_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_DigestInfo */
/* START_OF_SYMBOL_DEFINITION _cached_decoder_for_DigestInfo */
let _cached_decoder_for_DigestInfo = null;
/* END_OF_SYMBOL_DEFINITION _cached_decoder_for_DigestInfo */
/* START_OF_SYMBOL_DEFINITION _decode_DigestInfo */
/**
* @summary Decodes an ASN.1 element into a(n) DigestInfo
* @function
* @param {_Element} el The element being decoded.
* @returns {DigestInfo} The decoded data structure.
*/
function _decode_DigestInfo(el) {
if (!_cached_decoder_for_DigestInfo) {
_cached_decoder_for_DigestInfo = function (el) {
const sequence = el.sequence;
if (sequence.length < 2) {
throw new asn1_ts_1.ASN1ConstructionError("DigestInfo contained only " +
sequence.length.toString() +
" elements.");
}
sequence[0].name = "digestAlgorithm";
sequence[1].name = "digest";
let digestAlgorithm;
let digest;
digestAlgorithm = DigestAlgorithmIdentifier_ta_1._decode_DigestAlgorithmIdentifier(sequence[0]);
digest = Digest_ta_1._decode_Digest(sequence[1]);
return new DigestInfo(digestAlgorithm, digest);
};
}
return _cached_decoder_for_DigestInfo(el);
}
exports._decode_DigestInfo = _decode_DigestInfo;
/* END_OF_SYMBOL_DEFINITION _decode_DigestInfo */
/* START_OF_SYMBOL_DEFINITION _cached_encoder_for_DigestInfo */
let _cached_encoder_for_DigestInfo = null;
/* END_OF_SYMBOL_DEFINITION _cached_encoder_for_DigestInfo */
/* START_OF_SYMBOL_DEFINITION _encode_DigestInfo */
/**
* @summary Encodes a(n) DigestInfo 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 DigestInfo, encoded as an ASN.1 Element.
*/
function _encode_DigestInfo(value, elGetter) {
if (!_cached_encoder_for_DigestInfo) {
_cached_encoder_for_DigestInfo = function (value, elGetter) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ DigestAlgorithmIdentifier_ta_1._encode_DigestAlgorithmIdentifier(value.digestAlgorithm, $.BER),
/* REQUIRED */ Digest_ta_1._encode_Digest(value.digest, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_DigestInfo(value, elGetter);
}
exports._encode_DigestInfo = _encode_DigestInfo;
/* END_OF_SYMBOL_DEFINITION _encode_DigestInfo */
/* eslint-enable */
//# sourceMappingURL=DigestInfo.ta.js.map