-
Notifications
You must be signed in to change notification settings - Fork 1
/
GPGKeyDetails.cpp
71 lines (55 loc) · 2.4 KB
/
GPGKeyDetails.cpp
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
/*
* 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/>.
*/
#include <QDateTime>
#include <string>
#include <vector>
#include <GPGKeyDetails.hpp>
GPGKeyDetails::GPGKeyDetails() {}
GPGKeyDetails::~GPGKeyDetails() {
m_uids.clear();
m_mailAddresses.clear();
m_subkeyIDs.clear();
}
QString GPGKeyDetails::fingerPrint() const { return m_fingerPrint; }
QString GPGKeyDetails::keyID() const { return m_keyID; }
QString GPGKeyDetails::keyType() const { return m_keyType; }
QString GPGKeyDetails::keyLength() const { return m_keyLength; }
QString GPGKeyDetails::creationDate() const { return m_creationDate; }
QString GPGKeyDetails::expiryDate() const { return m_expiryDate; }
const QVector<QString>& GPGKeyDetails::uids() const { return m_uids; }
const QVector<QString>& GPGKeyDetails::mailAdresses() const { return m_mailAddresses; }
const QVector<QString>& GPGKeyDetails::subkeyIDs() const { return m_subkeyIDs; }
size_t GPGKeyDetails::getNumUIds() const { return m_uids.size(); }
const QString timestampToQString(const time_t timestamp_) {
QDateTime dt;
dt.setSecsSinceEpoch(timestamp_);
return dt.toString(QString("yyyy-MM-dd"));
}
void GPGKeyDetails::loadFromGPGMeKey(GpgME::Key key_) {
m_fingerPrint = QString(key_.primaryFingerprint());
m_keyID = QString(key_.shortKeyID());
m_keyType = QString::fromStdString(key_.subkey(0).algoName());
m_keyLength = QString::number(key_.subkey(0).length());
m_creationDate = QString(timestampToQString(key_.subkey(0).creationTime()));
m_expiryDate = QString(timestampToQString(key_.subkey(0).expirationTime()));
const std::vector<GpgME::UserID>& ids = key_.userIDs();
for (auto &id : ids) {
m_uids.push_back(id.name());
m_mailAddresses.push_back(id.email());
m_subkeyIDs.push_back(key_.subkey(1).keyID());
}
}