Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
crypto_asym.hpp
Go to the documentation of this file.
00001 //*********************************************************************/
00002 // dar - disk archive - a backup/restoration program
00003 // Copyright (C) 2002-2052 Denis Corbin
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 // to contact the author : http://dar.linux.free.fr/email.html
00020 /*********************************************************************/
00021 
00025 
00026 #ifndef CRYPTO_ASYM_HPP
00027 #define CRYPTO_ASYM_HPP
00028 
00029 extern "C"
00030 {
00031 #if HAVE_GPGME_H
00032 #include <gpgme.h>
00033 #endif
00034 }
00035 
00036 #include "../my_config.h"
00037 #include "generic_file.hpp"
00038 #include "generic_file_overlay_for_gpgme.hpp"
00039 #include "erreurs.hpp"
00040 #include "mem_ui.hpp"
00041 #include "crypto.hpp"
00042 
00043 #include <list>
00044 
00045 namespace libdar
00046 {
00049 
00050     class crypto_asym : public mem_ui
00051     {
00052     public:
00053 
00055     crypto_asym(const user_interaction & ui) : mem_ui(ui) { build_context(); has_signatories = false; };
00056 
00058     ~crypto_asym() { release_context(); };
00059 
00061     crypto_asym(const crypto_asym & ref): mem_ui(ref) { throw SRC_BUG; };
00062 
00064     const crypto_asym & operator = (const crypto_asym & ref) { throw SRC_BUG; };
00065 
00067     void set_signatories(const std::vector<std::string> & signatories);
00068 
00075     void encrypt(const std::vector<std::string> & recipients_email, generic_file & clear, generic_file & ciphered);
00076 
00082     void decrypt(generic_file & ciphered, generic_file & clear);
00083 
00086     const std::list<signator> & verify() const { return signing_result; };
00087 
00089     user_interaction & get_ui() const { return mem_ui::get_ui(); };
00090 
00091     private:
00092     bool has_signatories;
00093     std::list<signator> signing_result;
00094 #if GPGME_SUPPORT
00095     gpgme_ctx_t context;                     //< GPGME context
00096 
00097     void release_context() { gpgme_release(context); };
00098     void build_key_list(const std::vector<std::string> & recipients_email,  //< list of email to find a key for
00099                 gpgme_key_t * & ciphering_keys,                     //< resulting nullptr terminated list of keys
00100                 bool signatories);                                  //< false if email key need encryption capability, true for signing
00101     void release_key_list(gpgme_key_t * & ciphering_keys);
00102     void fill_signing_result();
00103 #else
00104     void release_context() {};
00105 #endif
00106 
00107     void build_context();
00108     };
00109 
00111 
00112 } // end of namespace
00113 
00114 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines