diff options
author | David Timber <mieabby@gmail.com> | 2020-07-20 23:36:38 +1000 |
---|---|---|
committer | David Timber <mieabby@gmail.com> | 2020-07-20 23:36:38 +1000 |
commit | d61c0f9ddba9176c09ed751587343f3268ac6812 (patch) | |
tree | f0067fa48605961f182425df329ef8f37215957e /src/proone-mask.c | |
parent | 99214f49b4397886abd2bb69de598b56d1be72d9 (diff) |
Util functions tidy up ...
* Remove stdio.h dependency from dmask
* Add hex util functions
* Write test for functions in util_rt.h
Diffstat (limited to 'src/proone-mask.c')
-rw-r--r-- | src/proone-mask.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/proone-mask.c b/src/proone-mask.c index 1807f3f..3385c5a 100644 --- a/src/proone-mask.c +++ b/src/proone-mask.c @@ -2,6 +2,7 @@ #include <stddef.h> #include <stdint.h> #include <stdbool.h> +#include <ctype.h> #include <unistd.h> #include <fcntl.h> @@ -10,7 +11,7 @@ #include "dvault.h" -int main (const int argc, const char **args) { +int main (const int argc, char **args) { int exit_code = 0; ssize_t fd_read_size; size_t read_size = 0; @@ -22,13 +23,29 @@ int main (const int argc, const char **args) { if (argc <= 1) { fprintf(stderr, - "Usage: %s <type>\n" - "<type>: 'cstr', 'bin'\n", + "Usage: %s <type> [salt]\n" + "<type>: 'cstr', 'bin'\n" + "[salt]: salt hex value\n", args[0]); exit_code = 2; goto END; } + if (argc >= 3) { + for (char *p = args[2]; *p != 0; p += 1) { + *p = (char)tolower(*p); + } + + if (sscanf(args[2], "%hhx", &salt) != 1) { + perror("parsing salt: "); + exit_code = 1; + goto END; + } + } + else { + getrandom(&salt, sizeof(salt), 0); + } + type = prne_data_type_fstr(args[1]); switch (type) { case PRNE_DATA_TYPE_BIN: @@ -59,8 +76,6 @@ int main (const int argc, const char **args) { goto END; } - getrandom(&salt, sizeof(salt), 0); - mask_result = prne_dvault_mask(type, salt, read_size, buf); if (mask_result.result == PRNE_DVAULT_MASK_OK) { printf("(uint8_t*)\"%s\",\n", mask_result.str); |