mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Added saving and loading of keys by default
This commit is contained in:
parent
b368a6b4b8
commit
164d92e2dd
|
@ -35,9 +35,41 @@ unsigned char * hex_string_to_bin(char hex_string[])
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void manage_keys()
|
||||||
|
{
|
||||||
|
const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
|
||||||
|
uint8_t keys[KEYS_SIZE];
|
||||||
|
|
||||||
|
FILE *keys_file = fopen("key", "r");
|
||||||
|
if (keys_file != NULL) {
|
||||||
|
//if file was opened successfully -- load keys
|
||||||
|
size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keys_file);
|
||||||
|
if (read_size != KEYS_SIZE) {
|
||||||
|
printf("Error while reading the key file\nExiting.\n");
|
||||||
|
exit(1);
|
||||||
|
} else {
|
||||||
|
printf("Keys loaded successfully\n");
|
||||||
|
}
|
||||||
|
load_keys(keys);
|
||||||
|
} else {
|
||||||
|
//otherwise save new keys
|
||||||
|
new_keys();
|
||||||
|
save_keys(keys);
|
||||||
|
keys_file = fopen("key", "w");
|
||||||
|
if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) {
|
||||||
|
printf("Error while writing the key file.\nExiting.\n");
|
||||||
|
exit(1);
|
||||||
|
} else {
|
||||||
|
printf("Keys saved successfully\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(keys_file);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
new_keys();
|
manage_keys();
|
||||||
printf("Public key: ");
|
printf("Public key: ");
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
for(i = 0; i < 32; i++)
|
for(i = 0; i < 32; i++)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user