netpgp: misc code cleanup
authorEdouard Tisserant
Mon, 04 May 2015 16:08:27 +0200
changeset 243c38813173fc7
parent 235 8b7468ca8034
child 244 36abc78b7de5
netpgp: misc code cleanup
src/pgp_netpgp.c
test/pEpEngineTest.cc
     1.1 --- a/src/pgp_netpgp.c	Sun May 03 16:40:28 2015 +0200
     1.2 +++ b/src/pgp_netpgp.c	Mon May 04 16:08:27 2015 +0200
     1.3 @@ -523,10 +523,10 @@
     1.4      if(*str == NULL)
     1.5          return 0;
     1.6  
     1.7 -    for (n = 0, i = 0 ; i < length - 1; i += 2) {
     1.8 -    	n += snprintf(&((*str)[n]), 6, "%02x%02x ", *fpr++, *fpr++);
     1.9 +    for (n = 0, i = 0 ; i < length - 2; i += 2) {
    1.10 +    	n += snprintf(&((*str)[n]), 6, "%02x%02x ", fpr[i], fpr[i+1]);
    1.11      }
    1.12 -    snprintf(&((*str)[n]), 5, "%02x%02x", *fpr++, *fpr++);
    1.13 +    snprintf(&((*str)[n]), 5, "%02x%02x", fpr[i], fpr[i+1]);
    1.14  
    1.15      return 1;
    1.16  }
    1.17 @@ -542,9 +542,10 @@
    1.18          while (*str == ' ') str++;
    1.19          for (j = 0; j < 2; j++) {
    1.20              uint8_t *byte = &fpr[*length];
    1.21 +            *byte = 0;
    1.22              for (i = 0; i < 2; i++) {
    1.23                  if (i > 0)
    1.24 -                    *byte *= 16;
    1.25 +                    *byte = *byte << 4;
    1.26                  if (*str >= 'a' && *str <= 'f')
    1.27                      *byte += 10 + *str - 'a';
    1.28                  else if (*str >= 'A' && *str <= 'F')
    1.29 @@ -555,7 +556,7 @@
    1.30                      return 0;
    1.31                  str++;
    1.32              }
    1.33 -            *length++;
    1.34 +            (*length)++;
    1.35          }
    1.36      }
    1.37      return 1;
    1.38 @@ -565,11 +566,13 @@
    1.39      pgp_key_t	pubkey;
    1.40      unsigned public;
    1.41      PEP_STATUS result;
    1.42 +    
    1.43  
    1.44      if ((public = (newkey->type == PGP_PTAG_CT_PUBLIC_KEY))){
    1.45          pubkey = *newkey;
    1.46      } else {
    1.47          // Duplicate key as public only
    1.48 +        bzero(&pubkey, sizeof(pubkey));
    1.49          if (!pgp_keydata_dup(&pubkey, newkey, 1 /* make_public */)){
    1.50              return PEP_OUT_OF_MEMORY;
    1.51          }
    1.52 @@ -613,7 +616,6 @@
    1.53  {
    1.54      netpgp_t *netpgp;
    1.55      pgp_key_t	newkey;
    1.56 -    pgp_key_t	pubkey;
    1.57  
    1.58      PEP_STATUS result;
    1.59      char newid[1024];
    1.60 @@ -642,7 +644,6 @@
    1.61      cipher = netpgp_getvar(netpgp, "cipher");
    1.62  
    1.63      bzero(&newkey, sizeof(newkey));
    1.64 -    bzero(&pubkey, sizeof(pubkey));
    1.65  
    1.66      // Generate the key
    1.67      if (!pgp_rsa_generate_keypair(&newkey, 4096, 65537UL, hashalg, cipher,
    1.68 @@ -787,13 +788,13 @@
    1.69      size_t buflen;
    1.70  
    1.71      assert(session);
    1.72 -    assert(fpr);
    1.73 +    assert(fprstr);
    1.74      assert(key_data);
    1.75      assert(size);
    1.76  
    1.77      netpgp = &session->ctx;
    1.78  
    1.79 -    if (!session || !fpr || !key_data || !size)
    1.80 +    if (!session || !fprstr || !key_data || !size)
    1.81          return PEP_UNKNOWN_ERROR;
    1.82  
    1.83      if (str_to_fpr(fprstr, fpr, &fprlen)) {
     2.1 --- a/test/pEpEngineTest.cc	Sun May 03 16:40:28 2015 +0200
     2.2 +++ b/test/pEpEngineTest.cc	Mon May 04 16:08:27 2015 +0200
     2.3 @@ -202,6 +202,7 @@
     2.4  
     2.5      cout << "export_key()\n\n";
     2.6      PEP_STATUS export_status = export_key(session, key.c_str(), &key_data, &size);
     2.7 +    cout << "export_key() exits with " << export_status << "\n";
     2.8      assert(export_status == PEP_STATUS_OK);
     2.9      cout << key_data << "\n\n";
    2.10