File indexing completed on 2024-12-22 05:05:19

0001 // SPDX-FileCopyrightText: 2001,2002 the KPGP authors
0002 // SPDX-FileCopyrightText: 2015 Sandro Knauß <knauss@kolabsys.com>
0003 // SPDX-FileCopyrightText: 2017 Daniel Vrátil <dvratil@kde.org>
0004 // SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006 #pragma once
0007 
0008 #include "mimetreeparser_core_export.h"
0009 
0010 #include <KMime/Message>
0011 #include <QByteArray>
0012 #include <QList>
0013 
0014 namespace MimeTreeParser
0015 {
0016 enum PGPBlockType {
0017     UnknownBlock = -1, // BEGIN PGP ???
0018     NoPgpBlock = 0,
0019     PgpMessageBlock = 1, // BEGIN PGP MESSAGE
0020     MultiPgpMessageBlock = 2, // BEGIN PGP MESSAGE, PART X[/Y]
0021     SignatureBlock = 3, // BEGIN PGP SIGNATURE
0022     ClearsignedBlock = 4, // BEGIN PGP SIGNED MESSAGE
0023     PublicKeyBlock = 5, // BEGIN PGP PUBLIC KEY BLOCK
0024     PrivateKeyBlock = 6, // BEGIN PGP PRIVATE KEY BLOCK (PGP 2.x: ...SECRET...)
0025 };
0026 
0027 class MIMETREEPARSER_CORE_EXPORT Block
0028 {
0029 public:
0030     Block();
0031     Block(const QByteArray &m);
0032 
0033     Block(const QByteArray &m, PGPBlockType t);
0034 
0035     [[nodiscard]] QByteArray text() const;
0036     [[nodiscard]] PGPBlockType type() const;
0037     [[nodiscard]] PGPBlockType determineType() const;
0038 
0039     QByteArray msg;
0040     PGPBlockType mType = UnknownBlock;
0041 };
0042 
0043 /** Parses the given message and splits it into OpenPGP blocks and
0044     Non-OpenPGP blocks.
0045 */
0046 [[nodiscard]] MIMETREEPARSER_CORE_EXPORT QList<Block> prepareMessageForDecryption(const QByteArray &msg);
0047 
0048 namespace CryptoUtils
0049 {
0050 [[nodiscard]] MIMETREEPARSER_CORE_EXPORT KMime::Message::Ptr decryptMessage(const KMime::Message::Ptr &decrypt, bool &wasEncrypted);
0051 }
0052 
0053 } // namespace MimeTreeParser
0054 
0055 Q_DECLARE_TYPEINFO(MimeTreeParser::Block, Q_MOVABLE_TYPE);