add editorconfig

pass on al file to reformat
This commit is contained in:
Antoine 2020-04-27 02:01:38 +02:00
rodzic 34bc39b252
commit 0d28f4f519
7 zmienionych plików z 53 dodań i 26 usunięć

27
.editorconfig Normal file
Wyświetl plik

@ -0,0 +1,27 @@
# formatting rule for this project
root = true
[*]
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
[*.cpp]
max_line_length = 119
# Ignored paths
[lib/**]
indent_size = unset
indent_style = unset
end_of_line = unset
insert_final_newline = unset
charset = unset
trim_trailing_whitespace = unset
# Makefiles always use tabs for indentation
[Makefile]
indent_style = tab

18
aes.hpp
Wyświetl plik

@ -38,7 +38,7 @@ private:
std::string generateNewFilename();
std::string getFilePath();
std::string extension = ".new";
public:
aes() {};
aes(std::string _filename);
@ -68,7 +68,7 @@ aes::aes(std::string _filename) {
aes& aes::clone(const aes& _e) {
filename = _e.filename;
setAesKey(_e.aesKey);
setAesIV(_e.aesIV);
@ -135,7 +135,7 @@ int aes::readFile(unsigned char** file, const char* filename) {
fprintf(stderr, "Failed to allocate memory\n");
exit(1);
}
// Read the file into the buffer
size_t bytesRead = fread(*file, 1, fileLength, fd);
@ -194,19 +194,19 @@ void aes::setAesKey(const unsigned char* _aesKey) {
void aes::setAesIV(const unsigned char* _aesIV) {
if(aesIV == NULL)
aesIV = (unsigned char*)malloc(AES_KEYLEN/8);
aesIV = (unsigned char*)malloc(AES_KEYLEN/8);
memcpy(aesIV , _aesIV, AES_KEYLEN/8);
}
unsigned char* aes::getAesKey() {
unsigned char* res = (unsigned char*)malloc(AES_KEYLEN/8);
unsigned char* res = (unsigned char*)malloc(AES_KEYLEN/8);
memcpy(res, aesKey, AES_KEYLEN/8);
return res;
}
unsigned char* aes::getAesIV() {
unsigned char* res = (unsigned char*)malloc(AES_KEYLEN/8);
unsigned char* res = (unsigned char*)malloc(AES_KEYLEN/8);
memcpy(res, aesIV, AES_KEYLEN/8);
return res;
}
@ -214,7 +214,7 @@ unsigned char* aes::getAesIV() {
std::string aes::PrintAesKey() {
std::stringstream ss;
std::string res;
res = "aesKey : ";
for (int i = 0; i < 32; i++) {
ss << std::hex;
@ -226,7 +226,7 @@ std::string aes::PrintAesKey() {
void aes::importKey(const char* filename) {
Json::Value root;
std::ifstream keyfile(filename, std::ifstream::binary);
keyfile >> root;
@ -256,4 +256,4 @@ void aes::clear_all() {
free(aesKey);
}
#endif
#endif

Wyświetl plik

@ -49,7 +49,7 @@ int crypt::aesEncrypt(const unsigned char *msg, size_t msgLen, unsigned char **e
*encMsg = (unsigned char*)malloc(msgLen + AES_BLOCK_SIZE);
if(encMsg == NULL) return FAILURE;
if(!EVP_EncryptInit_ex(aesEncryptCtx, EVP_aes_256_cbc(), NULL, aes::aesKey, aes::aesIV)) {
return FAILURE;
}

Wyświetl plik

@ -9,7 +9,7 @@ private:
public:
decrypt(std::string filename, unsigned char* aesKey=0, unsigned char* aesIV=0);
decrypt(const decrypt& a);
void init_all(bool initSuper=true);
int aesDecrypt(unsigned char *encMsg, size_t encMsgLen, unsigned char** decMsg);
~decrypt();
@ -55,7 +55,7 @@ int decrypt::aesDecrypt(unsigned char *encMsg, size_t encMsgLen, unsigned char *
*decMsg = (unsigned char*)malloc(encMsgLen);
if(*decMsg == NULL) return FAILURE;
if(!EVP_DecryptInit_ex(aesDecryptCtx, EVP_aes_256_cbc(), NULL, aes::aesKey, aes::aesIV)) {
return FAILURE;
}

Wyświetl plik

@ -18,11 +18,11 @@ int main(int argc, char* argv[]) {
// readFile fait l'aloccation mémoire !!! pensé au free
size_t fileLength = O->readFile(&file);
printf("%d bytes to be encrypted\n", (int)fileLength);
// Encrypt the file
unsigned char *encryptedFile;
int encryptedFileLength;
if((encryptedFileLength = (dynamic_cast<crypt*>(O))->aesEncrypt((const unsigned char*)file, fileLength, &encryptedFile) ) == -1) {
fprintf(stderr, "Encryption failed\n");
return 1;
@ -51,7 +51,7 @@ int main(int argc, char* argv[]) {
fprintf(stderr, "Decryption failed\n");
return 1;
}
printf("%d bytes decrypted\n", (int)decryptedFileLength);
std::cerr << O2->PrintAesKey() << std::endl;
// Write the decrypted file to its own file
@ -64,4 +64,4 @@ int main(int argc, char* argv[]) {
delete O;
return 0;
}
}

Wyświetl plik

@ -12,16 +12,16 @@ int main(int argc, char* argv[]) {
// Read the file to encrypt
unsigned char* file;
//******************************************************************* while a rajouté pour les gros fichier
// readFile fait l'aloccation mémoire !!! pensé au free
//******************************************************************* while a rajouté pour les gros fichier
// readFile made memory allocation !!! think to free arg
size_t fileLength = O->readFile(&file);
printf("%d bytes to be encrypted\n", (int)fileLength);
// Encrypt the file
unsigned char *encryptedFile;
int encryptedFileLength;
if((encryptedFileLength = (dynamic_cast<crypt*>(O))->aesEncrypt((const unsigned char*)file, fileLength, &encryptedFile) ) == -1) {
fprintf(stderr, "Encryption failed\n");
return 1;
@ -40,8 +40,8 @@ int main(int argc, char* argv[]) {
free(encryptedFile);
free(file);
//******************************************************************
//******************************************************************
delete O;
return 0;
}
}

Wyświetl plik

@ -6,7 +6,7 @@ int main(int argc, char* argv[]) {
std::cerr << "An input file is missing.\n ./Decrypt.ex fileToDecrypt AeskeyForDecrypt\n";
return 1;
}
size_t fileLength;
unsigned char* fileEncrypted;
unsigned char* decryptedFile;
@ -22,7 +22,7 @@ int main(int argc, char* argv[]) {
fprintf(stderr, "Decryption failed\n");
return 1;
}
printf("%d bytes decrypted\n", (int)decryptedFileLength);
std::cerr << O2->PrintAesKey() << std::endl;
@ -35,4 +35,4 @@ int main(int argc, char* argv[]) {
delete O2;
return 0;
}
}