Parcourir la source

fareqr db parsing fixes

* allow for spaces between fields
* allow for whitespace at end
* eventually we will want to update the db
  with which elements have been used or not,
  so parsing needs to allow for whitespace after
  private key
abetusk il y a 4 ans
Parent
commit
234c57920d
1 fichiers modifiés avec 15 ajouts et 6 suppressions
  1. 15 6
      busunit/passdb/fareqr.c

+ 15 - 6
busunit/passdb/fareqr.c

@@ -199,18 +199,27 @@ int fareqr_lookup_seed_secret(char *seedfn, char *pub, char *priv) {
         tok0_ptr = buf;
         tok1_ptr = strchr(buf, ' ');
         if (tok1_ptr) {
+
+          // tie off the tok0_ptr (public key) for use later
+          //
           *tok1_ptr = '\0';
-          tok1_ptr++;
+
+          // start our private key ptr at the start of the
+          // private key, skipping over whitespace
+          //
+          do {
+            tok1_ptr++;
+          } while ( (*tok1_ptr) && ((*tok1_ptr) == ' ') );
 
 
-          // Cechk it against our supplied 'pulbic' key
+          // Check it against our supplied 'pulbic' key
           //
           if (strcmp(pub, tok0_ptr)==0) {
 
             // If we've found it, copy it over to the `priv`
             // above and return
             //
-            for (i=0; tok1_ptr[i]; i++) {
+            for (i=0; tok1_ptr[i] && (tok1_ptr[i] != ' '); i++) {
               priv[i] = tok1_ptr[i];
             }
             priv[i]='\0';
@@ -273,11 +282,11 @@ void show_help(FILE *ofp) {
   fprintf(ofp, "Here is some example usage:\n");
   fprintf(ofp, "\n");
   fprintf(ofp, "  $ fareqr encode 'wu9XouSh' 'ohNgizahkephain3aosoh2AeH1aethoo4cie6oiSaezimaighai2eiVaefahfien' ';123456789060535?'\n");
-  fprintf(ofp, "  @wu9XouSh%VFl8VF1PV19TXEBeUVxdBl4=\n");
-  fprintf(ofp, "  $ fareqr decode 'ohNgizahkephain3aosoh2AeH1aethoo4cie6oiSaezimaighai2eiVaefahfien' '@wu9XouSh%VFl8VF1PV19TXEBeUVxdBl4=$'\n");
+  fprintf(ofp, "  @wu9XouSh%%VFl8VF1PV19TXEBeUVxdBl4=\n");
+  fprintf(ofp, "  $ fareqr decode 'ohNgizahkephain3aosoh2AeH1aethoo4cie6oiSaezimaighai2eiVaefahfien' '@wu9XouSh%%VFl8VF1PV19TXEBeUVxdBl4=$'\n");
   fprintf(ofp, "  ;123456789060535?\n");
   fprintf(ofp, "  $ echo 'wu9XouSh ohNgizahkephain3aosoh2AeH1aethoo4cie6oiSaezimaighai2eiVaefahfien' > ./qr.seed\n");
-  fprintf(ofp, "  $ fareqr dbdecode ./qr.seed '@wu9XouSh%VFl8VF1PV19TXEBeUVxdBl4=$'\n");
+  fprintf(ofp, "  $ fareqr dbdecode ./qr.seed '@wu9XouSh%%VFl8VF1PV19TXEBeUVxdBl4=$'\n");
   fprintf(ofp, "  ;123456789060535?\n");
   fprintf(ofp, "\n");
   fprintf(ofp, "Where 'wu9XouSh' is the public key, 'ohNgizahkephain3aosoh2AeH1aethoo4cie6oiSaezimaighai2eiVaefahfien' is the private key and\n");