]> err.no Git - yubikey-personalization/commitdiff
Re-factor adding _set_fixed().
authorFredrik Thulin <fredrik@yubico.com>
Wed, 23 May 2012 19:00:26 +0000 (21:00 +0200)
committerFredrik Thulin <fredrik@yubico.com>
Wed, 23 May 2012 19:00:26 +0000 (21:00 +0200)
Code moved to cater for upcoming commit (-ooath-id).

ykpers-args.c

index 3117b339ecbb7bb00a1fe0fa64841b4d50698167..6339552c0242f87e666a8732e11d6e31332bcd15 100644 (file)
@@ -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;
+}