From 71e4681d5cb4ba621af0c3f1e2a2ffc9d9fc4bbc Mon Sep 17 00:00:00 2001 From: C-3PO Date: Fri, 14 Sep 2018 01:51:48 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Parse=20decryption=20keys=20from=20?= =?UTF-8?q?comma-delimited=20string?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parseArguments.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/parseArguments.c b/src/parseArguments.c index 1597ee6..019d764 100644 --- a/src/parseArguments.c +++ b/src/parseArguments.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "decrypt.h" #include "errorAndExit.h" @@ -49,13 +50,26 @@ struct arguments parseArguments(int argc, char *argv[]) { state.fileSize = atol(optarg); hasSize = true; break; - case 'k': { //decryption keys - //TODO: parse from optarg - uint32_t key0 = atoi(argv[8]); - uint32_t key1 = atoi(argv[9]); - uint32_t key2 = atoi(argv[10]); + case 'k': { //decryption keys (12345,12345,12345) + //Split argument by comma into three integers + char* token = strtok(optarg, ","); + uint32_t keys[3] = { 0UL, 0UL, 0UL }; + int index = 0; + while (token != NULL) { + if (index > 2) { + fprintf(stderr, "Too many decryption keys specified with --keys; only 3 are allowed.\n"); + errorAndExit(); + } + keys[index] = atoi(token); + index += 1; + token = strtok(NULL, ","); + } + if (index < 3) { + fprintf(stderr, "Not enough decryption keys specified with --keys; 3 are required but only found %i.\n", index); + errorAndExit(); + } //Initialize decryption (pass decryption keys) - initDecryptor(key0, key1, key2); + initDecryptor(keys[0], keys[1], keys[2]); state.isEncrypted = true; break; }