-
Notifications
You must be signed in to change notification settings - Fork 1
/
GPGMeWrapper.hpp
92 lines (76 loc) · 3.1 KB
/
GPGMeWrapper.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* This file is part of kate-gpg-plugin (https://github.com/dennis2society).
* Copyright (c) 2023 Dennis Luebke.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
/**
* @brief This is a convenience wrapper for GPGMepp/GpgMe++ calls.
* We want returned datatypes in C++/Qt types+containers.
*/
#include <QVector>
#include <GPGKeyDetails.hpp>
#include <gpgme++/key.h>
struct GPGOperationResult {
QString resultString; // de- or encrypted string depending on operation
bool keyFound = false;
bool decryptionSuccess = false;
QString errorMessage;
QString keyIDUsedForDecryption;
};
class GPGMeWrapper {
private:
// The list of available GPG Keys
QVector<GPGKeyDetails> m_keys;
// for convenience reasons we want to know the currently selected key from the
// UI
uint m_selectedKeyIndex;
/**
* @brief Gets all available GPG keys containing mail addresses
* with search pattern.
* @param searchPattern_ The mail search pattern.
* @return A list of matching GpgMe::Key
*/
std::vector<GpgME::Key> listKeys(bool showOnlyPrivateKeys_, const QString &searchPattern_ = "");
public:
GPGMeWrapper();
~GPGMeWrapper();
const QVector<GPGKeyDetails> &getKeys() const;
size_t getNumKeys() const;
/**
* @brief This function reads all available keys and
* adds its details to the keys list.
*/
void loadKeys(bool showOnlyPrivateKeys_, bool hideExpiredKeys_, const QString searchPattern_);
/**
* @brief This function attempts to decrypt a given input string
* using any of the available private keys. Will fail if the
* message was not encrypted to your private key.
* @param inputString_ The encrypted input string.
* @param fingerprint_ This is used for planning ahead when attempting
* to decrypt a message encrypted to multiple
* recipients.
* @return The GPGOerationsResult (see above)
*/
const GPGOperationResult decryptString(const QString &inputString_,
const QString &fingerprint_);
const GPGOperationResult encryptString(const QString &inputString_,
const QString &fingerprint_,
const QString &recipientMail_,
bool symmetricEncryption_ = false,
bool showOnlyPrivateKeys_ = false);
bool isPreferredKey(const GPGKeyDetails d_, const QString &mailAddress_);
void setSelectedKeyIndex(uint newSelectedKeyIndex);
uint selectedKeyIndex() const;
};