libkdenetwork Library API Documentation

signingresult.cpp

00001 /* signingresult.cpp - wraps a gpgme verify result
00002    Copyright (C) 2004 Klarälvdalens Datakonsult AB
00003 
00004    This file is part of GPGME++.
00005  
00006    GPGME++ is free software; you can redistribute it and/or modify it
00007    under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010  
00011    GPGME++ is distributed in the hope that it will be useful, but
00012    WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with GPGME++; if not, write to the Free Software Foundation,
00018    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA.
00019 */
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024 
00025 #include <gpgmepp/signingresult.h>
00026 #include "shared.h"
00027 #include "result_p.h"
00028 
00029 #include <gpgme.h>
00030 
00031 #include <cstring>
00032 #include <cstdlib>
00033 
00034 class GpgME::SigningResult::Private : public GpgME::Shared {
00035 public:
00036   Private( const gpgme_sign_result_t r ) : Shared() {
00037     if ( !r )
00038       return;
00039     for ( gpgme_new_signature_t is = r->signatures ; is ; is = is->next ) {
00040       gpgme_new_signature_t copy = new _gpgme_new_signature( *is );
00041       if ( is->fpr )
00042     copy->fpr = strdup( is->fpr );
00043       copy->next = 0;
00044       created.push_back( copy );
00045     }
00046     for ( gpgme_invalid_key_t ik = r->invalid_signers ; ik ; ik = ik->next ) {
00047       gpgme_invalid_key_t copy = new _gpgme_invalid_key( *ik );
00048       if ( ik->fpr )
00049     copy->fpr = strdup( ik->fpr );
00050       copy->next = 0;
00051       invalid.push_back( copy );
00052     }
00053   }
00054   ~Private() {
00055     for ( std::vector<gpgme_new_signature_t>::iterator it = created.begin() ; it != created.end() ; ++it ) {
00056       std::free( (*it)->fpr );
00057       delete *it; *it = 0;
00058     }
00059     for ( std::vector<gpgme_invalid_key_t>::iterator it = invalid.begin() ; it != invalid.end() ; ++it ) {
00060       std::free( (*it)->fpr );
00061       delete *it; *it = 0;
00062     }
00063   }
00064 
00065   std::vector<gpgme_new_signature_t> created;
00066   std::vector<gpgme_invalid_key_t> invalid;
00067 };
00068 
00069 GpgME::SigningResult::SigningResult( gpgme_ctx_t ctx, int error )
00070   : GpgME::Result( error ), d( 0 )
00071 {
00072   if ( error || !ctx )
00073     return;
00074   gpgme_sign_result_t res = gpgme_op_sign_result( ctx );
00075   if ( !res )
00076     return;
00077   d = new Private( res );
00078   d->ref();
00079 }
00080 
00081 make_standard_stuff(SigningResult)
00082 
00083 GpgME::CreatedSignature GpgME::SigningResult::createdSignature( unsigned int idx ) const {
00084   return CreatedSignature( d, idx );
00085 }
00086 
00087 std::vector<GpgME::CreatedSignature> GpgME::SigningResult::createdSignatures() const {
00088   if ( !d )
00089     return std::vector<CreatedSignature>();
00090   std::vector<CreatedSignature> result;
00091   result.reserve( d->created.size() );
00092   for ( unsigned int i = 0 ; i < d->created.size() ; ++i )
00093     result.push_back( CreatedSignature( d, i ) );
00094   return result;
00095 }
00096 
00097 
00098 GpgME::InvalidSigningKey GpgME::SigningResult::invalidSigningKey( unsigned int idx ) const {
00099   return InvalidSigningKey( d, idx );
00100 }
00101 
00102 std::vector<GpgME::InvalidSigningKey> GpgME::SigningResult::invalidSigningKeys() const {
00103   if ( !d )
00104     return std::vector<GpgME::InvalidSigningKey>();
00105   std::vector<GpgME::InvalidSigningKey> result;
00106   result.reserve( d->invalid.size() );
00107   for ( unsigned int i = 0 ; i < d->invalid.size() ; ++i )
00108     result.push_back( InvalidSigningKey( d, i ) );
00109   return result;
00110 }
00111 
00112 
00113 
00114 
00115 GpgME::InvalidSigningKey::InvalidSigningKey( SigningResult::Private * parent, unsigned int i )
00116   : d( parent ), idx( i )
00117 {
00118   if ( d )
00119     d->ref();
00120 }
00121 
00122 GpgME::InvalidSigningKey::InvalidSigningKey() : d( 0 ), idx( 0 ) {}
00123 
00124 GpgME::InvalidSigningKey::InvalidSigningKey( const InvalidSigningKey & other )
00125   : d( other.d ), idx( other.idx )
00126 {
00127   if ( d )
00128     d->ref();
00129 }
00130 
00131 GpgME::InvalidSigningKey::~InvalidSigningKey() {
00132   if ( d )
00133     d->unref();
00134 }
00135 
00136 const GpgME::InvalidSigningKey & GpgME::InvalidSigningKey::operator=( const InvalidSigningKey & other ) {
00137   if ( this->d != other.d ) {
00138     if ( other.d )
00139       other.d->ref();
00140     if ( this->d )
00141       this->d->unref();
00142     this->d = other.d;
00143   }
00144 
00145   this->idx = other.idx;
00146   return *this;
00147 }
00148 
00149 
00150 bool GpgME::InvalidSigningKey::isNull() const {
00151   return !d || idx >= d->invalid.size() ;
00152 }
00153 
00154 const char * GpgME::InvalidSigningKey::fingerprint() const {
00155   return isNull() ? 0 : d->invalid[idx]->fpr ;
00156 }
00157 
00158 GpgME::Error GpgME::InvalidSigningKey::reason() const {
00159   return isNull() ? 0 : d->invalid[idx]->reason ;
00160 }
00161 
00162 
00163 
00164 GpgME::CreatedSignature::CreatedSignature( SigningResult::Private * parent, unsigned int i )
00165   : d( parent ), idx( i )
00166 {
00167   if ( d )
00168     d->ref();
00169 }
00170 
00171 GpgME::CreatedSignature::CreatedSignature() : d( 0 ), idx( 0 ) {}
00172 
00173 GpgME::CreatedSignature::CreatedSignature( const CreatedSignature & other )
00174   : d( other.d ), idx( other.idx )
00175 {
00176   if ( d )
00177     d->ref();
00178 }
00179 
00180 GpgME::CreatedSignature::~CreatedSignature() {
00181   if ( d )
00182     d->unref();
00183 }
00184 
00185 const GpgME::CreatedSignature & GpgME::CreatedSignature::operator=( const CreatedSignature & other ) {
00186   if ( this->d != other.d ) {
00187     if ( other.d )
00188       other.d->ref();
00189     if ( this->d )
00190       this->d->unref();
00191     this->d = other.d;
00192   }
00193 
00194   this->idx = other.idx;
00195   return *this;
00196 }
00197 
00198 
00199 bool GpgME::CreatedSignature::isNull() const {
00200   return !d || idx >= d->created.size() ;
00201 }
00202 
00203 const char * GpgME::CreatedSignature::fingerprint() const {
00204   return isNull() ? 0 : d->created[idx]->fpr ;
00205 }
00206 
00207 time_t GpgME::CreatedSignature::creationTime() const {
00208   return static_cast<time_t>( isNull() ? 0 : d->created[idx]->timestamp );
00209 }
00210 
00211 GpgME::Context::SignatureMode GpgME::CreatedSignature::mode() const {
00212   if ( isNull() )
00213     return Context::Normal;
00214   switch ( d->created[idx]->type ) {
00215   default:
00216   case GPGME_SIG_MODE_NORMAL: return Context::Normal;
00217   case GPGME_SIG_MODE_DETACH: return Context::Detached;
00218   case GPGME_SIG_MODE_CLEAR:  return Context::Clearsigned;
00219   }
00220 }
00221 
00222 unsigned int GpgME::CreatedSignature::publicKeyAlgorithm() const {
00223   return isNull() ? 0 : d->created[idx]->pubkey_algo ;
00224 }
00225 
00226 const char * GpgME::CreatedSignature::publicKeyAlgorithmAsString() const {
00227   return gpgme_pubkey_algo_name( isNull() ? (gpgme_pubkey_algo_t)0 : d->created[idx]->pubkey_algo );
00228 }
00229 
00230 unsigned int GpgME::CreatedSignature::hashAlgorithm() const {
00231   return isNull() ? 0 : d->created[idx]->hash_algo ;
00232 }
00233 
00234 const char * GpgME::CreatedSignature::hashAlgorithmAsString() const {
00235   return gpgme_hash_algo_name( isNull() ? (gpgme_hash_algo_t)0 : d->created[idx]->hash_algo );
00236 }
00237 
00238 unsigned int GpgME::CreatedSignature::signatureClass() const {
00239   return isNull() ? 0 : d->created[idx]->sig_class ;
00240 }
00241 
KDE Logo
This file is part of the documentation for libkdenetwork Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu May 3 20:17:03 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003