commit 7f142b1eb0f5738d4ad7cdfa70a012a5a9e18fc9
parent 9d53f2f47cf6adbd1905ae516a12f8bf5021cf94
Author: Dominik Schmidt <dominik@schm1dt.ch>
Date: Tue, 25 Dec 2018 13:03:19 +0100
Improve error reportingn on parsing and executing
Diffstat:
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/nettle.c b/nettle.c
@@ -222,7 +222,7 @@ enum MODE getMode(char *args){
}
}
-void parseKV(struct EncStage *es, char *args){
+int parseKV(struct EncStage *es, char *args){
while(args!=NULL && *args!='\0'){
char *k=args;
char *kv=strstr(args, ",");
@@ -247,9 +247,11 @@ void parseKV(struct EncStage *es, char *args){
}
else{
fprintf(stderr, "Key %s not known\n", k);
+ return 1;
}
}
}
+ return 0;
}
int fillEncStage(struct EncStage *es, char *args){
@@ -282,7 +284,9 @@ int fillEncStage(struct EncStage *es, char *args){
char *kv=strstr(cipher, ":");
if(kv!=NULL){
*kv++='\0';
- parseKV(es, kv);
+ if(parseKV(es, kv)!=0){
+ return 1;
+ }
}
es->cipher=getCipher(cipher);
@@ -374,7 +378,7 @@ void CFBDecrypt(void *state, struct EncStage *es){
}
-void execute(struct EncStage *es){
+int execute(struct EncStage *es){
size_t ctx_s=es->cipher->context_size;
void *ctx=malloc(ctx_s);
memset(ctx, 0, ctx_s);
@@ -409,6 +413,7 @@ void execute(struct EncStage *es){
break;
}
free(ctx);
+ return 0;
}
int main(int argc, char **argv){
@@ -437,7 +442,9 @@ int main(int argc, char **argv){
es.src=in;
es.dst=in;
- execute(&es);
+ if(execute(&es)!=0){
+ return 1;
+ }
//char *tmp=in;
//in=out;
//free(tmp);