From 0855a1296a1908016f011eb5e6552854ac53e63a Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Mon, 22 Feb 2016 18:28:08 +0100 Subject: Initial checkin of gpgmepp sources Based on git.kde.org/pim/gpgmepp rev. 0e3ebc02 * lang/cpp/src/assuanresult.cpp, lang/cpp/src/assuanresult.h, lang/cpp/src/callbacks.cpp, lang/cpp/src/callbacks.h, lang/cpp/src/configuration.cpp, lang/cpp/src/configuration.h, lang/cpp/src/context.cpp, lang/cpp/src/context.h, lang/cpp/src/context_glib.cpp, lang/cpp/src/context_p.h, lang/cpp/src/context_qt.cpp, lang/cpp/src/context_vanilla.cpp, lang/cpp/src/data.cpp, lang/cpp/src/data.h, lang/cpp/src/data_p.h, lang/cpp/src/decryptionresult.cpp, lang/cpp/src/decryptionresult.h, lang/cpp/src/defaultassuantransaction.cpp, lang/cpp/src/defaultassuantransaction.h, lang/cpp/src/editinteractor.cpp, lang/cpp/src/editinteractor.h, lang/cpp/src/encryptionresult.cpp, lang/cpp/src/encryptionresult.h, lang/cpp/src/engineinfo.cpp, lang/cpp/src/engineinfo.h, lang/cpp/src/error.h, lang/cpp/src/eventloopinteractor.cpp, lang/cpp/src/eventloopinteractor.h, lang/cpp/src/exception.cpp, lang/cpp/src/exception.h, lang/cpp/src/global.h, lang/cpp/src/gpgadduserideditinteractor.cpp, lang/cpp/src/gpgadduserideditinteractor.h, lang/cpp/src/gpgagentgetinfoassuantransaction.cpp, lang/cpp/src/gpgagentgetinfoassuantransaction.h, lang/cpp/src/gpgmefw.h, lang/cpp/src/gpgmepp_export.h, lang/cpp/src/gpgsetexpirytimeeditinteractor.cpp, lang/cpp/src/gpgsetexpirytimeeditinteractor.h, lang/cpp/src/gpgsetownertrusteditinteractor.cpp, lang/cpp/src/gpgsetownertrusteditinteractor.h, lang/cpp/src/gpgsignkeyeditinteractor.cpp, lang/cpp/src/gpgsignkeyeditinteractor.h, lang/cpp/src/importresult.cpp, lang/cpp/src/importresult.h, lang/cpp/src/key.cpp, lang/cpp/src/key.h, lang/cpp/src/keygenerationresult.cpp, lang/cpp/src/keygenerationresult.h, lang/cpp/src/keylistresult.cpp, lang/cpp/src/keylistresult.h, lang/cpp/src/notation.h, lang/cpp/src/result.h, lang/cpp/src/result_p.h, lang/cpp/src/scdgetinfoassuantransaction.cpp, lang/cpp/src/scdgetinfoassuantransaction.h, lang/cpp/src/signingresult.cpp, lang/cpp/src/signingresult.h, lang/cpp/src/trustitem.cpp, lang/cpp/src/trustitem.h, lang/cpp/src/util.h, lang/cpp/src/verificationresult.cpp, lang/cpp/src/verificationresult.h, lang/cpp/src/vfsmountresult.cpp, lang/cpp/src/vfsmountresult.h, lang/cpp/src/interfaces/assuantransaction.h, lang/cpp/src/interfaces/dataprovider.h, lang/cpp/src/interfaces/passphraseprovider.h, lang/cpp/src/interfaces/progressprovider.h: New. --- lang/cpp/src/key.h | 358 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 358 insertions(+) create mode 100644 lang/cpp/src/key.h (limited to 'lang/cpp/src/key.h') diff --git a/lang/cpp/src/key.h b/lang/cpp/src/key.h new file mode 100644 index 00000000..80bf4d19 --- /dev/null +++ b/lang/cpp/src/key.h @@ -0,0 +1,358 @@ +/* + key.h - wraps a gpgme key + Copyright (C) 2003, 2005 Klarälvdalens Datakonsult AB + + This file is part of GPGME++. + + GPGME++ is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + GPGME++ 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 Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with GPGME++; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +// -*- c++ -*- +#ifndef __GPGMEPP_KEY_H__ +#define __GPGMEPP_KEY_H__ + +#include "global.h" +#include "notation.h" + +#include "gpgmefw.h" + +#include +#include + +#include + +#include +#include +#include + +namespace GpgME +{ + +class Context; + +class Subkey; +class UserID; + +typedef boost::shared_ptr< boost::remove_pointer::type > shared_gpgme_key_t; + +// +// class Key +// + +class GPGMEPP_EXPORT Key +{ + friend class ::GpgME::Context; + struct Null { + Null() {} + }; +public: + Key(); + /* implicit */ Key(const Null &); + Key(const shared_gpgme_key_t &key); + Key(gpgme_key_t key, bool acquireRef); + + static const Null null; + + const Key &operator=(Key other) + { + swap(other); + return *this; + } + + const Key &mergeWith(const Key &other); + + void swap(Key &other) + { + using std::swap; + swap(this->key, other.key); + } + + bool isNull() const + { + return !key; + } + + UserID userID(unsigned int index) const; + Subkey subkey(unsigned int index) const; + + unsigned int numUserIDs() const; + unsigned int numSubkeys() const; + + std::vector userIDs() const; + std::vector subkeys() const; + + bool isRevoked() const; + bool isExpired() const; + bool isDisabled() const; + bool isInvalid() const; + + bool canEncrypt() const; + /*! + This function contains a workaround for old gpgme's: all secret + OpenPGP keys canSign() == true, which canReallySign() doesn't + have. I don't have time to find what breaks when I remove this + workaround, but since Kleopatra merges secret into public keys, + the workaround is not necessary there (and actively harms), I've + added a new function instead. + */ + bool canSign() const; + bool canReallySign() const; + bool canCertify() const; + bool canAuthenticate() const; + bool isQualified() const; + + bool hasSecret() const; + GPGMEPP_DEPRECATED bool isSecret() const + { + return hasSecret(); + } + + /*! + @return true if this is a X.509 root certificate (currently + equivalent to something like + strcmp( chainID(), subkey(0).fingerprint() ) == 0 ) + */ + bool isRoot() const; + + enum OwnerTrust { Unknown = 0, Undefined = 1, Never = 2, + Marginal = 3, Full = 4, Ultimate = 5 + }; + + OwnerTrust ownerTrust() const; + char ownerTrustAsString() const; + + Protocol protocol() const; + const char *protocolAsString() const; + + const char *issuerSerial() const; + const char *issuerName() const; + const char *chainID() const; + + const char *keyID() const; + const char *shortKeyID() const; + const char *primaryFingerprint() const; + + unsigned int keyListMode() const; + +private: + gpgme_key_t impl() const + { + return key.get(); + } + shared_gpgme_key_t key; +}; + +// +// class Subkey +// + +class GPGMEPP_EXPORT Subkey +{ +public: + Subkey(); + Subkey(const shared_gpgme_key_t &key, gpgme_sub_key_t subkey); + Subkey(const shared_gpgme_key_t &key, unsigned int idx); + + const Subkey &operator=(Subkey other) + { + swap(other); + return *this; + } + + void swap(Subkey &other) + { + using std::swap; + swap(this->key, other.key); + swap(this->subkey, other.subkey); + } + + bool isNull() const + { + return !key || !subkey; + } + + Key parent() const; + + const char *keyID() const; + const char *fingerprint() const; + + time_t creationTime() const; + time_t expirationTime() const; + bool neverExpires() const; + + bool isRevoked() const; + bool isExpired() const; + bool isInvalid() const; + bool isDisabled() const; + + bool canEncrypt() const; + bool canSign() const; + bool canCertify() const; + bool canAuthenticate() const; + bool isQualified() const; + bool isCardKey() const; + + bool isSecret() const; + + unsigned int publicKeyAlgorithm() const; + const char *publicKeyAlgorithmAsString() const; + + unsigned int length() const; + + const char *cardSerialNumber() const; + +private: + shared_gpgme_key_t key; + gpgme_sub_key_t subkey; +}; + +// +// class UserID +// + +class GPGMEPP_EXPORT UserID +{ +public: + class Signature; + + UserID(); + UserID(const shared_gpgme_key_t &key, gpgme_user_id_t uid); + UserID(const shared_gpgme_key_t &key, unsigned int idx); + + const UserID &operator=(UserID other) + { + swap(other); + return *this; + } + + void swap(UserID &other) + { + using std::swap; + swap(this->key, other.key); + swap(this->uid, other.uid); + } + + bool isNull() const + { + return !key || !uid; + } + + Key parent() const; + + unsigned int numSignatures() const; + Signature signature(unsigned int index) const; + std::vector signatures() const; + + const char *id() const; + const char *name() const; + const char *email() const; + const char *comment() const; + + enum Validity { Unknown = 0, Undefined = 1, Never = 2, + Marginal = 3, Full = 4, Ultimate = 5 + }; + + Validity validity() const; + char validityAsString() const; + + bool isRevoked() const; + bool isInvalid() const; + +private: + shared_gpgme_key_t key; + gpgme_user_id_t uid; +}; + +// +// class UserID::Signature +// + +class GPGMEPP_EXPORT UserID::Signature +{ +public: + typedef GPGMEPP_DEPRECATED GpgME::Notation Notation; + + Signature(); + Signature(const shared_gpgme_key_t &key, gpgme_user_id_t uid, gpgme_key_sig_t sig); + Signature(const shared_gpgme_key_t &key, gpgme_user_id_t uid, unsigned int idx); + + const Signature &operator=(Signature other) + { + swap(other); + return *this; + } + + void swap(Signature &other) + { + using std::swap; + swap(this->key, other.key); + swap(this->uid, other.uid); + swap(this->sig, other.sig); + } + + bool isNull() const + { + return !sig || !uid || !key ; + } + + UserID parent() const; + + const char *signerKeyID() const; + + const char *algorithmAsString() const; + unsigned int algorithm() const; + time_t creationTime() const; + time_t expirationTime() const; + bool neverExpires() const; + + bool isRevokation() const; + bool isInvalid() const; + bool isExpired() const; + bool isExportable() const; + + const char *signerUserID() const; + const char *signerName() const; + const char *signerEmail() const; + const char *signerComment() const; + + unsigned int certClass() const; + + enum Status { NoError = 0, SigExpired, KeyExpired, + BadSignature, NoPublicKey, GeneralError + }; + Status status() const; + std::string statusAsString() const; + + const char *policyURL() const; + + unsigned int numNotations() const; + GpgME::Notation notation(unsigned int idx) const; + std::vector notations() const; + +private: + shared_gpgme_key_t key; + gpgme_user_id_t uid; + gpgme_key_sig_t sig; +}; + +} // namespace GpgME + +GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Key) +GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Subkey) +GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(UserID) +GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(UserID::Signature) + +#endif // __GPGMEPP_KEY_H__ -- cgit v1.2.3 From f98898ab1a6952e0c3a5d235963a27eba2e19e46 Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Sun, 3 Apr 2016 04:52:16 -0800 Subject: Cpp / Qt: Reduce boost usage (memory and tuple) * cpp/src/assuanresult.h, cpp/src/configuration.cpp, cpp/src/configuration.h, cpp/src/data.h, cpp/src/decryptionresult.h, cpp/src/defaultassuantransaction.cpp, cpp/src/encryptionresult.cpp, cpp/src/encryptionresult.h, cpp/src/engineinfo.h, cpp/src/gpgagentgetinfoassuantransaction.cpp, cpp/src/gpgsignkeyeditinteractor.cpp, cpp/src/importresult.cpp, cpp/src/importresult.h, cpp/src/key.h, cpp/src/keygenerationresult.h, cpp/src/keylistresult.h, cpp/src/notation.h, cpp/src/signingresult.cpp, cpp/src/signingresult.h, cpp/src/verificationresult.cpp, cpp/src/verificationresult.h, cpp/src/vfsmountresult.h, qt/src/dataprovider.cpp, qt/src/dataprovider.h, qt/src/decryptjob.h, qt/src/decryptverifyjob.h, qt/src/downloadjob.h, qt/src/encryptjob.h, qt/src/qgpgmeadduseridjob.cpp, qt/src/qgpgmechangeexpiryjob.cpp, qt/src/qgpgmechangeownertrustjob.cpp, qt/src/qgpgmechangepasswdjob.cpp, qt/src/qgpgmedecryptjob.cpp, qt/src/qgpgmedecryptjob.h, qt/src/qgpgmedecryptverifyjob.cpp, qt/src/qgpgmedecryptverifyjob.h, qt/src/qgpgmedeletejob.cpp, qt/src/qgpgmedownloadjob.cpp, qt/src/qgpgmedownloadjob.h, qt/src/qgpgmeencryptjob.cpp, qt/src/qgpgmeencryptjob.h, qt/src/qgpgmeexportjob.cpp, qt/src/qgpgmeexportjob.h, qt/src/qgpgmeimportfromkeyserverjob.cpp, qt/src/qgpgmeimportfromkeyserverjob.h, qt/src/qgpgmeimportjob.cpp, qt/src/qgpgmeimportjob.h, qt/src/qgpgmekeygenerationjob.cpp, qt/src/qgpgmekeygenerationjob.h, qt/src/qgpgmekeylistjob.cpp, qt/src/qgpgmekeylistjob.h, qt/src/qgpgmelistallkeysjob.cpp, qt/src/qgpgmelistallkeysjob.h, qt/src/qgpgmenewcryptoconfig.cpp, qt/src/qgpgmenewcryptoconfig.h, qt/src/qgpgmesignencryptjob.cpp, qt/src/qgpgmesignencryptjob.h, qt/src/qgpgmesignjob.cpp, qt/src/qgpgmesignjob.h, qt/src/qgpgmesignkeyjob.cpp, qt/src/qgpgmeverifydetachedjob.cpp, qt/src/qgpgmeverifydetachedjob.h, qt/src/qgpgmeverifyopaquejob.cpp, qt/src/qgpgmeverifyopaquejob.h, qt/src/signencryptjob.h, qt/src/signjob.h, qt/src/threadedjobmixin.h, qt/src/verifydetachedjob.h, qt/src/verifyopaquejob.h: Reduce boost usage. -- This was mostly done with search and replace to change the templates / classes from memory and tuple to their c++11 equivalents. --- lang/cpp/src/key.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lang/cpp/src/key.h') diff --git a/lang/cpp/src/key.h b/lang/cpp/src/key.h index 80bf4d19..a87a35cf 100644 --- a/lang/cpp/src/key.h +++ b/lang/cpp/src/key.h @@ -29,9 +29,7 @@ #include "gpgmefw.h" -#include -#include - +#include #include #include @@ -46,7 +44,7 @@ class Context; class Subkey; class UserID; -typedef boost::shared_ptr< boost::remove_pointer::type > shared_gpgme_key_t; +typedef std::shared_ptr< std::remove_pointer::type > shared_gpgme_key_t; // // class Key -- cgit v1.2.3 From 1bb162a54ba480413c4da07f2578efe6860494c0 Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Mon, 11 Apr 2016 17:02:04 +0200 Subject: Cpp: Add string comparators for keys * lang/cpp/src/global.h (GPGMEPP_MAKE_STRCMP): New. (_gpgmepp_strcmp): NULL save wrapper around std::strcmp. * lang/cpp/src/key.h: Add comparators for various attributes. -- This was taken from libkleo predicates.h. Appears generally useful. --- lang/cpp/src/key.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lang/cpp/src/key.h') diff --git a/lang/cpp/src/key.h b/lang/cpp/src/key.h index a87a35cf..30badeaa 100644 --- a/lang/cpp/src/key.h +++ b/lang/cpp/src/key.h @@ -353,4 +353,9 @@ GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Subkey) GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(UserID) GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(UserID::Signature) +GPGMEPP_MAKE_STRCMP(ByFingerprint, .primaryFingerprint()); +GPGMEPP_MAKE_STRCMP(ByKeyID, .keyID()); +GPGMEPP_MAKE_STRCMP(ByShortKeyID, .shortKeyID()); +GPGMEPP_MAKE_STRCMP(ByChainID, .chainID()); + #endif // __GPGMEPP_KEY_H__ -- cgit v1.2.3 From 5489532ad6ccf3a9b59405686b8a17352f1ecf06 Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Tue, 12 Apr 2016 16:08:10 +0200 Subject: Cpp: Add support for pubkey_algo_name * lang/cpp/src/key.cpp (Subkey::algoName): New. * lang/cpp/src/key.h: Declare. --- lang/cpp/src/key.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lang/cpp/src/key.h') diff --git a/lang/cpp/src/key.h b/lang/cpp/src/key.h index 30badeaa..7322f650 100644 --- a/lang/cpp/src/key.h +++ b/lang/cpp/src/key.h @@ -206,8 +206,27 @@ public: bool isSecret() const; unsigned int publicKeyAlgorithm() const; + + /** + @brief Get the public key algorithm name. + + This only works for the pre 2.1 algorithms for ECC NULL is returned. + + @returns a statically allocated string with the name of the public + key algorithm, or NULL if that name is not known. + */ const char *publicKeyAlgorithmAsString() const; + /** + @brief Get the key algo string like GnuPG 2.1 prints it. + + This returns combinations of size and algorithm. Like + bp512 or rsa2048 + + @returns the key algorithm as string. Empty string on error. + */ + std::string algoName() const; + unsigned int length() const; const char *cardSerialNumber() const; -- cgit v1.2.3