Add --version and --help.

pull/2/head 1.0
Christopher Wellons 2017-03-05 21:02:00 -05:00
parent 188a0be098
commit b218e3be80
5 changed files with 28 additions and 3 deletions

View File

@ -3,6 +3,10 @@
/* Compile-time configuration */ /* Compile-time configuration */
#ifndef ENCHIVE_VERSION
# define ENCHIVE_VERSION 1.0
#endif
#ifndef ENCHIVE_RANDOM_DEVICE #ifndef ENCHIVE_RANDOM_DEVICE
# define ENCHIVE_RANDOM_DEVICE /dev/urandom # define ENCHIVE_RANDOM_DEVICE /dev/urandom
#endif #endif

View File

@ -4,8 +4,11 @@ static const char *docs_usage[] = {
" [-a|--agent[=seconds]] [--no-agent]", " [-a|--agent[=seconds]] [--no-agent]",
#endif #endif
#if ENCHIVE_OPTION_RANDOM_DEVICE #if ENCHIVE_OPTION_RANDOM_DEVICE
" [--random-device <file>]", " [--random-device <file>] "
#else
" "
#endif #endif
"[--version] [--help]",
" <command> [args]", " <command> [args]",
"", "",
"Commands (unique prefixes accepted):", "Commands (unique prefixes accepted):",
@ -24,6 +27,8 @@ static const char *docs_usage[] = {
#endif #endif
" --pubkey <file>, -p set the public key file [~/.enchive.pub]", " --pubkey <file>, -p set the public key file [~/.enchive.pub]",
" --seckey <file>, -s set the secret key file [~/.enchive.sec]", " --seckey <file>, -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", "Enchive archives files by encrypting them to yourself using your",
"public key. It uses ChaCha20, Curve25519, and SHA-224.", "public key. It uses ChaCha20, Curve25519, and SHA-224.",

View File

@ -1126,6 +1126,12 @@ print_usage(FILE *f)
multiputs(docs_usage, f); multiputs(docs_usage, f);
} }
static void
print_version(void)
{
puts("enchive " STR(ENCHIVE_VERSION));
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
@ -1139,6 +1145,8 @@ main(int argc, char **argv)
#endif #endif
{"pubkey", 'p', OPTPARSE_REQUIRED}, {"pubkey", 'p', OPTPARSE_REQUIRED},
{"seckey", 's', OPTPARSE_REQUIRED}, {"seckey", 's', OPTPARSE_REQUIRED},
{"version", 'V', OPTPARSE_NONE},
{"help", 'h', OPTPARSE_NONE},
{0, 0, 0} {0, 0, 0}
}; };
@ -1178,6 +1186,14 @@ main(int argc, char **argv)
case 's': case 's':
global_seckey = options->optarg; global_seckey = options->optarg;
break; break;
case 'h':
print_usage(stdout);
exit(EXIT_SUCCESS);
break;
case 'V':
print_version();
exit(EXIT_SUCCESS);
break;
default: default:
fatal("%s", options->errmsg); fatal("%s", options->errmsg);
} }

View File

@ -1,7 +1,7 @@
/********************************************************************* /*********************************************************************
* Filename: sha256.c * Filename: sha256.c
* Author: Brad Conte (brad AT bradconte.com) * Author: Brad Conte (brad AT bradconte.com)
* Copyright: * Copyright: Public Domain
* Disclaimer: This code is presented "as is" without any guarantees. * Disclaimer: This code is presented "as is" without any guarantees.
* Details: Implementation of the SHA-256 hashing algorithm. * Details: Implementation of the SHA-256 hashing algorithm.
SHA-256 is one of the three algorithms in the SHA2 SHA-256 is one of the three algorithms in the SHA2

View File

@ -1,7 +1,7 @@
/********************************************************************* /*********************************************************************
* Filename: sha256.h * Filename: sha256.h
* Author: Brad Conte (brad AT bradconte.com) * Author: Brad Conte (brad AT bradconte.com)
* Copyright: * Copyright: Public Domain
* Disclaimer: This code is presented "as is" without any guarantees. * Disclaimer: This code is presented "as is" without any guarantees.
* Details: Defines the API for the corresponding SHA1 implementation. * Details: Defines the API for the corresponding SHA1 implementation.
*********************************************************************/ *********************************************************************/