diff options
| author | David M. Syzdek <david@syzdek.net> | 2023-01-17 09:31:14 -0900 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2023-01-17 09:31:14 -0900 |
| commit | d11992f5b3fc2de1ff8ca40c044cdbd851139d34 (patch) | |
| tree | ef0d89fceaa8d6a3a09bb2fdab67928a392b6d7f | |
| parent | 5bcd1277a2cbadb0c9000c11c0a804653bd0f51a (diff) | |
| download | otputils-d11992f5b3fc2de1ff8ca40c044cdbd851139d34.tar.gz otputils-d11992f5b3fc2de1ff8ca40c044cdbd851139d34.tar.bz2 otputils-d11992f5b3fc2de1ff8ca40c044cdbd851139d34.tar.xz otputils-d11992f5b3fc2de1ff8ca40c044cdbd851139d34.zip | |
otputil: refactoring aliases for OTP widget
| -rw-r--r-- | src/otputil.c | 26 | ||||
| -rw-r--r-- | src/widget-otp.c | 11 |
2 files changed, 14 insertions, 23 deletions
diff --git a/src/otputil.c b/src/otputil.c index fac63f2..5c7d798 100644 --- a/src/otputil.c +++ b/src/otputil.c | |||
| @@ -183,33 +183,13 @@ static otputil_widget_t otputil_widget_map[] = | |||
| 183 | .func_usage = &otputil_widget_otp_usage, | 183 | .func_usage = &otputil_widget_otp_usage, |
| 184 | }, | 184 | }, |
| 185 | { .name = "otp-md4", | 185 | { .name = "otp-md4", |
| 186 | .desc = "otp alias for MD4", | 186 | .desc = NULL, |
| 187 | .usage = " [ sequence [ seed [ code ]]]", | ||
| 188 | .short_opt = (TOTP_SHORT_OPT "c:O:oP:ps:"), | ||
| 189 | .arg_min = 0, | ||
| 190 | .arg_max = 3, | ||
| 191 | .aliases = NULL, | ||
| 192 | .func_exec = &otputil_widget_otp_md4, | ||
| 193 | .func_usage = NULL, | ||
| 194 | }, | ||
| 195 | { .name = "otp-md5", | ||
| 196 | .desc = "otp alias for MD5", | ||
| 197 | .usage = " [ sequence [ seed [ code ]]]", | ||
| 198 | .short_opt = (TOTP_SHORT_OPT "c:O:oP:ps:"), | ||
| 199 | .arg_min = 0, | ||
| 200 | .arg_max = 3, | ||
| 201 | .aliases = NULL, | ||
| 202 | .func_exec = &otputil_widget_otp_md5, | ||
| 203 | .func_usage = NULL, | ||
| 204 | }, | ||
| 205 | { .name = "otp-sha1", | ||
| 206 | .desc = "otp alias for SHA1", | ||
| 207 | .usage = " [ sequence [ seed [ code ]]]", | 187 | .usage = " [ sequence [ seed [ code ]]]", |
| 208 | .short_opt = (TOTP_SHORT_OPT "c:O:oP:ps:"), | 188 | .short_opt = (TOTP_SHORT_OPT "c:O:oP:ps:"), |
| 209 | .arg_min = 0, | 189 | .arg_min = 0, |
| 210 | .arg_max = 3, | 190 | .arg_max = 3, |
| 211 | .aliases = NULL, | 191 | .aliases = (const char *[]){ "otp-md5", "otp-sha1", "otp-sha256", "otp-sha512", NULL }, |
| 212 | .func_exec = &otputil_widget_otp_sha1, | 192 | .func_exec = &otputil_widget_otp, |
| 213 | .func_usage = NULL, | 193 | .func_usage = NULL, |
| 214 | }, | 194 | }, |
| 215 | { .name = "skey", | 195 | { .name = "skey", |
diff --git a/src/widget-otp.c b/src/widget-otp.c index d4c06fc..079f035 100644 --- a/src/widget-otp.c +++ b/src/widget-otp.c | |||
| @@ -115,6 +115,17 @@ otputil_widget_otp( | |||
| 115 | return(1); | 115 | return(1); |
| 116 | }; | 116 | }; |
| 117 | 117 | ||
| 118 | // set default hash | ||
| 119 | if (!(strncasecmp(cnf->argv[0], "otp-", 4))) | ||
| 120 | { | ||
| 121 | if ((hash = otputil_str2md(&cnf->argv[0][4])) == -1) | ||
| 122 | { | ||
| 123 | fprintf(stderr, "%s: unsupported hash algorithm\n", cnf->prog_name); | ||
| 124 | return(1); | ||
| 125 | }; | ||
| 126 | otputil_set_param(NULL, OTPUTIL_OPT_OTP_HASH, &hash); | ||
| 127 | }; | ||
| 128 | |||
| 118 | // initial processing of cli arguments | 129 | // initial processing of cli arguments |
| 119 | if ((rc = otputil_arguments(cnf, cnf->argc, cnf->argv)) != 0) | 130 | if ((rc = otputil_arguments(cnf, cnf->argc, cnf->argv)) != 0) |
| 120 | return((rc == -1) ? 0 : 1); | 131 | return((rc == -1) ? 0 : 1); |
