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; }