API
This commit is contained in:
parent
a198642207
commit
33b0878a81
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -1,3 +1,4 @@
|
||||
{
|
||||
"makefile.configureOnOpen": false
|
||||
"makefile.configureOnOpen": false,
|
||||
"C_Cpp.errorSquiggles": "disabled"
|
||||
}
|
||||
14
DOCS.md
14
DOCS.md
@ -5,6 +5,7 @@
|
||||
- [Создание пользователя и шифрование](#создание-пользователя-и-шифрование)
|
||||
- [Чтение данных пользователя и расшифровка](#чтение-данных-пользователя-и-расшифровка)
|
||||
- [Опции команды](#опции-команды)
|
||||
- [API](#api)
|
||||
## Установка
|
||||
Зависимости для компиляции:
|
||||
- GCC
|
||||
@ -67,4 +68,17 @@ vipre-cryptor ИМЯ_ФАЙЛА_С_КЛЮЧОМ.sig --user-data ИМЯ_ПОЛЬ
|
||||
# Опции "--file-input" и "--file-out" можно сократить до "--file" или просто "-f"
|
||||
"--help" - "-h"
|
||||
"--version" - "-v"
|
||||
```
|
||||
## API
|
||||
У библиотеки есть **API**:
|
||||
```c
|
||||
/* Пример */
|
||||
#include "vipre-manager.h"
|
||||
|
||||
int main(void) {
|
||||
__set_api_mode("admin", "1234", "signature_key");
|
||||
__create_sig("api_example_key.sig");
|
||||
__create_user("api_example_key.sig", "api_example_user.bin", "example.txt");
|
||||
__read_user("api_example_key.sig", "api_example_user.bin", "example_out.txt");
|
||||
}
|
||||
```
|
||||
BIN
api_example
Executable file
BIN
api_example
Executable file
Binary file not shown.
9
api_example.c
Normal file
9
api_example.c
Normal file
@ -0,0 +1,9 @@
|
||||
/* Пример API */
|
||||
#include "vipre-manager.h"
|
||||
|
||||
int main(void) {
|
||||
__set_api_mode("admin", "1234", "signature_key");
|
||||
__create_sig("api_example_key.sig");
|
||||
__create_user("api_example_key.sig", "api_example_user.bin", "example.txt");
|
||||
__read_user("api_example_key.sig", "api_example_user.bin", "example_out.txt");
|
||||
}
|
||||
BIN
api_example_key.sig
Normal file
BIN
api_example_key.sig
Normal file
Binary file not shown.
BIN
api_example_user.bin
Normal file
BIN
api_example_user.bin
Normal file
Binary file not shown.
BIN
vipre-cryptor
BIN
vipre-cryptor
Binary file not shown.
101
vipre-manager.h
101
vipre-manager.h
@ -35,8 +35,22 @@
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
char* __YEFWHD_api_login = NULL;
|
||||
char* __YEFWHD_api_password = NULL;
|
||||
char* __YEFWHD_api_datakey = NULL;
|
||||
char __YEFWHD_data_type = '\0';
|
||||
|
||||
#define VIPRE_API_MODE 'A'
|
||||
|
||||
typedef FILE* file_t;
|
||||
|
||||
void __set_api_mode(char* login, char* password, char* data_key) {
|
||||
__YEFWHD_api_login = login;
|
||||
__YEFWHD_api_password = password;
|
||||
__YEFWHD_api_datakey = data_key;
|
||||
__YEFWHD_data_type = VIPRE_API_MODE;
|
||||
}
|
||||
|
||||
void _put_vipre_help(void) {
|
||||
puts (
|
||||
"Vipre Console Cryptor V " VERSION "\n"
|
||||
@ -122,10 +136,15 @@ int __create_sig(char* file) {
|
||||
str_dt ++;
|
||||
}
|
||||
char key[32] = "";
|
||||
fputs("Signature key: ", stdout);
|
||||
if (!scanf("%32[^\n]", key)) puts("\033[1mvipre-cryptor: \033[91mKey read error!\033[0m");
|
||||
file_t fp = fopen(file, "wb");
|
||||
if (fp == NULL) { _file_read_error(); free(arr); return EXIT_FAILURE; }
|
||||
if (__YEFWHD_data_type != VIPRE_API_MODE) {
|
||||
fputs("Signature key: ", stdout);
|
||||
if (!scanf("%32[^\n]", key)) puts("\033[1mvipre-cryptor: \033[91mKey read error!\033[0m");
|
||||
} else {
|
||||
strncpy(key, __YEFWHD_api_datakey, 31);
|
||||
key[31] = '\0';
|
||||
}
|
||||
_str_srand(__generate_hash(key));
|
||||
unsigned short int pos = 0;
|
||||
while (true) {
|
||||
@ -148,6 +167,10 @@ int __create_sig(char* file) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static void __nl_del(char* user_login) {
|
||||
if (user_login[strlen(user_login) - 1] == '\n') user_login[strlen(user_login) - 1] = '\0';
|
||||
}
|
||||
|
||||
int __create_user(char* file, char* user_file, char* cry_file) {
|
||||
file_t fp = fopen(file, "rb");
|
||||
file_t wp = fopen(user_file, "wb");
|
||||
@ -162,35 +185,42 @@ int __create_user(char* file, char* user_file, char* cry_file) {
|
||||
}
|
||||
char user_login[32];
|
||||
char password[32];
|
||||
fputs("Login: ", stdout);
|
||||
int c;
|
||||
size_t cnt = 0;
|
||||
while((c=getchar())!=EOF && cnt < 31 && c != '\n') {
|
||||
user_login[cnt] = c;
|
||||
cnt ++;
|
||||
}
|
||||
fputs("Password: ", stdout);
|
||||
cnt = 0;
|
||||
while((c=getchar())!=EOF && cnt < 31 && c != '\n') {
|
||||
password[cnt] = c;
|
||||
cnt ++;
|
||||
}
|
||||
size_t cnt_save = cnt;
|
||||
password[cnt] = '\0';
|
||||
fputs("Repeat password: ", stdout);
|
||||
cnt = 0;
|
||||
while((c=getchar())!=EOF && cnt < 31 && c != '\n') {
|
||||
if (password[cnt] != c) {
|
||||
if (__YEFWHD_data_type != VIPRE_API_MODE) {
|
||||
fputs("Login: ", stdout);
|
||||
size_t cnt = 0;
|
||||
while((c=getchar())!=EOF && cnt < 31 && c != '\n') {
|
||||
user_login[cnt] = c;
|
||||
cnt ++;
|
||||
}
|
||||
fputs("Password: ", stdout);
|
||||
cnt = 0;
|
||||
while((c=getchar())!=EOF && cnt < 31 && c != '\n') {
|
||||
password[cnt] = c;
|
||||
cnt ++;
|
||||
}
|
||||
size_t cnt_save = cnt;
|
||||
password[cnt] = '\0';
|
||||
fputs("Repeat password: ", stdout);
|
||||
cnt = 0;
|
||||
while((c=getchar())!=EOF && cnt < 31 && c != '\n') {
|
||||
if (password[cnt] != c) {
|
||||
puts("\033[1mvipre-cryptor: \033[91mThe password was repeated incorrectly!\033[0m");
|
||||
free(arr);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
cnt ++;
|
||||
}
|
||||
if (cnt != cnt_save) {
|
||||
puts("\033[1mvipre-cryptor: \033[91mThe password was repeated incorrectly!\033[0m");
|
||||
free(arr);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
cnt ++;
|
||||
}
|
||||
if (cnt != cnt_save) {
|
||||
puts("\033[1mvipre-cryptor: \033[91mThe password was repeated incorrectly!\033[0m");
|
||||
free(arr);
|
||||
return EXIT_FAILURE;
|
||||
} else {
|
||||
strncpy(user_login, __YEFWHD_api_login, 31);
|
||||
strncpy(password, __YEFWHD_api_password, 31);
|
||||
user_login[31] = '\0';
|
||||
password[31] = '\0';
|
||||
}
|
||||
fputs(user_login, wp); putc('\n', wp);
|
||||
fputs(password, wp); putc('\n', wp);
|
||||
@ -228,14 +258,25 @@ int __read_user(char* file, char* user_file, char* cry_file) {
|
||||
char correct_login[32];
|
||||
char password[32];
|
||||
char correct_password[32];
|
||||
fputs("Login: ", stdout);
|
||||
char* res;
|
||||
res = fgets(user_login, 32, stdin);
|
||||
res = fgets(correct_login, 32, up);
|
||||
fputs("Password: ", stdout);
|
||||
res = fgets(password, 32, stdin);
|
||||
res = fgets(correct_password, 32, up);
|
||||
if (__YEFWHD_data_type != VIPRE_API_MODE) {
|
||||
fputs("Login: ", stdout);
|
||||
res = fgets(user_login, 32, stdin);
|
||||
fputs("Password: ", stdout);
|
||||
res = fgets(password, 32, stdin);
|
||||
} else {
|
||||
strncpy(user_login, __YEFWHD_api_login, 31);
|
||||
strncpy(password, __YEFWHD_api_password, 31);
|
||||
user_login[31] = '\0';
|
||||
password[31] = '\0';
|
||||
|
||||
}
|
||||
if (res);
|
||||
__nl_del(user_login); __nl_del(password);
|
||||
__nl_del(correct_login); __nl_del(correct_password);
|
||||
if (user_login[strlen(user_login) - 1] == '\n') user_login[strlen(user_login) - 1] = '\0';
|
||||
if (!(strcmp(user_login, correct_login) == 0 && strcmp(password, correct_password) == 0)) {
|
||||
puts("\033[1mvipre-cryptor: \033[91mThe password or login is incorrect!\033[0m");
|
||||
free(arr);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user