Add I/O error handling and use filenames instead of file descriptors

This commit is contained in:
William Wennerström
2020-07-21 09:31:47 +02:00
parent 73f313b921
commit 62cbad1c6e
10 changed files with 102 additions and 71 deletions

View File

@@ -35,7 +35,6 @@
#include <assert.h>
#include <signal/signal_protocol.h>
#include <signal/signal_protocol_types.h>
#include <gcrypt.h>
#include "log.h"
#include "omemo/omemo.h"
@@ -377,7 +376,7 @@ out:
return res;
}
int
gcry_error_t
aes256gcm_crypt_file(FILE* in, FILE* out, off_t file_size,
unsigned char key[], unsigned char nonce[], bool encrypt)
{
@@ -416,7 +415,7 @@ aes256gcm_crypt_file(FILE* in, FILE* out, off_t file_size,
off_t bytes_read = 0, bytes_available = 0, read_size = 0;
while (bytes_read < file_size) {
bytes_available = file_size - bytes_read;
if (!bytes_available) {
if (!bytes_available || ferror(in) != 0) {
break;
}