From b218e3be80def0969d050b0419dc647bd5071dd6 Mon Sep 17 00:00:00 2001 From: Christopher Wellons Date: Sun, 5 Mar 2017 21:02:00 -0500 Subject: [PATCH] Add --version and --help. --- config.h | 4 ++++ src/docs.h | 7 ++++++- src/enchive.c | 16 ++++++++++++++++ src/sha256.c | 2 +- src/sha256.h | 2 +- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/config.h b/config.h index 9e318df..a1c0102 100644 --- a/config.h +++ b/config.h @@ -3,6 +3,10 @@ /* Compile-time configuration */ +#ifndef ENCHIVE_VERSION +# define ENCHIVE_VERSION 1.0 +#endif + #ifndef ENCHIVE_RANDOM_DEVICE # define ENCHIVE_RANDOM_DEVICE /dev/urandom #endif diff --git a/src/docs.h b/src/docs.h index 9ccd348..b5e65a6 100644 --- a/src/docs.h +++ b/src/docs.h @@ -4,8 +4,11 @@ static const char *docs_usage[] = { " [-a|--agent[=seconds]] [--no-agent]", #endif #if ENCHIVE_OPTION_RANDOM_DEVICE -" [--random-device ]", +" [--random-device ] " +#else +" " #endif +"[--version] [--help]", " [args]", "", "Commands (unique prefixes accepted):", @@ -24,6 +27,8 @@ static const char *docs_usage[] = { #endif " --pubkey , -p set the public key file [~/.enchive.pub]", " --seckey , -s set the secret key file [~/.enchive.sec]", +" --version display version information", +" --help display this usage information", "", "Enchive archives files by encrypting them to yourself using your", "public key. It uses ChaCha20, Curve25519, and SHA-224.", diff --git a/src/enchive.c b/src/enchive.c index 003d834..d8fcbb4 100644 --- a/src/enchive.c +++ b/src/enchive.c @@ -1126,6 +1126,12 @@ print_usage(FILE *f) multiputs(docs_usage, f); } +static void +print_version(void) +{ + puts("enchive " STR(ENCHIVE_VERSION)); +} + int main(int argc, char **argv) { @@ -1139,6 +1145,8 @@ main(int argc, char **argv) #endif {"pubkey", 'p', OPTPARSE_REQUIRED}, {"seckey", 's', OPTPARSE_REQUIRED}, + {"version", 'V', OPTPARSE_NONE}, + {"help", 'h', OPTPARSE_NONE}, {0, 0, 0} }; @@ -1178,6 +1186,14 @@ main(int argc, char **argv) case 's': global_seckey = options->optarg; break; + case 'h': + print_usage(stdout); + exit(EXIT_SUCCESS); + break; + case 'V': + print_version(); + exit(EXIT_SUCCESS); + break; default: fatal("%s", options->errmsg); } diff --git a/src/sha256.c b/src/sha256.c index 364f12d..45b017f 100644 --- a/src/sha256.c +++ b/src/sha256.c @@ -1,7 +1,7 @@ /********************************************************************* * Filename: sha256.c * Author: Brad Conte (brad AT bradconte.com) -* Copyright: +* Copyright: Public Domain * Disclaimer: This code is presented "as is" without any guarantees. * Details: Implementation of the SHA-256 hashing algorithm. SHA-256 is one of the three algorithms in the SHA2 diff --git a/src/sha256.h b/src/sha256.h index 863b91c..1905d2f 100644 --- a/src/sha256.h +++ b/src/sha256.h @@ -1,7 +1,7 @@ /********************************************************************* * Filename: sha256.h * Author: Brad Conte (brad AT bradconte.com) -* Copyright: +* Copyright: Public Domain * Disclaimer: This code is presented "as is" without any guarantees. * Details: Defines the API for the corresponding SHA1 implementation. *********************************************************************/