From: Fredrik Thulin Date: Wed, 23 May 2012 19:00:26 +0000 (+0200) Subject: Re-factor adding _set_fixed(). X-Git-Tag: v1.6.4~6 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=487e2ad0ab8698649df659998be4c0b60bc00819;p=yubikey-personalization.old Re-factor adding _set_fixed(). Code moved to cater for upcoming commit (-ooath-id). --- diff --git a/ykpers-args.c b/ykpers-args.c index 3117b33..6339552 100644 --- a/ykpers-args.c +++ b/ykpers-args.c @@ -303,21 +303,13 @@ int args_to_config(int argc, char **argv, YKP_CONFIG *cfg, YK_KEY *yk, if (strncmp(optarg, "salt=", 5) == 0) salt = strdup(optarg+5); else if (strncmp(optarg, "fixed=", 6) == 0) { - const char *fixed = optarg+6; - size_t fixedlen = strlen (fixed); - unsigned char fixedbin[256]; - size_t fixedbinlen = 0; - int rc = hex_modhex_decode(fixedbin, &fixedbinlen, - fixed, fixedlen, - 0, 16, true); - if (rc <= 0) { + if (_set_fixed(optarg + 6, cfg) != 1) { fprintf(stderr, "Invalid fixed string: %s\n", - fixed); + optarg + 6); *exit_code = 1; return 0; } - ykp_set_fixed(cfg, fixedbin, fixedbinlen); } else if (strncmp(optarg, "uid=", 4) == 0) { const char *uid = optarg+4; @@ -510,3 +502,18 @@ int args_to_config(int argc, char **argv, YKP_CONFIG *cfg, YK_KEY *yk, return 1; } + +int _set_fixed(char *optarg, YKP_CONFIG *cfg) { + const char *fixed = optarg; + size_t fixedlen = strlen (fixed); + unsigned char fixedbin[256]; + size_t fixedbinlen = 0; + int rc = hex_modhex_decode(fixedbin, &fixedbinlen, + fixed, fixedlen, + 0, 16, true); + if (rc <= 0) + return 0; + + ykp_set_fixed(cfg, fixedbin, fixedbinlen); + return 1; +}