Renamed ghettocryptwrapper class to gcryptwrapper

This commit is contained in:
Leonetienne 2022-05-16 22:50:52 +02:00
parent 13a7abd82d
commit b998a51e11
No known key found for this signature in database
GPG Key ID: C33879CD92E9708C
4 changed files with 18 additions and 17 deletions

View File

@ -1,5 +1,5 @@
#include <iostream>
#include <GCrypt/GhettoCryptWrapper.h>
#include <GCrypt/GCryptWrapper.h>
#include <GCrypt/SecureBitset.h>
#include <GCrypt/Util.h>
#include <GCrypt/InitializationVector.h>
@ -14,11 +14,11 @@ void ExampleString() {
std::cout << input << std::endl;
// Encrypt
const std::string encrypted = GhettoCryptWrapper::EncryptString(input, "password1");
const std::string encrypted = GCryptWrapper::EncryptString(input, "password1");
std::cout << encrypted << std::endl;
// Decrypt
const std::string decrypted = GhettoCryptWrapper::DecryptString(encrypted, "password1");
const std::string decrypted = GCryptWrapper::DecryptString(encrypted, "password1");
std::cout << decrypted << std::endl;
return;
@ -28,10 +28,10 @@ void ExampleFiles() {
std::cout << "Example on how to encrypt & decrypt any file:" << std::endl;
// Encrypt
GhettoCryptWrapper::EncryptFile("main.cpp", "main.cpp.crypt", "password1");
GCryptWrapper::EncryptFile("main.cpp", "main.cpp.crypt", "password1");
// Decrypt
GhettoCryptWrapper::DecryptFile("main.cpp.crypt", "main.cpp.clear", "password1");
GCryptWrapper::DecryptFile("main.cpp.crypt", "main.cpp.clear", "password1");
return;
}

View File

@ -5,7 +5,7 @@ namespace Leonetienne::GCrypt {
/** This class is a wrapper to make working with the GhettoCipher
* super easy with a python-like syntax
*/
class GhettoCryptWrapper {
class GCryptWrapper {
public:
//! Will encrypt a string and return it hexadecimally encoded.
static std::string EncryptString(const std::string& cleartext, const std::string& password);
@ -27,6 +27,7 @@ namespace Leonetienne::GCrypt {
private:
// No instanciation! >:(
GhettoCryptWrapper();
GCryptWrapper();
};
}

View File

@ -1,10 +1,10 @@
#include "GCrypt/GhettoCryptWrapper.h"
#include "GCrypt/GCryptWrapper.h"
#include "GCrypt/Cipher.h"
#include "GCrypt/Util.h"
namespace Leonetienne::GCrypt {
std::string GhettoCryptWrapper::EncryptString(const std::string& cleartext, const std::string& password) {
std::string GCryptWrapper::EncryptString(const std::string& cleartext, const std::string& password) {
// Instanciate our cipher and supply a key
const Block key = PasswordToKey(password);
Cipher cipher(key);
@ -22,7 +22,7 @@ namespace Leonetienne::GCrypt {
return ciphertext;
}
std::string GhettoCryptWrapper::DecryptString(const std::string& ciphertext, const std::string& password) {
std::string GCryptWrapper::DecryptString(const std::string& ciphertext, const std::string& password) {
// Instanciate our cipher and supply a key
const Block key = PasswordToKey(password);
Cipher cipher(key);
@ -40,7 +40,7 @@ namespace Leonetienne::GCrypt {
return cleartext;
}
bool GhettoCryptWrapper::EncryptFile(const std::string& filename_in, const std::string& filename_out, const std::string& password, bool printProgressReport) {
bool GCryptWrapper::EncryptFile(const std::string& filename_in, const std::string& filename_out, const std::string& password, bool printProgressReport) {
try {
// Read the file to bits
const Flexblock cleartext_bits = ReadFileToBits(filename_in);
@ -62,7 +62,7 @@ namespace Leonetienne::GCrypt {
}
}
bool GhettoCryptWrapper::DecryptFile(const std::string& filename_in, const std::string& filename_out, const std::string& password, bool printProgressReport) {
bool GCryptWrapper::DecryptFile(const std::string& filename_in, const std::string& filename_out, const std::string& password, bool printProgressReport) {
try {
// Read the file to bits
const Flexblock ciphertext_bits = ReadFileToBits(filename_in);

View File

@ -1,4 +1,4 @@
#include <GCrypt/GhettoCryptWrapper.h>
#include <GCrypt/GCryptWrapper.h>
#include <GCrypt/Flexblock.h>
#include <GCrypt/Util.h>
#include "Catch2.h"
@ -17,10 +17,10 @@ TEST_CASE(__FILE__"/Encrypting and decrypting strings works", "[Wrapper]") {
std::string decrypted;
// Encryption
ciphertext = GhettoCryptWrapper::EncryptString(plaintext, password);
ciphertext = GCryptWrapper::EncryptString(plaintext, password);
// Decryption
decrypted = GhettoCryptWrapper::DecryptString(ciphertext, password);
decrypted = GCryptWrapper::DecryptString(ciphertext, password);
// Assertion
REQUIRE(plaintext == decrypted);
@ -40,10 +40,10 @@ TEST_CASE(__FILE__"/Encrypting and decrypting files works", "[Wrapper]") {
// Encryption
GhettoCryptWrapper::EncryptFile(filename_plain, filename_encrypted, password);
GCryptWrapper::EncryptFile(filename_plain, filename_encrypted, password);
// Decryption
GhettoCryptWrapper::DecryptFile(filename_encrypted, filename_decrypted, password);
GCryptWrapper::DecryptFile(filename_encrypted, filename_decrypted, password);
// Read in both the base, and the decrypted file
const Flexblock plainfile = ReadFileToBits(filename_plain);