mirror of https://github.com/skeeto/enchive.git
Use strerror() when available for better errors (#7)
parent
bd1100ae99
commit
9d87816841
|
@ -705,7 +705,7 @@ symmetric_encrypt(FILE *in, FILE *out, const u8 *key, const u8 *iv)
|
||||||
if (!fwrite(mac, sizeof(mac), 1, out))
|
if (!fwrite(mac, sizeof(mac), 1, out))
|
||||||
fatal("error writing checksum to ciphertext file");
|
fatal("error writing checksum to ciphertext file");
|
||||||
if (fflush(out))
|
if (fflush(out))
|
||||||
fatal("error flushing to ciphertext file");
|
fatal("error flushing to ciphertext file -- %s", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -755,7 +755,7 @@ symmetric_decrypt(FILE *in, FILE *out, const u8 *key, const u8 *iv)
|
||||||
if (memcmp(buffer[0], mac, sizeof(mac)) != 0)
|
if (memcmp(buffer[0], mac, sizeof(mac)) != 0)
|
||||||
fatal("checksum mismatch!");
|
fatal("checksum mismatch!");
|
||||||
if (fflush(out))
|
if (fflush(out))
|
||||||
fatal("error flushing to plaintext file");
|
fatal("error flushing to plaintext file -- %s", strerror(errno));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -785,13 +785,14 @@ write_pubkey(char *file, u8 *key)
|
||||||
{
|
{
|
||||||
FILE *f = fopen(file, "wb");
|
FILE *f = fopen(file, "wb");
|
||||||
if (!f)
|
if (!f)
|
||||||
fatal("failed to open key file for writing -- %s", file);
|
fatal("failed to open key file for writing '%s' -- %s",
|
||||||
|
file, strerror(errno));
|
||||||
cleanup_register(f, file);
|
cleanup_register(f, file);
|
||||||
if (!fwrite(key, 32, 1, f))
|
if (!fwrite(key, 32, 1, f))
|
||||||
fatal("failed to write key file -- %s", file);
|
fatal("failed to write key file '%s'", file);
|
||||||
cleanup_closed(f);
|
cleanup_closed(f);
|
||||||
if (fclose(f))
|
if (fclose(f))
|
||||||
fatal("failed to flush key file -- %s", file);
|
fatal("failed to flush key file '%s' -- %s", file, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Layout of secret key file */
|
/* Layout of secret key file */
|
||||||
|
@ -859,13 +860,13 @@ write_seckey(char *file, const u8 *seckey, int iexp)
|
||||||
|
|
||||||
secfile = secure_creat(file);
|
secfile = secure_creat(file);
|
||||||
if (!secfile)
|
if (!secfile)
|
||||||
fatal("failed to open key file for writing -- %s", file);
|
fatal("failed to open key file for writing '%s'", file);
|
||||||
cleanup_register(secfile, file);
|
cleanup_register(secfile, file);
|
||||||
if (!fwrite(buf, sizeof(buf), 1, secfile))
|
if (!fwrite(buf, sizeof(buf), 1, secfile))
|
||||||
fatal("failed to write key file -- %s", file);
|
fatal("failed to write key file '%s'", file);
|
||||||
cleanup_closed(secfile);
|
cleanup_closed(secfile);
|
||||||
if (fclose(secfile))
|
if (fclose(secfile))
|
||||||
fatal("failed to flush key file -- %s", file);
|
fatal("failed to flush key file '%s' -- %s", file, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -876,9 +877,10 @@ load_pubkey(const char *file, u8 *key)
|
||||||
{
|
{
|
||||||
FILE *f = fopen(file, "rb");
|
FILE *f = fopen(file, "rb");
|
||||||
if (!f)
|
if (!f)
|
||||||
fatal("failed to open key file for reading -- %s", file);
|
fatal("failed to open key file for reading '%s' -- %s",
|
||||||
|
file, strerror(errno));
|
||||||
if (!fread(key, 32, 1, f))
|
if (!fread(key, 32, 1, f))
|
||||||
fatal("failed to read key file -- %s", file);
|
fatal("failed to read key file '%s'", file);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -913,7 +915,8 @@ load_seckey(const char *file, u8 *seckey)
|
||||||
/* Read the entire file into buf. */
|
/* Read the entire file into buf. */
|
||||||
secfile = fopen(file, "rb");
|
secfile = fopen(file, "rb");
|
||||||
if (!secfile)
|
if (!secfile)
|
||||||
fatal("failed to open key file for reading -- %s", file);
|
fatal("failed to open key file for reading '%s' -- %s",
|
||||||
|
file, strerror(errno));
|
||||||
if (!fread(buf, sizeof(buf), 1, secfile))
|
if (!fread(buf, sizeof(buf), 1, secfile))
|
||||||
fatal("failed to read key file -- %s", file);
|
fatal("failed to read key file -- %s", file);
|
||||||
fclose(secfile);
|
fclose(secfile);
|
||||||
|
@ -1230,7 +1233,8 @@ command_archive(struct optparse *options)
|
||||||
if (infile) {
|
if (infile) {
|
||||||
in = fopen(infile, "rb");
|
in = fopen(infile, "rb");
|
||||||
if (!in)
|
if (!in)
|
||||||
fatal("could not open input file -- %s", infile);
|
fatal("could not open input file '%s' -- %s",
|
||||||
|
infile, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
outfile = dupstr(optparse_arg(options));
|
outfile = dupstr(optparse_arg(options));
|
||||||
|
@ -1241,7 +1245,8 @@ command_archive(struct optparse *options)
|
||||||
if (outfile) {
|
if (outfile) {
|
||||||
out = fopen(outfile, "wb");
|
out = fopen(outfile, "wb");
|
||||||
if (!out)
|
if (!out)
|
||||||
fatal("could not open output file -- %s", outfile);
|
fatal("could not open output file '%s' -- %s",
|
||||||
|
outfile, strerror(errno));
|
||||||
cleanup_register(out, outfile);
|
cleanup_register(out, outfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1317,7 +1322,8 @@ command_extract(struct optparse *options)
|
||||||
if (infile) {
|
if (infile) {
|
||||||
in = fopen(infile, "rb");
|
in = fopen(infile, "rb");
|
||||||
if (!in)
|
if (!in)
|
||||||
fatal("could not open input file -- %s", infile);
|
fatal("could not open input file '%s' -- %s",
|
||||||
|
infile, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
outfile = dupstr(optparse_arg(options));
|
outfile = dupstr(optparse_arg(options));
|
||||||
|
@ -1333,7 +1339,8 @@ command_extract(struct optparse *options)
|
||||||
if (outfile) {
|
if (outfile) {
|
||||||
out = fopen(outfile, "wb");
|
out = fopen(outfile, "wb");
|
||||||
if (!out)
|
if (!out)
|
||||||
fatal("could not open output file -- %s", infile);
|
fatal("could not open output file '%s' -- %s",
|
||||||
|
infile, strerror(errno));
|
||||||
cleanup_register(out, outfile);
|
cleanup_register(out, outfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue