diff options
Diffstat (limited to 'libkdenetwork/gpgmepp')
-rw-r--r-- | libkdenetwork/gpgmepp/context.cpp | 88 | ||||
-rw-r--r-- | libkdenetwork/gpgmepp/context.h | 11 | ||||
-rw-r--r-- | libkdenetwork/gpgmepp/data.cpp | 10 | ||||
-rw-r--r-- | libkdenetwork/gpgmepp/decryptionresult.cpp | 12 | ||||
-rw-r--r-- | libkdenetwork/gpgmepp/decryptionresult.h | 7 | ||||
-rw-r--r-- | libkdenetwork/gpgmepp/encryptionresult.cpp | 26 | ||||
-rw-r--r-- | libkdenetwork/gpgmepp/encryptionresult.h | 6 | ||||
-rw-r--r-- | libkdenetwork/gpgmepp/signingresult.cpp | 42 | ||||
-rw-r--r-- | libkdenetwork/gpgmepp/signingresult.h | 9 | ||||
-rw-r--r-- | libkdenetwork/gpgmepp/util.h | 4 | ||||
-rw-r--r-- | libkdenetwork/gpgmepp/verificationresult.cpp | 56 | ||||
-rw-r--r-- | libkdenetwork/gpgmepp/verificationresult.h | 8 |
12 files changed, 273 insertions, 6 deletions
diff --git a/libkdenetwork/gpgmepp/context.cpp b/libkdenetwork/gpgmepp/context.cpp index c0286fcbd..547adde95 100644 --- a/libkdenetwork/gpgmepp/context.cpp +++ b/libkdenetwork/gpgmepp/context.cpp @@ -43,6 +43,7 @@ //#include <string> //using std::string; +#include <istream> #ifndef NDEBUG #include <iostream> using std::cerr; @@ -77,6 +78,10 @@ namespace GpgME { return code() == GPG_ERR_CANCELED; } + std::ostream & operator<<( std::ostream & os, Error err ) { + return os << "GpgME::Error(" << err.operator int() << " (" << err.asString() << "))"; + } + Context::Context( gpgme_ctx_t ctx ) { d = new Private( ctx ); } @@ -628,6 +633,89 @@ namespace GpgME { return d->lasterr; } + std::ostream & operator<<( std::ostream & os, Context::Protocol proto ) { + os << "GpgME::Context::Protocol("; + switch ( proto ) { + case Context::OpenPGP: + os << "OpenPGP"; + break; + case Context::CMS: + os << "CMS"; + break; + default: + case Context::Unknown: + os << "Unknown"; + break; + } + return os << ')'; + } + + std::ostream & operator<<( std::ostream & os, Context::CertificateInclusion incl ) { + os << "GpgME::Context::CertificateInclusion(" << static_cast<int>( incl ); + switch ( incl ) { + case Context::DefaultCertificates: + os << "(DefaultCertificates)"; + break; + case Context::AllCertificatesExceptRoot: + os << "(AllCertificatesExceptRoot)"; + break; + case Context::AllCertificates: + os << "(AllCertificates)"; + break; + case Context::NoCertificates: + os << "(NoCertificates)"; + break; + case Context::OnlySenderCertificate: + os << "(OnlySenderCertificate)"; + break; + } + return os << ')'; + } + + std::ostream & operator<<( std::ostream & os, Context::KeyListMode mode ) { + os << "GpgME::Context::KeyListMode("; +#define CHECK( x ) if ( !(mode & (Context::x)) ) {} else do { os << #x " "; } while (0) + CHECK( Local ); + CHECK( Extern ); + CHECK( Signatures ); + CHECK( Validate ); +#undef CHECK + return os << ')'; + } + + std::ostream & operator<<( std::ostream & os, Context::SignatureMode mode ) { + os << "GpgME::Context::SignatureMode("; + switch ( mode ) { +#define CHECK( x ) case Context::x: os << #x; break + CHECK( Normal ); + CHECK( Detached ); + CHECK( Clearsigned ); +#undef CHECK + default: + os << "???" "(" << static_cast<int>( mode ) << ')'; + break; + } + return os << ')'; + } + + std::ostream & operator<<( std::ostream & os, Context::EncryptionFlags flags ) { + os << "GpgME::Context::EncryptionFlags("; +#define CHECK( x ) if ( !(flags & (Context::x)) ) {} else do { os << #x " "; } while (0) + CHECK( AlwaysTrust ); +#undef CHECK + return os << ')'; + } + + std::ostream & operator<<( std::ostream & os, Context::AuditLogFlags flags ) { + os << "GpgME::Context::AuditLogFlags("; +#define CHECK( x ) if ( !(flags & (Context::x)) ) {} else do { os << #x " "; } while (0) + CHECK( HtmlAuditLog ); + CHECK( AuditLogWithHelp ); +#undef CHECK + return os << ')'; + } + + } // namespace GpgME diff --git a/libkdenetwork/gpgmepp/context.h b/libkdenetwork/gpgmepp/context.h index aae69f86a..b07e722ef 100644 --- a/libkdenetwork/gpgmepp/context.h +++ b/libkdenetwork/gpgmepp/context.h @@ -25,6 +25,8 @@ #include <vector> #include <utility> +#include <iosfwd> + #include <kdepimmacros.h> namespace GpgME { @@ -64,6 +66,8 @@ namespace GpgME { int mErr; }; + KDE_EXPORT std::ostream & operator<<( std::ostream & os, Error err ); + class KDE_EXPORT Context { Context( gpgme_ctx_t ); public: @@ -281,6 +285,13 @@ namespace GpgME { const Context & operator=( const Context & ); }; + KDE_EXPORT std::ostream & operator<<( std::ostream & os, Context::Protocol proto ); + KDE_EXPORT std::ostream & operator<<( std::ostream & os, Context::CertificateInclusion incl ); + KDE_EXPORT std::ostream & operator<<( std::ostream & os, Context::KeyListMode mode ); + KDE_EXPORT std::ostream & operator<<( std::ostream & os, Context::SignatureMode mode ); + KDE_EXPORT std::ostream & operator<<( std::ostream & os, Context::EncryptionFlags flags ); + KDE_EXPORT std::ostream & operator<<( std::ostream & os, Context::AuditLogFlags flags ); + // // // Globals diff --git a/libkdenetwork/gpgmepp/data.cpp b/libkdenetwork/gpgmepp/data.cpp index 52c96544b..52471be9b 100644 --- a/libkdenetwork/gpgmepp/data.cpp +++ b/libkdenetwork/gpgmepp/data.cpp @@ -133,11 +133,11 @@ GpgME::Data::Data( DataProvider * dp ) { if ( e ) d->data = 0; #ifndef NDEBUG - std::cerr << "GpgME::Data(): DataProvider supports: " - << ( d->cbs.read ? "read" : "no read" ) << ", " - << ( d->cbs.write ? "write" : "no write" ) << ", " - << ( d->cbs.seek ? "seek" : "no seek" ) << ", " - << ( d->cbs.release ? "release" : "no release" ) << std::endl; +// std::cerr << "GpgME::Data(): DataProvider supports: " +// << ( d->cbs.read ? "read" : "no read" ) << ", " +// << ( d->cbs.write ? "write" : "no write" ) << ", " +// << ( d->cbs.seek ? "seek" : "no seek" ) << ", " +// << ( d->cbs.release ? "release" : "no release" ) << std::endl; #endif } diff --git a/libkdenetwork/gpgmepp/decryptionresult.cpp b/libkdenetwork/gpgmepp/decryptionresult.cpp index cdefefe9b..2efcc67d9 100644 --- a/libkdenetwork/gpgmepp/decryptionresult.cpp +++ b/libkdenetwork/gpgmepp/decryptionresult.cpp @@ -25,11 +25,13 @@ #include <gpgmepp/decryptionresult.h> #include "shared.h" #include "result_p.h" +#include "util.h" #include <gpgme.h> #include <cstring> #include <cstdlib> +#include <istream> class GpgME::DecryptionResult::Private : public GpgME::Shared { public: @@ -71,3 +73,13 @@ bool GpgME::DecryptionResult::wrongKeyUsage() const { #endif return false; } + +std::ostream & GpgME::operator<<( std::ostream & os, const DecryptionResult & result ) { + os << "GpgME::DecryptionResult("; + if ( !result.isNull() ) + os << "\n error: " << result.error() + << "\n unsupportedAlgortihm: " << protect( result.unsupportedAlgortihm() ) + << "\n wrongKeyUsage: " << result.wrongKeyUsage() + << '\n'; + return os << ')'; +} diff --git a/libkdenetwork/gpgmepp/decryptionresult.h b/libkdenetwork/gpgmepp/decryptionresult.h index b6307a05b..b97f59aed 100644 --- a/libkdenetwork/gpgmepp/decryptionresult.h +++ b/libkdenetwork/gpgmepp/decryptionresult.h @@ -23,6 +23,9 @@ #include <gpgmepp/gpgmefw.h> #include <gpgmepp/result.h> + +#include <iosfwd> + #include <kdepimmacros.h> namespace GpgME { @@ -49,6 +52,8 @@ namespace GpgME { Private * d; }; + KDE_EXPORT std::ostream & operator<<( std::ostream & os, const DecryptionResult & result ); + } -#endif // __GPGMEPP_KEYGENERATIONRESULT_H__ +#endif // __GPGMEPP_DECRYPTIONRESULT_H__ diff --git a/libkdenetwork/gpgmepp/encryptionresult.cpp b/libkdenetwork/gpgmepp/encryptionresult.cpp index deec8f9d5..f827ca839 100644 --- a/libkdenetwork/gpgmepp/encryptionresult.cpp +++ b/libkdenetwork/gpgmepp/encryptionresult.cpp @@ -25,11 +25,15 @@ #include <gpgmepp/encryptionresult.h> #include "shared.h" #include "result_p.h" +#include "util.h" #include <gpgme.h> #include <cstring> #include <cstdlib> +#include <istream> +#include <algorithm> +#include <iterator> class GpgME::EncryptionResult::Private : public GpgME::Shared { public: @@ -137,3 +141,25 @@ GpgME::Error GpgME::InvalidRecipient::reason() const { return isNull() ? 0 : d->invalid[idx]->reason ; } + + +std::ostream & GpgME::operator<<( std::ostream & os, const EncryptionResult & result ) { + os << "GpgME::EncryptionResult("; + if ( !result.isNull() ) { + os << "\n error: " << result.error() + << "\n invalid recipients:\n"; + const std::vector<InvalidRecipient> ir = result.invalidEncryptionKeys(); + std::copy( ir.begin(), ir.end(), + std::ostream_iterator<InvalidRecipient>( os, "\n" ) ); + } + return os << ')'; +} + +std::ostream & GpgME::operator<<( std::ostream & os, const InvalidRecipient & ir ) { + os << "GpgME::InvalidRecipient("; + if ( !ir.isNull() ) + os << "\n fingerprint: " << protect( ir.fingerprint() ) + << "\n reason: " << ir.reason() + << '\n'; + return os << ')'; +} diff --git a/libkdenetwork/gpgmepp/encryptionresult.h b/libkdenetwork/gpgmepp/encryptionresult.h index ba59554ef..7267afc01 100644 --- a/libkdenetwork/gpgmepp/encryptionresult.h +++ b/libkdenetwork/gpgmepp/encryptionresult.h @@ -25,6 +25,8 @@ #include <gpgmepp/result.h> #include <vector> +#include <iosfwd> + #include <kdepimmacros.h> namespace GpgME { @@ -53,6 +55,8 @@ namespace GpgME { Private * d; }; + KDE_EXPORT std::ostream & operator<<( std::ostream & os, const EncryptionResult & result ); + class KDE_EXPORT InvalidRecipient { friend class EncryptionResult; InvalidRecipient( EncryptionResult::Private * parent, unsigned int index ); @@ -73,6 +77,8 @@ namespace GpgME { unsigned int idx; }; + KDE_EXPORT std::ostream & operator<<( std::ostream & os, const InvalidRecipient & recipient ); + } #endif // __GPGMEPP_ENCRYPTIONRESULT_H__ diff --git a/libkdenetwork/gpgmepp/signingresult.cpp b/libkdenetwork/gpgmepp/signingresult.cpp index bd5e0a3b8..6996eef7a 100644 --- a/libkdenetwork/gpgmepp/signingresult.cpp +++ b/libkdenetwork/gpgmepp/signingresult.cpp @@ -25,11 +25,15 @@ #include <gpgmepp/signingresult.h> #include "shared.h" #include "result_p.h" +#include "util.h" #include <gpgme.h> #include <cstring> #include <cstdlib> +#include <algorithm> +#include <istream> +#include <iterator> class GpgME::SigningResult::Private : public GpgME::Shared { public: @@ -239,3 +243,41 @@ unsigned int GpgME::CreatedSignature::signatureClass() const { return isNull() ? 0 : d->created[idx]->sig_class ; } + +std::ostream & GpgME::operator<<( std::ostream & os, const SigningResult & result ) { + os << "GpgME::SigningResult("; + if ( !result.isNull() ) { + os << "\n error: " << result.error() + << "\n createdSignatures:\n"; + const std::vector<CreatedSignature> cs = result.createdSignatures(); + std::copy( cs.begin(), cs.end(), + std::ostream_iterator<CreatedSignature>( os, "\n" ) ); + os << " invalidSigningKeys:\n"; + const std::vector<InvalidSigningKey> isk = result.invalidSigningKeys(); + std::copy( isk.begin(), isk.end(), + std::ostream_iterator<InvalidSigningKey>( os, "\n" ) ); + } + return os << ')'; +} + +std::ostream & GpgME::operator<<( std::ostream & os, const CreatedSignature & sig ) { + os << "GpgME::CreatedSignature("; + if ( !sig.isNull() ) + os << "\n fingerprint: " << protect( sig.fingerprint() ) + << "\n creationTime: " << sig.creationTime() + << "\n mode: " << sig.mode() + << "\n publicKeyAlgorithm: " << protect( sig.publicKeyAlgorithmAsString() ) + << "\n hashAlgorithm: " << protect( sig.hashAlgorithmAsString() ) + << "\n signatureClass: " << sig.signatureClass() + << '\n'; + return os << ')'; +} + +std::ostream & GpgME::operator<<( std::ostream & os, const InvalidSigningKey & key ) { + os << "GpgME::InvalidSigningKey("; + if ( !key.isNull() ) + os << "\n fingerprint: " << protect( key.fingerprint() ) + << "\n reason: " << key.reason() + << '\n'; + return os << ')'; +} diff --git a/libkdenetwork/gpgmepp/signingresult.h b/libkdenetwork/gpgmepp/signingresult.h index e9684abb9..202d09b41 100644 --- a/libkdenetwork/gpgmepp/signingresult.h +++ b/libkdenetwork/gpgmepp/signingresult.h @@ -28,7 +28,10 @@ #include <time.h> #include <vector> +#include <iosfwd> + #include <kdepimmacros.h> + namespace GpgME { class Error; @@ -57,6 +60,8 @@ namespace GpgME { Private * d; }; + KDE_EXPORT std::ostream & operator<<( std::ostream & os, const SigningResult & result ); + class KDE_EXPORT InvalidSigningKey { friend class SigningResult; InvalidSigningKey( SigningResult::Private * parent, unsigned int index ); @@ -77,6 +82,8 @@ namespace GpgME { unsigned int idx; }; + KDE_EXPORT std::ostream & operator<<( std::ostream & os, const InvalidSigningKey & key ); + class KDE_EXPORT CreatedSignature { friend class SigningResult; CreatedSignature( SigningResult::Private * parent, unsigned int index ); @@ -110,6 +117,8 @@ namespace GpgME { unsigned int idx; }; + KDE_EXPORT std::ostream & operator<<( std::ostream & os, const CreatedSignature & sig ); + } #endif // __GPGMEPP_SIGNINGRESULT_H__ diff --git a/libkdenetwork/gpgmepp/util.h b/libkdenetwork/gpgmepp/util.h index c8786bdcb..8246cfc32 100644 --- a/libkdenetwork/gpgmepp/util.h +++ b/libkdenetwork/gpgmepp/util.h @@ -28,6 +28,10 @@ #include <iostream> #endif +static inline const char * protect( const char * s ) { + return s ? s : "<null>" ; +} + static inline gpgme_keylist_mode_t add_to_gpgme_keylist_mode_t( unsigned int oldmode, unsigned int newmodes ) { if ( newmodes & GpgME::Context::Local ) oldmode |= GPGME_KEYLIST_MODE_LOCAL; if ( newmodes & GpgME::Context::Extern ) oldmode |= GPGME_KEYLIST_MODE_EXTERN; diff --git a/libkdenetwork/gpgmepp/verificationresult.cpp b/libkdenetwork/gpgmepp/verificationresult.cpp index decf5bce9..abf30d96c 100644 --- a/libkdenetwork/gpgmepp/verificationresult.cpp +++ b/libkdenetwork/gpgmepp/verificationresult.cpp @@ -25,10 +25,13 @@ #include <gpgmepp/verificationresult.h> #include "shared.h" #include "result_p.h" +#include "util.h" #include <gpgme.h> +#include <istream> #include <algorithm> +#include <iterator> #include <cstring> #include <cstdlib> @@ -299,3 +302,56 @@ const char * GpgME::Signature::Notation::value() const { return isNull() ? 0 : d->nota[sidx][nidx].value ; } + +std::ostream & GpgME::operator<<( std::ostream & os, const VerificationResult & result ) { + os << "GpgME::VerificationResult("; + if ( !result.isNull() ) { + os << "\n error: " << result.error() + << "\n signatures:\n"; + const std::vector<Signature> sigs = result.signatures(); + std::copy( sigs.begin(), sigs.end(), + std::ostream_iterator<Signature>( os, "\n" ) ); + } + return os << ')'; +} + +std::ostream & GpgME::operator<<( std::ostream & os, Signature::Summary summary ) { +#define OUTPUT( x ) if ( !(summary & (GpgME::Signature:: x)) ) {} else do { os << #x " "; } while(0) + os << "GpgME::Signature::Summary("; + OUTPUT( Valid ); + OUTPUT( Green ); + OUTPUT( Red ); + OUTPUT( KeyRevoked ); + OUTPUT( KeyExpired ); + OUTPUT( SigExpired ); + OUTPUT( KeyMissing ); + OUTPUT( CrlMissing ); + OUTPUT( CrlTooOld ); + OUTPUT( BadPolicy ); + OUTPUT( SysError ); +#undef OUTPUT + return os << ')'; +} + +std::ostream & GpgME::operator<<( std::ostream & os, const Signature & sig ) { + os << "GpgME::Signature("; + if ( !sig.isNull() ) { + os << "\n Summary: " << sig.summary() + << "\n Fingerprint: " << protect( sig.fingerprint() ) + << "\n Status: " << sig.status() + << "\n creationTime: " << sig.creationTime() + << "\n expirationTime: " << sig.expirationTime() + << "\n wrongKeyUsage: " << sig.wrongKeyUsage() + << "\n validity: " << sig.validityAsString() + << "\n nonValidityReason: " << sig.nonValidityReason() + << "\n notations:\n"; + const std::vector<Signature::Notation> nota = sig.notations(); + std::copy( nota.begin(), nota.end(), + std::ostream_iterator<Signature::Notation>( os, "\n" ) ); + } + return os << ')'; +} + +std::ostream & GpgME::operator<<( std::ostream & os, const Signature::Notation & nota ) { + return os << "GpgME::Signature::Notation( \"" << protect( nota.name() ) << "\", \"" << protect( nota.value() ) << "\")"; +} diff --git a/libkdenetwork/gpgmepp/verificationresult.h b/libkdenetwork/gpgmepp/verificationresult.h index 86e3525f8..edcd02787 100644 --- a/libkdenetwork/gpgmepp/verificationresult.h +++ b/libkdenetwork/gpgmepp/verificationresult.h @@ -27,6 +27,7 @@ #include <time.h> #include <vector> +#include <iosfwd> #include <kdepimmacros.h> @@ -54,6 +55,8 @@ namespace GpgME { Private * d; }; + KDE_EXPORT std::ostream & operator<<( std::ostream & os, const VerificationResult & result ); + class KDE_EXPORT Signature { friend class VerificationResult; Signature( VerificationResult::Private * parent, unsigned int index ); @@ -110,6 +113,9 @@ namespace GpgME { unsigned int idx; }; + KDE_EXPORT std::ostream & operator<<( std::ostream & os, const Signature & sig ); + KDE_EXPORT std::ostream & operator<<( std::ostream & os, Signature::Summary summary ); + class KDE_EXPORT Signature::Notation { friend class Signature; Notation( VerificationResult::Private * parent, unsigned int sindex, unsigned int nindex ); @@ -131,6 +137,8 @@ namespace GpgME { unsigned int nidx; }; + KDE_EXPORT std::ostream & operator<<( std::ostream & os, const Signature::Notation & nota ); + } #endif // __GPGMEPP_VERIFICATIONRESULT_H__ |