• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

kgpg

  • sources
  • kde-4.14
  • kdeutils
  • kgpg
  • core
convert.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006 Jimmy Gilles <jimmygilles@gmail.com>
3  * Copyright (C) 2010,2013,2014 Rolf Eike Beer <kde@opensource.sf-tec.de>
4  */
5 /***************************************************************************
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #include "convert.h"
23 
24 #include <KDebug>
25 #include <gpgme.h>
26 
27 #include "kgpgsettings.h"
28 
29 namespace KgpgCore
30 {
31 
32 namespace Convert
33 {
34 
35 QString toString(const KgpgKeyAlgo algorithm)
36 {
37  switch (algorithm) {
38  case ALGO_RSA:
39  return i18nc("Encryption algorithm", "RSA");
40  case ALGO_DSA:
41  return i18nc("Encryption algorithm", "DSA");
42  case ALGO_ELGAMAL:
43  return i18nc("Encryption algorithm", "ElGamal");
44  case ALGO_DSA_ELGAMAL:
45  return i18nc("Encryption algorithm", "DSA & ElGamal");
46  case ALGO_RSA_RSA:
47  return i18nc("Encryption algorithm RSA, Signing algorithm RSA", "RSA & RSA");
48  case ALGO_UNKNOWN:
49  default:
50  return i18nc("Unknown algorithm", "Unknown");
51  }
52 }
53 
54 QString toString(const gpgme_validity_t ownertrust)
55 {
56  switch (ownertrust) {
57  case GPGME_VALIDITY_UNDEFINED:
58  return i18n("Do not Know");
59  case GPGME_VALIDITY_NEVER:
60  return i18n("Do NOT Trust");
61  case GPGME_VALIDITY_MARGINAL:
62  return i18n("Marginally");
63  case GPGME_VALIDITY_FULL:
64  return i18n("Fully");
65  case GPGME_VALIDITY_ULTIMATE:
66  return i18n("Ultimately");
67  case GPGME_VALIDITY_UNKNOWN:
68  default:
69  return i18nc("Unknown trust in key owner", "Unknown");
70  }
71 }
72 
73 QString toString(const KgpgKeyTrust trust)
74 {
75  switch (trust) {
76  case TRUST_INVALID:
77  return i18nc("Invalid key", "Invalid");
78  case TRUST_DISABLED:
79  return i18nc("Disabled key", "Disabled");
80  case TRUST_REVOKED:
81  return i18n("Revoked");
82  case TRUST_EXPIRED:
83  return i18nc("Expired key", "Expired");
84  case TRUST_UNDEFINED:
85  return i18nc("Undefined key trust", "Undefined");
86  case TRUST_NONE:
87  return i18nc("No trust in key", "None");
88  case TRUST_MARGINAL:
89  return i18nc("Marginal trust in key", "Marginal");
90  case TRUST_FULL:
91  return i18nc("Full trust in key", "Full");
92  case TRUST_ULTIMATE:
93  return i18nc("Ultimate trust in key", "Ultimate");
94  case TRUST_UNKNOWN:
95  default:
96  return i18nc("Unknown trust in key", "Unknown");
97  }
98 }
99 
100 QString toString(const KgpgCore::KgpgSubKeyType type)
101 {
102  QStringList res;
103 
104  if (type & SKT_SIGNATURE)
105  res << i18nc("key capability", "Signature");
106  if (type & SKT_ENCRYPTION)
107  res << i18nc("key capability", "Encryption");
108  if (type & SKT_AUTHENTICATION)
109  res << i18nc("key capability", "Authentication");
110  if (type & SKT_CERTIFICATION)
111  res << i18nc("key capability", "Certification");
112 
113  return res.join(i18nc("used to join a list of key types, e.g. 'encryption, signature'", ", "));
114 }
115 
116 KgpgKeyAlgo toAlgo(const uint v)
117 {
118  switch (v) {
119  case GPGME_PK_RSA:
120  return ALGO_RSA;
121  case GPGME_PK_ELG_E:
122  case GPGME_PK_ELG:
123  return ALGO_ELGAMAL;
124  case GPGME_PK_DSA:
125  return ALGO_DSA;
126  default:
127  return ALGO_UNKNOWN;
128  }
129 }
130 
131 KgpgKeyAlgo toAlgo(const QString &s)
132 {
133  bool b;
134  unsigned int u = s.toUInt(&b);
135  return b ? toAlgo(u) : ALGO_UNKNOWN;
136 }
137 
138 KgpgKeyTrust toTrust(const QChar &c)
139 {
140  switch (c.toAscii()) {
141  case 'o':
142  return TRUST_UNKNOWN;
143  case 'i':
144  return TRUST_INVALID;
145  case 'd':
146  return TRUST_DISABLED;
147  case 'r':
148  return TRUST_REVOKED;
149  case 'e':
150  return TRUST_EXPIRED;
151  case 'q':
152  return TRUST_UNDEFINED;
153  case 'n':
154  return TRUST_NONE;
155  case 'm':
156  return TRUST_MARGINAL;
157  case 'f':
158  return TRUST_FULL;
159  case 'u':
160  return TRUST_ULTIMATE;
161  default:
162  return TRUST_UNKNOWN;
163  }
164 }
165 
166 KgpgKeyTrust toTrust(const QString &s)
167 {
168  return s.isEmpty() ? TRUST_UNKNOWN : toTrust(s[0]);
169 }
170 
171 gpgme_validity_t toOwnerTrust(const QChar &c)
172 {
173  switch (c.toAscii()) {
174  case 'n':
175  return GPGME_VALIDITY_NEVER;
176  case 'm':
177  return GPGME_VALIDITY_MARGINAL;
178  case 'f':
179  return GPGME_VALIDITY_FULL;
180  case 'u':
181  return GPGME_VALIDITY_ULTIMATE;
182  default:
183  return GPGME_VALIDITY_UNDEFINED;
184  }
185 }
186 
187 KgpgSubKeyType toSubType(const QString& capString, bool upper)
188 {
189  KgpgSubKeyType ret;
190 
191  foreach (const QChar &ch, capString) {
192  switch (ch.toAscii()) {
193  case 's':
194  case 'S':
195  if (upper != ch.isUpper())
196  continue;
197  ret |= SKT_SIGNATURE;
198  break;
199  case 'e':
200  case 'E':
201  if (upper != ch.isUpper())
202  continue;
203  ret |= SKT_ENCRYPTION;
204  break;
205  case 'a':
206  case 'A':
207  if (upper != ch.isUpper())
208  continue;
209  ret |= SKT_AUTHENTICATION;
210  break;
211  case 'c':
212  case 'C':
213  if (upper != ch.isUpper())
214  continue;
215  ret |= SKT_CERTIFICATION;
216  break;
217  case 'D': // disabled key
218  case '?': // unknown to GnuPG
219  continue;
220  default:
221  kDebug(2100) << "unknown capability letter" << ch
222  << "in cap string" << capString;
223  }
224  }
225 
226  return ret;
227 }
228 
229 } // namespace Convert
230 
231 } // namespace KgpgCore
KgpgCore::TRUST_MARGINAL
there is a minimal level of trust
Definition: kgpgkey.h:62
KgpgCore::SKT_SIGNATURE
Definition: kgpgkey.h:73
KgpgCore::SKT_ENCRYPTION
Definition: kgpgkey.h:72
QChar::toAscii
char toAscii() const
KgpgCore::ALGO_ELGAMAL
Definition: kgpgkey.h:38
QChar
KgpgCore::Convert::toTrust
KgpgKeyTrust toTrust(const QChar &c)
Definition: convert.cpp:138
QStringList::join
QString join(const QString &separator) const
KgpgCore::TRUST_DISABLED
key is disabled by user (not owner)
Definition: kgpgkey.h:56
QString::isEmpty
bool isEmpty() const
QChar::isUpper
bool isUpper() const
KgpgCore::Convert::toSubType
KgpgSubKeyType toSubType(const QString &capString, bool upper)
parse the GnuPG capabilities field
Definition: convert.cpp:187
KgpgCore::Convert::toString
QString toString(const KgpgKeyAlgo algorithm)
Definition: convert.cpp:35
KgpgCore::ALGO_UNKNOWN
Definition: kgpgkey.h:35
QString
KgpgCore::TRUST_FULL
you can fully trust this key
Definition: kgpgkey.h:63
KgpgCore::SKT_CERTIFICATION
Definition: kgpgkey.h:75
KgpgCore::Convert::toOwnerTrust
gpgme_validity_t toOwnerTrust(const QChar &c)
Definition: convert.cpp:171
QStringList
KgpgCore::TRUST_EXPIRED
key is beyond it's expiry date
Definition: kgpgkey.h:58
KgpgCore::TRUST_UNDEFINED
trust value undefined (i.e. you did not set a trust level)
Definition: kgpgkey.h:59
KgpgCore::TRUST_REVOKED
key is revoked by owner
Definition: kgpgkey.h:57
KgpgCore::ALGO_RSA_RSA
Definition: kgpgkey.h:40
kgpgsettings.h
KgpgCore::TRUST_UNKNOWN
trust value unknown (i.e. no entry in gpg's trust database)
Definition: kgpgkey.h:60
KgpgCore::SKT_AUTHENTICATION
Definition: kgpgkey.h:74
KgpgCore::TRUST_ULTIMATE
this key has highest possible level of trust (e.g. your own secret keys)
Definition: kgpgkey.h:64
KgpgCore::TRUST_INVALID
key is invalid
Definition: kgpgkey.h:55
convert.h
KgpgCore::Convert::toAlgo
KgpgKeyAlgo toAlgo(const uint v)
Definition: convert.cpp:116
KgpgCore::TRUST_NONE
there is no trusted path to this key
Definition: kgpgkey.h:61
KgpgCore::ALGO_DSA
Definition: kgpgkey.h:37
KgpgCore::ALGO_RSA
Definition: kgpgkey.h:36
QString::toUInt
uint toUInt(bool *ok, int base) const
KgpgCore::ALGO_DSA_ELGAMAL
Definition: kgpgkey.h:39
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kgpg

Skip menu "kgpg"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal