From bd8f111990ae2a1ee1b5fb741605a5e3a968add7 Mon Sep 17 00:00:00 2001 From: "David M. Syzdek" Date: Tue, 17 Jan 2023 09:45:38 -0900 Subject: otputil: adding TOTP widget aliases --- src/otputil.c | 10 ++++++++++ src/widget-totp.c | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/otputil.c b/src/otputil.c index 7f2ca4d..134f2e2 100644 --- a/src/otputil.c +++ b/src/otputil.c @@ -233,6 +233,16 @@ static otputil_widget_t otputil_widget_map[] = .func_exec = &otputil_widget_totp, .func_usage = NULL, }, + { .name = "totp-sha1", + .desc = NULL, + .usage = " [ code ]", + .short_opt = (TOTP_SHORT_OPT "d:k:O:oT:t:x:"), + .arg_min = 0, + .arg_max = 1, + .aliases = (const char *[]){ "totp-sha256", "totp-sha512", NULL }, + .func_exec = &otputil_widget_totp, + .func_usage = NULL, + }, // version widget { .name = "version", diff --git a/src/widget-totp.c b/src/widget-totp.c index fe08220..69c67cb 100644 --- a/src/widget-totp.c +++ b/src/widget-totp.c @@ -100,6 +100,7 @@ otputil_widget_totp( otputil_config_t * cnf ) { int rc; + int hash; uint64_t meth; assert(cnf != NULL); @@ -112,6 +113,17 @@ otputil_widget_totp( return(1); }; + // set default hash + if (!(strncasecmp(cnf->argv[0], "totp-", 5))) + { + if ((hash = otputil_str2md(&cnf->argv[0][5])) == -1) + { + fprintf(stderr, "%s: unsupported hash algorithm\n", cnf->prog_name); + return(1); + }; + otputil_set_param(NULL, OTPUTIL_OPT_TOTP_HMAC, &hash); + }; + // initial processing of cli arguments if ((rc = otputil_arguments(cnf, cnf->argc, cnf->argv)) != 0) return((rc == -1) ? 0 : 1); -- cgit v1.2.3