Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deflagify #76

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions wolfCLU/clu_include/clu_header_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,26 @@
*
* @param argc holds all command line input
* @param argv each holds one value from the command line input
* @param offset offset to where the non-flag arguments start
* @param action forwarded from wolfCLU_main (-e, -d, -h, or -b)
*/
int wolfCLU_setup(int argc, char** argv, char action);
int wolfCLU_setup(int argc, char** argv, int offset, char action);

/* hash argument function
*
* @param argc holds all command line input
* @param argv each holds one value from the command line input
* @param offset offset to where the non-flag arguments start
*/
int wolfCLU_hashSetup(int argc, char** argv);
int wolfCLU_hashSetup(int argc, char** argv, int offset);

/* benchmark argument function
*
* @param argc holds all command line input
* @param argv each holds one value from the command line input
* @param offset offset to where the non-flag arguments start
*/
int wolfCLU_benchSetup(int argc, char** argv);
int wolfCLU_benchSetup(int argc, char** argv, int offset);

/*
* generic help function
Expand Down
19 changes: 0 additions & 19 deletions wolfCLU/clu_include/clu_optargs.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@

/* Enumerated types for long arguments */
enum {
/* @temporary: implement modes as arguments */
ENCRYPT = 1000,
DECRYPT,
BENCHMARK,
HASH,
X509,
REQUEST,
GEN_KEY,

INFILE,
OUTFILE,
PASSWORD,
Expand All @@ -53,16 +44,6 @@ enum {

/* Structure for holding long arguments */
static struct option long_options[] = {

/* @temporary: implement modes as flags */
{"encrypt", required_argument, 0, ENCRYPT },
{"decrypt", required_argument, 0, DECRYPT },
{"bench", no_argument, 0, BENCHMARK },
{"hash", required_argument, 0, HASH },
{"x509", no_argument, 0, X509 },
{"req", required_argument, 0, REQUEST },
{"genkey", required_argument, 0, GEN_KEY },

{"in", required_argument, 0, INFILE },
{"out", required_argument, 0, OUTFILE },
{"pwd", required_argument, 0, PASSWORD },
Expand Down
2 changes: 1 addition & 1 deletion wolfCLU/clu_include/genkey/clu_genkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ enum {
};

/* handles incoming arguments for certificate generation */
int wolfCLU_genKeySetup(int argc, char** argv);
int wolfCLU_genKeySetup(int argc, char** argv, int offset);

#ifdef HAVE_ED25519
/* Generate an ED25519 key */
Expand Down
2 changes: 1 addition & 1 deletion wolfCLU/clu_include/x509/clu_cert.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum {
};

/* handles incoming arguments for certificate generation */
int wolfCLU_certSetup(int argc, char** argv);
int wolfCLU_certSetup(int argc, char** argv, int offset);

/* print help info */
void wolfCLU_certHelp();
Expand Down
2 changes: 1 addition & 1 deletion wolfCLU/clu_include/x509/clu_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
*/

/* handles incoming arguments for certificate requests */
int wolfCLU_requestSetup(int argc, char** argv);
int wolfCLU_requestSetup(int argc, char** argv, int offset);


11 changes: 6 additions & 5 deletions wolfCLU/clu_src/benchmark/clu_bench_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "clu_include/clu_header_main.h"

int wolfCLU_benchSetup(int argc, char** argv)
int wolfCLU_benchSetup(int argc, char** argv, int offset)
{
int ret = 0; /* return variable */
int time = 3; /* timer variable */
Expand Down Expand Up @@ -95,10 +95,11 @@ int wolfCLU_benchSetup(int argc, char** argv)

/* pull as many of the algorithms out of the argv as posible */
for (i = 0; i < (int)algsSz; ++i) {
ret = wolfCLU_checkForArg(algs[i], XSTRLEN(algs[i]), argc, argv);
if (ret > 0) {
option[i] = 1;
optionCheck = 1;
for (j = offset; j > argc; ++j) {
if (XSTRNCMP(argv[j], algs[i], XSTRLEN(algs[i]))) {
option[i] = 1;
optionCheck = 1;
}
}
}

Expand Down
84 changes: 32 additions & 52 deletions wolfCLU/clu_src/clu_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@

int main(int argc, char** argv)
{
int flag = 0;
char* mode = "";
int helpCheck = 0;
int ret = 0;
int option = 0;
int ignoreIn = 0;
Expand All @@ -50,17 +49,6 @@ int main(int argc, char** argv)

switch (option) {

/* @temporary: implement the modes as arguments */
case ENCRYPT:
case DECRYPT:
case BENCHMARK:
case HASH:
case X509:
case REQUEST:
case GEN_KEY:

if (!flag) flag = option;

/*
* Ignore the following arguments for now. They will be handled by
* their respective setups (e.g. Crypto setup, Benchmark setup, or
Expand Down Expand Up @@ -98,12 +86,7 @@ int main(int argc, char** argv)
*/

case HELP:
/* only print for -help if no mode has been declared */
if (!flag) {
printf("Main help menu:\n");
wolfCLU_help();
return 0;
}
helpCheck = 1;
break;

case VERBOSE:
Expand All @@ -121,40 +104,37 @@ int main(int argc, char** argv)
}
}

/* @temporary: implement mode as a flag */
switch (flag) {
case 0:
printf("No mode provided.\n");
ret = 0;
break;

case ENCRYPT:
ret = wolfCLU_setup(argc, argv, 'e');
break;

case DECRYPT:
ret = wolfCLU_setup(argc, argv, 'd');
break;

case BENCHMARK:
ret = wolfCLU_benchSetup(argc, argv);
break;
/* look for modes */

case HASH:
ret = wolfCLU_hashSetup(argc, argv);
break;

case X509:
ret = wolfCLU_certSetup(argc, argv);
break;

case REQUEST:
ret = wolfCLU_requestSetup(argc, argv);
break;

case GEN_KEY:
ret = wolfCLU_genKeySetup(argc, argv);
break;
if (argv[optind] == NULL) {
if (helpCheck == 1) {
wolfCLU_help();
}
}
else if (XSTRNCMP(argv[optind], "encrypt", 7) == 0) {
ret = wolfCLU_setup(argc, argv, optind, 'e');
}
else if (XSTRNCMP(argv[optind], "decrypt", 7) == 0) {
ret = wolfCLU_setup(argc, argv, optind, 'd');
}
else if (XSTRNCMP(argv[optind], "bench", 5) == 0) {
ret = wolfCLU_benchSetup(argc, argv, optind);
}
else if (XSTRNCMP(argv[optind], "hash", 4) == 0) {
ret = wolfCLU_hashSetup(argc, argv, optind);
}
else if (XSTRNCMP(argv[optind], "x509", 4) == 0) {
ret = wolfCLU_certSetup(argc, argv, optind);
}
else if (XSTRNCMP(argv[optind], "req", 3) == 0) {
ret = wolfCLU_requestSetup(argc, argv, optind);
}
else if (XSTRNCMP(argv[optind], "genkey", 6) == 0) {
ret = wolfCLU_genKeySetup(argc, argv, optind);
}
else {
printf("%s: '%s' is not a valid mode. Please consult -help\n",
argv[0], argv[optind]);
}

if (ret != 0)
Expand Down
4 changes: 2 additions & 2 deletions wolfCLU/clu_src/crypto/clu_crypto_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "clu_include/clu_header_main.h"

int wolfCLU_setup(int argc, char** argv, char action)
int wolfCLU_setup(int argc, char** argv, int offset, char action)
{
char outNameE[256]; /* default outFile for encrypt */
char outNameD[256]; /* default outfile for decrypt */
Expand Down Expand Up @@ -71,7 +71,7 @@ int wolfCLU_setup(int argc, char** argv, char action)
}
}

name = argv[2];
name = argv[offset + 1];
if (name == NULL) {
return FATAL_ERROR;
}
Expand Down
8 changes: 6 additions & 2 deletions wolfCLU/clu_src/genkey/clu_genkey_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "clu_include/genkey/clu_genkey.h"
#include "clu_include/x509/clu_cert.h" /* argument checking */

int wolfCLU_genKeySetup(int argc, char** argv)
int wolfCLU_genKeySetup(int argc, char** argv, int offset)
{
char keyOutFName[MAX_FILENAME_SZ]; /* default outFile for genKey */
char defaultFormat[4] = "der\0";
Expand All @@ -46,7 +46,11 @@ int wolfCLU_genKeySetup(int argc, char** argv)

XMEMSET(keyOutFName, 0, MAX_FILENAME_SZ);

keyType = argv[2];
keyType = argv[offset+1];
if (keyType == NULL) {
printf("No key type provided.\n");
return USER_INPUT_ERROR;
}

ret = wc_InitRng(&rng);

Expand Down
16 changes: 10 additions & 6 deletions wolfCLU/clu_src/hash/clu_hash_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/*
* hash argument function
*/
int wolfCLU_hashSetup(int argc, char** argv)
int wolfCLU_hashSetup(int argc, char** argv, int offset)
{
int ret = 0; /* return variable, counter */
int i = 0; /* loop variable */
Expand All @@ -50,9 +50,9 @@ int wolfCLU_hashSetup(int argc, char** argv)
"blake2b",
#endif
#ifndef NO_CODING
#ifdef WOLFSSL_BASE64_ENCODE
#ifdef WOLFSSL_BASE64_ENCODE
"base64enc",
#endif
#endif
"base64dec",
#endif
NULL /* terminal element (also stops the array from being 0-size */
Expand All @@ -75,10 +75,14 @@ int wolfCLU_hashSetup(int argc, char** argv)
return 0;
}

for (i = 0; i < (int)algsSz; ++i) {
if (argv[offset+1] == NULL) {
printf("No algorithm provided\n");
return FATAL_ERROR;
}
else for (i = 0; i < (int)algsSz; ++i) {
/* checks for acceptable algorithms */
if (XSTRNCMP(argv[2], algs[i], XSTRLEN(algs[i])) == 0) {
alg = argv[2];
if (XSTRNCMP(argv[offset+1], algs[i], XSTRLEN(algs[i])) == 0) {
alg = argv[offset+1];
algCheck = 1;
}
}
Expand Down
Loading