forgetIt/IOFileClass/FileManIOFile.hpp

134 lines
2.7 KiB
C++
Raw Normal View History

/**
* @file FileManIOFile.hpp
* @brief FileManIOFile class definitions
* @author manzerbredes
* @date 9 Mars 2015
*
* Contain all definitions of FileManIOFile class.
*
*/
2015-03-11 09:53:59 +04:00
#ifndef __FileManIOFile__
#define __FileManIOFile__
2015-03-13 15:39:56 +04:00
//----- std -----
#include <iostream>
#include <string>
#include <fstream>
2015-03-13 15:39:56 +04:00
//----- class -----
#include "HASHCrypt.hpp"
#include "AESCrypt.hpp"
2015-03-13 15:39:56 +04:00
/**
* @class FileManIOFile FileManIOFile.hpp "/CryptClass/FileManIOFile.hpp"
2015-03-13 15:39:56 +04:00
* @brief Class for quick open and close encrypted files.
* @author manzerbredes
*
* -----File organisation-----
*
2015-03-13 15:39:56 +04:00
* 16 first bytes : md5 of decrypted data
* Rest of the file : data encrypted (ASE for now)
*
2015-03-13 15:39:56 +04:00
* \bug Need check if file exist and can be opened
*/
class FileManIOFile {
public:
2015-03-13 15:39:56 +04:00
//Constructor
FileManIOFile(std::string filename);
2015-03-13 15:39:56 +04:00
//Destructor
~FileManIOFile();
2015-03-13 15:39:56 +04:00
/**
* @brief Read encrypted file.
*
* @param key : key to encrypt data
*
* Read data from "filename" attribute.
2015-03-13 15:39:56 +04:00
* If file fully decrypted, readable var switch to true,
* and key saved in key attribute (before been crypted with SHA-256 algorithm).
*
*/
void read(std::string key);
2015-03-11 17:21:24 +04:00
/**
2015-03-11 17:21:24 +04:00
* @brief Write data in encrypted file.
*
* @param key : key to encrypt data
2015-03-11 17:21:24 +04:00
* @param data : data to write
*
2015-03-13 15:39:56 +04:00
* Write the file with or without key.
2015-03-11 17:21:24 +04:00
* To write data without key, you need to read it before (to save the key
2015-03-13 15:39:56 +04:00
* in attribute key).
*
*/
void write(std::string key, std::string data);
void write(std::string data);
/**
* @brief True if file fully decrypted.
*
2015-03-13 15:39:56 +04:00
* @return readable attribute
*
* Return "readable" attribute.
*
*/
bool isReadable();
/**
* @brief Get data attribute.
*
2015-03-13 15:39:56 +04:00
* @return data attribute.
*
* **Warning** if data not fully decrypted (readable!=true),
2015-03-13 15:39:56 +04:00
* data will be unreadable (unparsable).
*
*/
std::string getData();
2015-03-13 15:39:56 +04:00
private:
2015-03-13 15:39:56 +04:00
/**
* @brief Write data in encrypted file.
*
* @param data : data to write (for MD5)
* @param dataEncrypted : data to write
*
* Write encryptedData to filename
*
*/
void writeRoutine(std::string data, std::string dataEncrypted);
2015-03-13 15:39:56 +04:00
//Attributes:
2015-03-13 15:39:56 +04:00
AESCrypt aes; ///< AES instance
2015-03-13 15:39:56 +04:00
HASHCrypt hash; ///< HASH instance
2015-03-13 15:39:56 +04:00
std::string filename; ///< Filename attribute
2015-03-13 15:39:56 +04:00
std::string data; ///< Data attribute
2015-03-13 15:39:56 +04:00
bool readable; ///< Readable attribute
byte key[32]; ///< Key in SHA-256
};
2015-03-11 09:53:59 +04:00
#endif