1 //********************************************************************************** 2 //EncryptPad Copyright 2016 Evgeny Pokhilko 3 //<http://www.evpo.net/encryptpad> 4 // 5 //This file is part of EncryptPad 6 // 7 //EncryptPad is free software: you can redistribute it and/or modify 8 //it under the terms of the GNU General Public License as published by 9 //the Free Software Foundation, either version 2 of the License, or 10 //(at your option) any later version. 11 // 12 //EncryptPad is distributed in the hope that it will be useful, 13 //but WITHOUT ANY WARRANTY; without even the implied warranty of 14 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 //GNU General Public License for more details. 16 // 17 //You should have received a copy of the GNU General Public License 18 //along with EncryptPad. If not, see <http://www.gnu.org/licenses/>. 19 //********************************************************************************** 20 #pragma once 21 22 #include <string> 23 #include "botan/secmem.h" 24 #include "key_service.h" 25 #include "packet_composer.h" 26 #include "epad_result.h" 27 28 namespace EncryptPadEncryptor 29 { 30 31 class EncryptedPlainSwitchFunctor; 32 33 class Encryptor 34 { 35 private: 36 EncryptedPlainSwitchFunctor *mEncryptedPlainSwitchFunctor; 37 EncryptPad::KeyService key_service_; 38 EncryptPad::KeyService kf_key_service_; 39 bool mPlainText; 40 std::string mX2KeyLocation; 41 std::string mLibcurlPath; 42 std::string mLibcurlParams; 43 Encryptor(const Encryptor &); 44 Encryptor & operator=(const Encryptor &); 45 public: Encryptor()46 Encryptor():mEncryptedPlainSwitchFunctor(nullptr), 47 kf_key_service_(1), mPlainText(true){} 48 GetKFKeyService()49 EncryptPad::KeyService &GetKFKeyService() 50 { 51 return kf_key_service_; 52 } 53 GetKeyService()54 EncryptPad::KeyService &GetKeyService() 55 { 56 return key_service_; 57 } 58 59 void SetPassphrase(const char *pwd, EncryptPad::PacketMetadata *metadata = nullptr); 60 void SetIsPlainText(); 61 bool GetIsPlainText(); 62 bool UnusedKeysExist(); 63 const std::string &GetX2KeyLocation() const; 64 void SetEncryptedPlainSwitchFunctor(EncryptedPlainSwitchFunctor *functor); 65 void ClearKFPassphrase(); 66 bool HasKFPassphrase() const; 67 void SetLibcurlPath(const std::string &path); 68 void SetLibcurlParams(const std::string ¶ms); 69 70 // Saves content to fileName 71 // persists the x2 key location in fileName if persistX2KeyLocation 72 EncryptPad::EpadResult Save(const std::string &fileName, const Botan::SecureVector<Botan::byte> &content, 73 const std::string &x2KeyLocation = "", bool persistX2KeyLocation = false, 74 EncryptPad::PacketMetadata *metadata = nullptr, const std::string *kf_passphrase = nullptr 75 ); 76 77 EncryptPad::EpadResult Load(const std::string &fileName, Botan::SecureVector<Botan::byte> &content, 78 const std::string &x2KeyLocation = "", const std::string *passphrase = nullptr, 79 EncryptPad::PacketMetadata *metadata = nullptr, const std::string *kf_passphrase = nullptr 80 ); 81 82 }; 83 84 class EncryptedPlainSwitchFunctor 85 { 86 public: EncryptedPlainSwitchFunctor()87 EncryptedPlainSwitchFunctor() 88 { 89 } 90 ~EncryptedPlainSwitchFunctor()91 virtual ~EncryptedPlainSwitchFunctor() 92 { 93 } 94 95 virtual void EncryptedPlainSwitchChange(bool encrypted) = 0; 96 private: 97 EncryptedPlainSwitchFunctor(const EncryptedPlainSwitchFunctor &); 98 EncryptedPlainSwitchFunctor & operator=(const EncryptedPlainSwitchFunctor &); 99 }; 100 101 } 102 103