libkdenetwork Library API Documentation

encryptionresult.cpp

00001 /* encryptionresult.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/encryptionresult.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::EncryptionResult::Private : public GpgME::Shared {
00035 public:
00036   Private( const gpgme_encrypt_result_t r ) : Shared() {
00037     if ( !r )
00038       return;
00039     for ( gpgme_invalid_key_t ik = r->invalid_recipients ; ik ; ik = ik->next ) {
00040       gpgme_invalid_key_t copy = new _gpgme_invalid_key( *ik );
00041       if ( ik->fpr )
00042     copy->fpr = strdup( ik->fpr );
00043       copy->next = 0;
00044       invalid.push_back( copy );
00045     }
00046   }
00047   ~Private() {
00048     for ( std::vector<gpgme_invalid_key_t>::iterator it = invalid.begin() ; it != invalid.end() ; ++it ) {
00049       std::free( (*it)->fpr );
00050       delete *it; *it = 0;
00051     }
00052   }
00053 
00054   std::vector<gpgme_invalid_key_t> invalid;
00055 };
00056 
00057 GpgME::EncryptionResult::EncryptionResult( gpgme_ctx_t ctx, int error )
00058   : GpgME::Result( error ), d( 0 )
00059 {
00060   if ( error || !ctx )
00061     return;
00062   gpgme_encrypt_result_t res = gpgme_op_encrypt_result( ctx );
00063   if ( !res )
00064     return;
00065   d = new Private( res );
00066   d->ref();
00067 }
00068 
00069 make_standard_stuff(EncryptionResult)
00070 
00071 
00072 unsigned int GpgME::EncryptionResult::numInvalidRecipients() const {
00073   return d ? d->invalid.size() : 0 ;
00074 }
00075 
00076 GpgME::InvalidRecipient GpgME::EncryptionResult::invalidEncryptionKey( unsigned int idx ) const {
00077   return InvalidRecipient( d, idx );
00078 }
00079 
00080 std::vector<GpgME::InvalidRecipient> GpgME::EncryptionResult::invalidEncryptionKeys() const {
00081   if ( !d )
00082     return std::vector<GpgME::InvalidRecipient>();
00083   std::vector<GpgME::InvalidRecipient> result;
00084   result.reserve( d->invalid.size() );
00085   for ( unsigned int i = 0 ; i < d->invalid.size() ; ++i )
00086     result.push_back( InvalidRecipient( d, i ) );
00087   return result;
00088 }
00089 
00090 
00091 
00092 
00093 GpgME::InvalidRecipient::InvalidRecipient( EncryptionResult::Private * parent, unsigned int i )
00094   : d( parent ), idx( i )
00095 {
00096   if ( d )
00097     d->ref();
00098 }
00099 
00100 GpgME::InvalidRecipient::InvalidRecipient() : d( 0 ), idx( 0 ) {}
00101 
00102 GpgME::InvalidRecipient::InvalidRecipient( const InvalidRecipient & other )
00103   : d( other.d ), idx( other.idx )
00104 {
00105   if ( d )
00106     d->ref();
00107 }
00108 
00109 GpgME::InvalidRecipient::~InvalidRecipient() {
00110   if ( d )
00111     d->unref();
00112 }
00113 
00114 const GpgME::InvalidRecipient & GpgME::InvalidRecipient::operator=( const InvalidRecipient & other ) {
00115   if ( this->d != other.d ) {
00116     if ( other.d )
00117       other.d->ref();
00118     if ( this->d )
00119       this->d->unref();
00120     this->d = other.d;
00121   }
00122 
00123   this->idx = other.idx;
00124   return *this;
00125 }
00126 
00127 
00128 bool GpgME::InvalidRecipient::isNull() const {
00129   return !d || idx >= d->invalid.size() ;
00130 }
00131 
00132 const char * GpgME::InvalidRecipient::fingerprint() const {
00133   return isNull() ? 0 : d->invalid[idx]->fpr ;
00134 }
00135 
00136 GpgME::Error GpgME::InvalidRecipient::reason() const {
00137   return isNull() ? 0 : d->invalid[idx]->reason ;
00138 }
00139 
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:16:58 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003