summaryrefslogtreecommitdiff
path: root/IOFileClass/FileManIOFile.cpp
diff options
context:
space:
mode:
authormanzerbredes <loic.guegan_secondary@yahoo.fr>2015-03-11 17:21:24 +0400
committermanzerbredes <loic.guegan_secondary@yahoo.fr>2015-03-11 17:21:24 +0400
commit34b47f8e08eff519f6c8372f2e4ce5b24267614c (patch)
tree4aebab48876d857eb24117a104c9348c508f5d82 /IOFileClass/FileManIOFile.cpp
parentecda75a273c653eeb42bd0449831a250433e05f0 (diff)
Arrange FileManIOFile class
Diffstat (limited to 'IOFileClass/FileManIOFile.cpp')
-rw-r--r--IOFileClass/FileManIOFile.cpp35
1 files changed, 14 insertions, 21 deletions
diff --git a/IOFileClass/FileManIOFile.cpp b/IOFileClass/FileManIOFile.cpp
index 424d704..bee2ebe 100644
--- a/IOFileClass/FileManIOFile.cpp
+++ b/IOFileClass/FileManIOFile.cpp
@@ -74,40 +74,32 @@ void FileManIOFile::read(std::string key){
void FileManIOFile::write(std::string key,std::string data){
AESCrypt aes;
- HASHCrypt hash;
std::string dataEncrypted;
dataEncrypted=aes.encrypt(key, data);
+ this->writeRoutine(data, dataEncrypted);
- byte digest[16];
- hash.getMD5_128(data, digest, sizeof(digest));
-
-
- std::ofstream file;
- file.open(this->filename, std::ios::out | std::ios::binary);
-
- file.write((char *) digest,sizeof(digest));
-
-
- file.write(dataEncrypted.c_str(), dataEncrypted.size());
-
-
-
- file.close();
-
- this->data=data;
}
void FileManIOFile::write(std::string data){
-
+ if(not(this->readable)){
+ std::cout << "Can't write data without key (read it before) !" << std::endl;
+ std::exit(EXIT_FAILURE);
+ }
AESCrypt aes;
- HASHCrypt hash;
std::string dataEncrypted;
dataEncrypted=aes.encrypt(this->key, data);
+ this->writeRoutine(data, dataEncrypted);
+
+}
+
+
+void FileManIOFile::writeRoutine(std::string data, std::string dataEncrypted){
+ HASHCrypt hash;
byte digest[16];
hash.getMD5_128(data, digest, sizeof(digest));
@@ -126,9 +118,10 @@ void FileManIOFile::write(std::string data){
file.close();
this->data=data;
-
}
+
+
std::string FileManIOFile::getData(){
return this->data;
}