UNPKG

@wildboar/pkcs

Version:
183 lines 7.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._encode_DigestedData = exports._decode_DigestedData = exports._extension_additions_list_spec_for_DigestedData = exports._root_component_type_list_2_spec_for_DigestedData = exports._root_component_type_list_1_spec_for_DigestedData = exports.DigestedData = void 0; /* eslint-disable */ const asn1_ts_1 = require("asn1-ts"); const $ = require("asn1-ts/dist/node/functional"); const HASH_ta_1 = require("@wildboar/x500/src/lib/modules/AuthenticationFramework/HASH.ta"); const ContentInfo_ta_1 = require("../PKCS7/ContentInfo.ta"); const DigestAlgorithmIdentifier_ta_1 = require("../PKCS7/DigestAlgorithmIdentifier.ta"); const Version_ta_1 = require("../PKCS7/Version.ta"); /* START_OF_SYMBOL_DEFINITION DigestedData */ /** * @summary DigestedData * @description * * ### ASN.1 Definition: * * ```asn1 * DigestedData ::= SEQUENCE { * version Version, * digestAlgorithm DigestAlgorithmIdentifier, * contentInfo ContentInfo, * digest HASH{PKCS7-CONTENT-TYPE.&Type({PKCS7ContentTable})} * } * ``` * * @class */ class DigestedData { constructor( /** * @summary `version`. * @public * @readonly */ version, /** * @summary `digestAlgorithm`. * @public * @readonly */ digestAlgorithm, /** * @summary `contentInfo`. * @public * @readonly */ contentInfo, /** * @summary `digest`. * @public * @readonly */ digest) { this.version = version; this.digestAlgorithm = digestAlgorithm; this.contentInfo = contentInfo; this.digest = digest; } /** * @summary Restructures an object into a DigestedData * @description * * This takes an `object` and converts it to a `DigestedData`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `DigestedData`. * @returns {DigestedData} */ static _from_object(_o) { return new DigestedData(_o.version, _o.digestAlgorithm, _o.contentInfo, _o.digest); } } exports.DigestedData = DigestedData; /* END_OF_SYMBOL_DEFINITION DigestedData */ /* START_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_DigestedData */ /** * @summary The Leading Root Component Types of DigestedData * @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_DigestedData = [ new $.ComponentSpec("version", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 2), undefined, undefined), new $.ComponentSpec("digestAlgorithm", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 16), undefined, undefined), new $.ComponentSpec("contentInfo", 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_DigestedData */ /* START_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_DigestedData */ /** * @summary The Trailing Root Component Types of DigestedData * @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_DigestedData = []; /* END_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_DigestedData */ /* START_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_DigestedData */ /** * @summary The Extension Addition Component Types of DigestedData * @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_DigestedData = []; /* END_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_DigestedData */ /* START_OF_SYMBOL_DEFINITION _cached_decoder_for_DigestedData */ let _cached_decoder_for_DigestedData = null; /* END_OF_SYMBOL_DEFINITION _cached_decoder_for_DigestedData */ /* START_OF_SYMBOL_DEFINITION _decode_DigestedData */ /** * @summary Decodes an ASN.1 element into a(n) DigestedData * @function * @param {_Element} el The element being decoded. * @returns {DigestedData} The decoded data structure. */ function _decode_DigestedData(el) { if (!_cached_decoder_for_DigestedData) { _cached_decoder_for_DigestedData = function (el) { const sequence = el.sequence; if (sequence.length < 4) { throw new asn1_ts_1.ASN1ConstructionError("DigestedData contained only " + sequence.length.toString() + " elements."); } sequence[0].name = "version"; sequence[1].name = "digestAlgorithm"; sequence[2].name = "contentInfo"; sequence[3].name = "digest"; let version; let digestAlgorithm; let contentInfo; let digest; version = Version_ta_1._decode_Version(sequence[0]); digestAlgorithm = DigestAlgorithmIdentifier_ta_1._decode_DigestAlgorithmIdentifier(sequence[1]); contentInfo = ContentInfo_ta_1._decode_ContentInfo(sequence[2]); digest = HASH_ta_1._get_decoder_for_HASH($._decodeAny)(sequence[3]); return new DigestedData(version, digestAlgorithm, contentInfo, digest); }; } return _cached_decoder_for_DigestedData(el); } exports._decode_DigestedData = _decode_DigestedData; /* END_OF_SYMBOL_DEFINITION _decode_DigestedData */ /* START_OF_SYMBOL_DEFINITION _cached_encoder_for_DigestedData */ let _cached_encoder_for_DigestedData = null; /* END_OF_SYMBOL_DEFINITION _cached_encoder_for_DigestedData */ /* START_OF_SYMBOL_DEFINITION _encode_DigestedData */ /** * @summary Encodes a(n) DigestedData 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 DigestedData, encoded as an ASN.1 Element. */ function _encode_DigestedData(value, elGetter) { if (!_cached_encoder_for_DigestedData) { _cached_encoder_for_DigestedData = function (value, elGetter) { return $._encodeSequence([] .concat([ /* REQUIRED */ Version_ta_1._encode_Version(value.version, $.BER), /* REQUIRED */ DigestAlgorithmIdentifier_ta_1._encode_DigestAlgorithmIdentifier(value.digestAlgorithm, $.BER), /* REQUIRED */ ContentInfo_ta_1._encode_ContentInfo(value.contentInfo, $.BER), /* REQUIRED */ HASH_ta_1._get_encoder_for_HASH($._encodeAny)(value.digest, $.BER), ]) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_DigestedData(value, elGetter); } exports._encode_DigestedData = _encode_DigestedData; /* END_OF_SYMBOL_DEFINITION _encode_DigestedData */ /* eslint-enable */ //# sourceMappingURL=DigestedData.ta.js.map