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

kgpg

  • sources
  • kde-4.12
  • 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 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 <KGlobal>
26 #include <KLocale>
27 
28 #include "kgpgsettings.h"
29 #include "images.h"
30 
31 namespace KgpgCore
32 {
33 
34 namespace Convert
35 {
36 
37 QString toString(const KgpgKeyAlgo algorithm)
38 {
39  switch (algorithm)
40  {
41  case ALGO_RSA: return i18nc("Encryption algorithm", "RSA");
42  case ALGO_DSA: return i18nc("Encryption algorithm", "DSA");
43  case ALGO_ELGAMAL: return i18nc("Encryption algorithm", "ElGamal");
44  case ALGO_DSA_ELGAMAL: return i18nc("Encryption algorithm", "DSA & ElGamal");
45  case ALGO_RSA_RSA: return i18nc("Encryption algorithm RSA, Signing algorithm RSA", "RSA & RSA");
46  case ALGO_UNKNOWN:
47  default: return i18nc("Unknown algorithm", "Unknown");
48  }
49 }
50 
51 QString toString(const KgpgKeyOwnerTrust ownertrust)
52 {
53  switch (ownertrust)
54  {
55  case OWTRUST_UNDEFINED: return i18n("Do not Know");
56  case OWTRUST_NONE: return i18n("Do NOT Trust");
57  case OWTRUST_MARGINAL: return i18n("Marginally");
58  case OWTRUST_FULL: return i18n("Fully");
59  case OWTRUST_ULTIMATE: return i18n("Ultimately");
60  case OWTRUST_UNKNOWN:
61  default: return i18nc("Unknown trust in key owner", "Unknown");
62  }
63 }
64 
65 QString toString(const KgpgKeyTrust trust)
66 {
67  switch (trust)
68  {
69  case TRUST_INVALID: return i18nc("Invalid key", "Invalid");
70  case TRUST_DISABLED: return i18nc("Disabled key", "Disabled");
71  case TRUST_REVOKED: return i18n("Revoked");
72  case TRUST_EXPIRED: return i18nc("Expired key", "Expired");
73  case TRUST_UNDEFINED: return i18nc("Undefined key trust", "Undefined");
74  case TRUST_NONE: return i18nc("No trust in key", "None");
75  case TRUST_MARGINAL: return i18nc("Marginal trust in key", "Marginal");
76  case TRUST_FULL: return i18nc("Full trust in key", "Full");
77  case TRUST_ULTIMATE: return i18nc("Ultimate trust in key", "Ultimate");
78  case TRUST_UNKNOWN:
79  default: return i18nc("Unknown trust in key", "Unknown");
80  }
81 }
82 
83 QString toString(const QDate &date)
84 {
85  return KGlobal::locale()->formatDate(date, KLocale::ShortDate);
86 }
87 
88 QString toString(const KgpgCore::KgpgSubKeyType type)
89 {
90  QStringList res;
91 
92  if (type & SKT_SIGNATURE)
93  res << i18nc("key capability", "Signature");
94  if (type & SKT_ENCRYPTION)
95  res << i18nc("key capability", "Encryption");
96  if (type & SKT_AUTHENTICATION)
97  res << i18nc("key capability", "Authentication");
98  if (type & SKT_CERTIFICATION)
99  res << i18nc("key capability", "Certification");
100 
101  return res.join(i18nc("used to join a list of key types, e.g. 'encryption, signature'", ", "));
102 }
103 
104 KgpgKeyAlgo toAlgo(const uint v)
105 {
106  switch (v)
107  {
108  case 1: return ALGO_RSA;
109  case 16:
110  case 20: return ALGO_ELGAMAL;
111  case 17: return ALGO_DSA;
112  default: return ALGO_UNKNOWN;
113  }
114 }
115 
116 KgpgKeyAlgo toAlgo(const QString &s)
117 {
118  bool b;
119  unsigned int u = s.toUInt(&b);
120  return b ? toAlgo(u) : ALGO_UNKNOWN;
121 }
122 
123 KgpgKeyTrust toTrust(const QChar &c)
124 {
125  switch (c.toAscii())
126  {
127  case 'o': return TRUST_UNKNOWN;
128  case 'i': return TRUST_INVALID;
129  case 'd': return TRUST_DISABLED;
130  case 'r': return TRUST_REVOKED;
131  case 'e': return TRUST_EXPIRED;
132  case 'q': return TRUST_UNDEFINED;
133  case 'n': return TRUST_NONE;
134  case 'm': return TRUST_MARGINAL;
135  case 'f': return TRUST_FULL;
136  case 'u': return TRUST_ULTIMATE;
137  default: return TRUST_UNKNOWN;
138  }
139 }
140 
141 KgpgKeyTrust toTrust(const QString &s)
142 {
143  return s.isEmpty() ? TRUST_UNKNOWN : toTrust(s[0]);
144 }
145 
146 KgpgKeyOwnerTrust toOwnerTrust(const QChar &c)
147 {
148  switch (c.toAscii())
149  {
150  case 'n': return OWTRUST_NONE;
151  case 'm': return OWTRUST_MARGINAL;
152  case 'u': return OWTRUST_ULTIMATE;
153  case 'f': return OWTRUST_FULL;
154  default: return OWTRUST_UNDEFINED;
155  }
156 }
157 
158 KgpgKeyOwnerTrust toOwnerTrust(const QString &s)
159 {
160  return s.isEmpty() ? OWTRUST_UNDEFINED : toOwnerTrust(s[0]);
161 }
162 
163 KgpgSubKeyType toSubType(const QString& capString, bool upper)
164 {
165  KgpgSubKeyType ret;
166 
167  foreach (const QChar &ch, capString) {
168  switch (ch.toAscii()) {
169  case 's':
170  case 'S':
171  if (upper != ch.isUpper())
172  continue;
173  ret |= SKT_SIGNATURE;
174  break;
175  case 'e':
176  case 'E':
177  if (upper != ch.isUpper())
178  continue;
179  ret |= SKT_ENCRYPTION;
180  break;
181  case 'a':
182  case 'A':
183  if (upper != ch.isUpper())
184  continue;
185  ret |= SKT_AUTHENTICATION;
186  break;
187  case 'c':
188  case 'C':
189  if (upper != ch.isUpper())
190  continue;
191  ret |= SKT_CERTIFICATION;
192  break;
193  case 'D': // disabled key
194  case '?': // unknown to GnuPG
195  continue;
196  default:
197  kDebug(2100) << "unknown capability letter" << ch
198  << "in cap string" << capString;
199  }
200  }
201 
202  return ret;
203 }
204 
205 } // namespace Convert
206 
207 } // namespace KgpgCore
KgpgCore::OWTRUST_NONE
You do not trust the key owner, keys signed by him are untrusted.
Definition: kgpgkey.h:80
KgpgCore::TRUST_MARGINAL
there is a minimal level of trust
Definition: kgpgkey.h:61
KgpgCore::SKT_SIGNATURE
Definition: kgpgkey.h:91
KgpgCore::OWTRUST_ULTIMATE
There is no doubt in this key owner. This level is used for your own secret keys. ...
Definition: kgpgkey.h:83
KgpgCore::SKT_ENCRYPTION
Definition: kgpgkey.h:90
KgpgCore::ALGO_ELGAMAL
Definition: kgpgkey.h:37
KgpgCore::OWTRUST_MARGINAL
You have a minimum level of trust in the key owner.
Definition: kgpgkey.h:81
KgpgCore::OWTRUST_UNKNOWN
Trust value is unknown (e.g. no entry in trust database).
Definition: kgpgkey.h:78
KgpgCore::OWTRUST_FULL
You believe the key owner does good checking. Keys signed by him are trusted by you, too.
Definition: kgpgkey.h:82
KgpgCore::Convert::toTrust
KgpgKeyTrust toTrust(const QChar &c)
Definition: convert.cpp:123
images.h
KgpgCore::Convert::toOwnerTrust
KgpgKeyOwnerTrust toOwnerTrust(const QChar &c)
Definition: convert.cpp:146
KgpgCore::TRUST_DISABLED
key is disabled by user (not owner)
Definition: kgpgkey.h:55
KgpgCore::Convert::toSubType
KgpgSubKeyType toSubType(const QString &capString, bool upper)
parse the GnuPG capabilities field
Definition: convert.cpp:163
KgpgCore::Convert::toString
QString toString(const KgpgKeyAlgo algorithm)
Definition: convert.cpp:37
KgpgCore::ALGO_UNKNOWN
Definition: kgpgkey.h:34
KgpgCore::TRUST_FULL
you can fully trust this key
Definition: kgpgkey.h:62
KgpgCore::SKT_CERTIFICATION
Definition: kgpgkey.h:93
KgpgCore::OWTRUST_UNDEFINED
Trust value undefined (e.g. not trust level set).
Definition: kgpgkey.h:79
KgpgCore::TRUST_EXPIRED
key is beyond it's expiry date
Definition: kgpgkey.h:57
KgpgCore::TRUST_UNDEFINED
trust value undefined (i.e. you did not set a trust level)
Definition: kgpgkey.h:58
KgpgCore::TRUST_REVOKED
key is revoked by owner
Definition: kgpgkey.h:56
KgpgCore::ALGO_RSA_RSA
Definition: kgpgkey.h:39
kgpgsettings.h
KgpgCore::TRUST_UNKNOWN
trust value unknown (i.e. no entry in gpg's trust database)
Definition: kgpgkey.h:59
KgpgCore::SKT_AUTHENTICATION
Definition: kgpgkey.h:92
KgpgCore::TRUST_ULTIMATE
this key has highest possible level of trust (e.g. your own secret keys)
Definition: kgpgkey.h:63
KgpgCore::TRUST_INVALID
key is invalid
Definition: kgpgkey.h:54
convert.h
KgpgCore::Convert::toAlgo
KgpgKeyAlgo toAlgo(const uint v)
Definition: convert.cpp:104
KgpgCore::TRUST_NONE
there is no trusted path to this key
Definition: kgpgkey.h:60
KgpgCore::ALGO_DSA
Definition: kgpgkey.h:36
KgpgCore::ALGO_RSA
Definition: kgpgkey.h:35
KgpgCore::ALGO_DSA_ELGAMAL
Definition: kgpgkey.h:38
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:07:51 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
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • 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