It compiles no encript

This commit is contained in:
Nikola Petrov
2024-01-14 21:43:49 +01:00
parent 3935c3f34e
commit 36de6ec412
19 changed files with 500 additions and 406 deletions

View File

@@ -1,45 +0,0 @@
#pragma once
struct LoginInfoPointer;
class Buffer;
class Cryptography;
#include <string>
#include <optional>
enum class Arg
{
Get, // get password for label
Generate, // generate password for label
List, // list all labels
Delete, // delete password for label
Print_all_p, // print all passwords
Input, // input password for label
Change, // change main password
Show, // show password for label
Error, // error
Username, // update username
Name, // update label name
File, // select save file
};
Arg get_args(int argc, char** argv, char** label);
std::optional<LoginInfoPointer> arg_get(Buffer& decrypted_buffer, const char* label);
std::optional<LoginInfoPointer> arg_new_password(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto, bool generate);
void arg_username(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto);
void arg_label_name(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto);
void arg_list(Buffer& decrypted_buffer);
void arg_delete(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto);
void arg_print_all_p(Buffer& decrypted_buffer, std::string& user_pass);
void arg_change(Buffer& decrypted_buffer, Buffer& encrypted_buffer, std::string& user_pass, Cryptography& crypto);
void arg_show(Buffer& decrypted_buffer, const char* label);
void arg_file(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto, std::string& save_location_path);

48
include/arg_func.hpp Normal file
View File

@@ -0,0 +1,48 @@
#ifndef ARG_FUNC_HPP
#define ARG_FUNC_HPP
struct LoginInfoPointer;
class Buffer;
class Cryptography;
#include <string>
#include <optional>
enum class Arg
{
Get, // get password for label
Generate, // generate password for label
List, // list all labels
Delete, // delete password for label
Print_all_p, // print all passwords
Input, // input password for label
Change, // change main password
Show, // show password for label
Error, // error
Username, // update username
Name, // update label name
File, // select save file
};
Arg get_args(int argc, char **argv, char **label);
std::optional<LoginInfoPointer> arg_get(Buffer &decrypted_buffer, const char *label);
std::optional<LoginInfoPointer> arg_new_password(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *label, Cryptography &crypto, bool generate);
void arg_username(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *label, Cryptography &crypto);
void arg_label_name(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *label, Cryptography &crypto);
void arg_list(Buffer &decrypted_buffer);
void arg_delete(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *label, Cryptography &crypto);
void arg_print_all_p(Buffer &decrypted_buffer, std::string &user_pass);
void arg_change(Buffer &decrypted_buffer, Buffer &encrypted_buffer, std::string &user_pass, Cryptography &crypto);
void arg_show(Buffer &decrypted_buffer, const char *label);
void arg_file(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *label, Cryptography &crypto, std::string &save_location_path);
#endif

View File

@@ -1,11 +1,13 @@
#pragma once
#ifndef BUFFER_HPP
#define BUFFER_HPP
#include <cstdint>
#include <string>
class Buffer
{
public:
uint8_t* buffer = nullptr;
uint8_t *buffer = nullptr;
size_t taken = 0;
size_t size = 0;
std::string file_path;
@@ -14,17 +16,17 @@ public:
Buffer();
~Buffer();
bool resize(size_t new_size);
int add_end(uint8_t* data, size_t data_size);
int add_middle(uint8_t* data, size_t data_size, size_t index);
int add_end(uint8_t *data, size_t data_size);
int add_middle(uint8_t *data, size_t data_size, size_t index);
// Removes data from buffer without checking if it's in the buffer
void remove_fast(uint8_t* data, size_t data_size);
void remove_fast(uint8_t *data, size_t data_size);
void remove(size_t index, size_t data_size);
size_t find(uint8_t* data, size_t data_size);
size_t find(uint8_t *data, size_t data_size);
void remove(uint8_t* data, size_t data_size);
void remove(uint8_t *data, size_t data_size);
void clear() { taken = 0; }
@@ -33,5 +35,6 @@ public:
bool load_from_file();
bool load_from_file(std::string file_path);
};
};
#endif

View File

@@ -1,23 +0,0 @@
#pragma once
#include <cstdint>
struct evp_cipher_ctx_st;
typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX;
class Buffer;
class Cryptography
{
public:
Cryptography(const char* password, size_t size);
~Cryptography();
bool encrypt(Buffer* plain, Buffer* encrypted);
bool decrypt(Buffer* encrypted, Buffer* decrypted);
bool generate_key_and_iv_from_password(const char* password, size_t size);
private:
uint8_t key[32] = { 0 };
uint8_t iv[16] = { 0 };
EVP_CIPHER_CTX* ctx = nullptr;
bool handleErrors();
};

27
include/cryptography.hpp Normal file
View File

@@ -0,0 +1,27 @@
#ifndef CRYPTOGRAPHY_HPP
#define CRYPTOGRAPHY_HPP
#include <cstdint>
struct evp_cipher_ctx_st;
typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX;
class Buffer;
class Cryptography
{
public:
Cryptography(const char *password, size_t size);
~Cryptography();
bool encrypt(Buffer *plain, Buffer *encrypted);
bool decrypt(Buffer *encrypted, Buffer *decrypted);
bool generate_key_and_iv_from_password(const char *password, size_t size);
private:
uint8_t key[32] = {0};
uint8_t iv[16] = {0};
EVP_CIPHER_CTX *ctx = nullptr;
bool handleErrors();
};
#endif

View File

@@ -1,35 +0,0 @@
#pragma once
#include <string>
class Buffer;
struct LoginInfo
{
uint32_t label;
uint32_t username;
uint32_t password;
};
struct LoginInfoPointer
{
const char* label;
const char* username;
const char* password;
};
struct Index
{
uint32_t count;
uint32_t offset;
};
int find_logininfo_in_buffer(Buffer& buffer, const char* label);
void delete_logininfo_from_buffer(Buffer& buffer, int index_of_pass);
void add_logininfo_to_buffer(Buffer& buffer, const char* label, const char* username, const char* password);
LoginInfoPointer get_logininfo_pointer_from_buffer(Buffer& buffer, int index_of_pass);
void generate_password(std::string& password, int len);

38
include/func.hpp Normal file
View File

@@ -0,0 +1,38 @@
#ifndef FUNC_HPP
#define FUNC_HPP
#include <string>
class Buffer;
struct LoginInfo
{
uint32_t label;
uint32_t username;
uint32_t password;
};
struct LoginInfoPointer
{
const char *label;
const char *username;
const char *password;
};
struct Index
{
uint32_t count;
uint32_t offset;
};
int find_logininfo_in_buffer(Buffer &buffer, const char *label);
void delete_logininfo_from_buffer(Buffer &buffer, int index_of_pass);
void add_logininfo_to_buffer(Buffer &buffer, const char *label, const char *username, const char *password);
LoginInfoPointer get_logininfo_pointer_from_buffer(Buffer &buffer, int index_of_pass);
void generate_password(std::string &password, int len);
#endif

View File

@@ -1,13 +0,0 @@
#pragma once
enum class Glob_Result {
OOM_ERROR,
ENCODING_ERROR,
SYNTAX_ERROR,
UNMATCHED,
MATCHED,
};
// https://github.com/tsoding/glob.h
Glob_Result glob(const char* pattern, const char* text);

16
include/glob.hpp Normal file
View File

@@ -0,0 +1,16 @@
#ifndef GLOB_HPP
#define GLOB_HPP
enum class Glob_Result
{
OOM_ERROR,
ENCODING_ERROR,
SYNTAX_ERROR,
UNMATCHED,
MATCHED,
};
// https://github.com/tsoding/glob.h
Glob_Result glob(const char *pattern, const char *text);
#endif

11
include/sys.hpp Normal file
View File

@@ -0,0 +1,11 @@
#ifndef WIN_HPP
#define WIN_HPP
#include <optional>
#include <string>
bool put_data_on_clipboard(const char *text);
std::string get_user_password();
std::optional<std::string> get_save_path();
#endif

View File

@@ -1,6 +0,0 @@
#pragma once
#include <optional>
bool put_data_on_clipboard(const char* text);
std::string get_user_password();
std::optional<std::string> get_save_path();