basic error handling for inform/outform arguments

pull/32/head
kaleb-himes 2016-11-24 09:44:47 -07:00
parent d42a176965
commit 21eb80db37
7 changed files with 112 additions and 19 deletions

View File

@ -0,0 +1,5 @@
enum {
USER_INPUT_ERROR = -1001,
};

View File

@ -5,5 +5,6 @@
nobase_include_HEADERS+=clu_include/clu_header_main.h \
clu_include/x509/clu_cert.h \
clu_include/clu_optargs.h
clu_include/clu_optargs.h \
clu_include/clu_error_codes.h

View File

@ -35,3 +35,7 @@ int wolfsslCertSetup(int argc, char** argv);
/* print help info */
void wolfsslCertHelp();
/* check for user input errors */
int error_check(int inpem, int inder, int outpem, int outder);

View File

@ -22,7 +22,7 @@
#include "clu_include/clu_header_main.h"
#include "clu_include/x509/clu_cert.h"
#include "clu_include/clu_optargs.h"
#include "clu_include/clu_error_codes.h"
/* enumerate optionals beyond ascii range to dis-allow use of alias IE we
* do not want "-e" to work for encrypt, user must use "encrypt"
*/
@ -109,3 +109,12 @@ int main(int argc, char** argv)
return ret;
}
void convert_to_lower(char* s, int sSz)
{
int i;
for (i = 0; i < sSz; i++) {
s[i] = tolower(s[i]);
}
}

View File

@ -73,7 +73,7 @@
#define PACKAGE_NAME "wolfssl_clu"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "wolfssl_clu 0.4"
#define PACKAGE_STRING "wolfssl_clu 0.5"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "wolfssl_clu"
@ -82,7 +82,7 @@
#define PACKAGE_URL ""
/* Define to the version of this package. */
#define PACKAGE_VERSION "0.4"
#define PACKAGE_VERSION "0.5"
/* The size of `long', as computed by sizeof. */
#define SIZEOF_LONG 8

View File

@ -14,5 +14,4 @@ wolfssl_SOURCES = clu_src/tools/clu_funcs.c \
clu_src/benchmark/clu_bench_setup.c \
clu_src/benchmark/clu_benchmark.c \
clu_src/clu_main.c \
clu_src/x509/clu_cert_setup.c \
include/clu_header_main.h
clu_src/x509/clu_cert_setup.c

View File

@ -24,6 +24,7 @@
#include "clu_include/x509/clu_cert.h"
#include <wolfssl/wolfcrypt/types.h>
#include "clu_include/clu_optargs.h"
#include "clu_include/clu_error_codes.h"
#ifdef WOLFSSL_STATIC_MEMORY
#include <wolfssl/wolfcrypt/memory.h>
@ -32,11 +33,19 @@ else
#define HEAP_HINT NULL
#endif
enum {
INPEM_OUTPEM = 1,
INPEM_OUTDER = 2,
INDER_OUTPEM = 3,
INDER_OUTDER = 4,
};
int wolfsslCertSetup(int argc, char** argv)
{
int i;
int i, ret;
char* inform;
char* outform;
int inder = 0, inpem = 0, outder = 0, outpem = 0;
printf("In x509 loop\n");
for (i = 2; i < argc; i++) {
@ -55,9 +64,9 @@ int wolfsslCertSetup(int argc, char** argv)
printf("inform is %s\n", inform);
if (XSTRNCMP(inform, "pem", 3) == 0)
printf("IDENTIFIED PEM\n");
inpem = 1;
if (XSTRNCMP(inform, "der", 3) == 0)
printf("IDENTIFIED DER\n");
inder = 1;
} else if (XSTRNCMP(argv[i], "-outform", 8) == 0) {
convert_to_lower(argv[i+1], (int) XSTRLEN(argv[i+1]));
@ -66,24 +75,90 @@ int wolfsslCertSetup(int argc, char** argv)
printf("outform is %s\n", outform);
if (XSTRNCMP(outform, "pem", 3) == 0)
printf("IDENTIFIED PEM\n");
outpem = 1;
if (XSTRNCMP(outform, "der", 3) == 0)
printf("IDENTIFIED DER\n");
outder = 1;
}
}
return 0;
ret = error_check(inpem, inder, outpem, outder);
printf("ret = %d\n", ret);
switch (ret) {
case INPEM_OUTPEM:
ret = 0;
printf("run inpem outpem\n");
break;
case INPEM_OUTDER:
ret = 0;
printf("run inpem outder\n");
break;
case INDER_OUTPEM:
ret = 0;
printf("run inder outpem\n");
break;
case INDER_OUTDER:
ret = 0;
printf("run inder outder\n");
break;
default:
goto clu_cert_end;
break;
}
clu_cert_end:
return ret;
}
void convert_to_lower(char* s, int sSz)
{
int i;
for (i = 0; i < sSz; i++) {
s[i] = tolower(s[i]);
}
}
void wolfsslCertHelp()
{
printf("\n\n\nThis would be the certificate help.\n\n\n");
}
/*
* @arg a: is inform set to pem
* @arg b: is inform set to der
* @arg c: is outform set to pem
* @arg d: is outform set to der
*/
int error_check(int inpem, int inder, int outpem, int outder)
{
int ret = USER_INPUT_ERROR;
ret = ( inpem & inder);
if (ret) {
printf("ERROR: inform set to both PEM and DER format\n");
return USER_INPUT_ERROR;
}
ret = ( inpem & outpem);
if (ret) {
printf("input is pem format, output is pem format\n");
return INPEM_OUTPEM;
}
ret = (inpem & outder);
if (ret) {
printf("input is pem format, output is der format\n");
return INPEM_OUTDER;
}
ret = (inder & outpem);
if (ret) {
printf("input is der format, output is pem format\n");
return INDER_OUTPEM;
}
ret = (inder & outder);
if (ret) {
printf("input is der format, output is der format\n");
return INDER_OUTDER;
}
ret = (outder & outpem);
if (ret) {
printf("ERROR: outform set to both DER and PEM format\n");
return USER_INPUT_ERROR;
}
if (!ret) {
ret = USER_INPUT_ERROR;
if ( !inpem && !inder)
printf("User failed to specify input format: -inform not set\n");
else
printf("User failed to specify output format: -outform not set\n");
}
return ret;
}