Check if key file was opened correctly in DHT_bootstrap.c

Warn the user if it wasn't.
This commit is contained in:
irungentoo 2014-11-29 23:45:32 -05:00
parent 1c3f88758d
commit ee0f06937f
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98

View File

@ -83,6 +83,11 @@ void manage_keys(DHT *dht)
memcpy(keys + crypto_box_PUBLICKEYBYTES, dht->self_secret_key, crypto_box_SECRETKEYBYTES);
keys_file = fopen("key", "w");
if (keys_file == NULL) {
printf("Error opening key file in write mode.\nKeys will not be saved.\n");
return;
}
if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) {
printf("Error while writing the key file.\nExiting.\n");
exit(1);