Implemented netpgp functionality - untested, haven't yet tried to compile. Added test skeleton, fixed all the function signatures to match the identity list returned ENGINE-73
authorKrista Grothoff <krista@pep-project.org>
Mon, 15 Aug 2016 21:06:38 +0200
branchENGINE-73
changeset 1019e38a6ec264bd
parent 1018 e3c6cf28309c
child 1020 b80ab1442557
Implemented netpgp functionality - untested, haven't yet tried to compile. Added test skeleton, fixed all the function signatures to match the identity list returned
src/cryptotech.h
src/pEpEngine.c
src/pEpEngine.h
src/pgp_gpg.c
src/pgp_gpg.h
src/pgp_netpgp.c
test/pgp_list_keys_test.cc
     1.1 --- a/src/cryptotech.h	Mon Aug 15 20:18:43 2016 +0200
     1.2 +++ b/src/cryptotech.h	Mon Aug 15 21:06:38 2016 +0200
     1.3 @@ -69,7 +69,7 @@
     1.4  typedef PEP_STATUS (*binary_path_t)(const char **path);
     1.5  
     1.6  typedef PEP_STATUS (*list_keys_t)(PEP_SESSION session, 
     1.7 -                                             stringpair_list_t** key_email_list);
     1.8 +                                             identity_list** id_list);
     1.9  
    1.10  typedef struct _PEP_cryptotech_t {
    1.11      uint8_t id;
     2.1 --- a/src/pEpEngine.c	Mon Aug 15 20:18:43 2016 +0200
     2.2 +++ b/src/pEpEngine.c	Mon Aug 15 21:06:38 2016 +0200
     2.3 @@ -1235,16 +1235,16 @@
     2.4  }
     2.5  
     2.6  DYNAMIC_API PEP_STATUS list_keys(
     2.7 -        PEP_SESSION session, stringpair_list_t **key_email_list
     2.8 +        PEP_SESSION session, identity_list** id_list
     2.9      )
    2.10  {
    2.11      assert(session);
    2.12 -    assert(key_email_list);
    2.13 +    assert(id_list);
    2.14  
    2.15 -    if (!(session && key_email_list))
    2.16 +    if (!(session && id_list))
    2.17          return PEP_ILLEGAL_VALUE;
    2.18  
    2.19 -    return session->cryptotech[PEP_crypt_OpenPGP].list_keys(session, key_email_list);
    2.20 +    return session->cryptotech[PEP_crypt_OpenPGP].list_keys(session, id_list);
    2.21  }
    2.22  
    2.23  DYNAMIC_API PEP_STATUS generate_keypair(
     3.1 --- a/src/pEpEngine.h	Mon Aug 15 20:18:43 2016 +0200
     3.2 +++ b/src/pEpEngine.h	Mon Aug 15 21:06:38 2016 +0200
     3.3 @@ -646,19 +646,19 @@
     3.4      );
     3.5  
     3.6  
     3.7 -// find_keys() - find keys in keyring
     3.8 +// list_keys() - return identities for all keys in the keyring
     3.9  //
    3.10  //  parameters:
    3.11 -//      session (in)            session handle
    3.12 -//      key_email_pairs (out)   list of key id/primary email address pairs for 
    3.13 -//                              each available key (whether in management database 
    3.14 -//                              or not)
    3.15 +//      session (in)          session handle
    3.16 +//      id_list (out)         list of identities for each available key 
    3.17 +//                            (whether in management database 
    3.18 +//                             or not)
    3.19  //
    3.20  //  caveat: FIXME
    3.21 -//        the ownerships of keylist isgoing to the caller
    3.22 -//        the caller must use free_stringlist() to free it
    3.23 +//        the ownership of the identity list goes to the caller
    3.24 +//        the caller must use free_identity_list() to free it
    3.25  DYNAMIC_API PEP_STATUS list_keys(
    3.26 -        PEP_SESSION session, stringpair_list_t** key_email_pairs
    3.27 +        PEP_SESSION session, identity_list** id_list
    3.28      );
    3.29  
    3.30  // send_key() - send key(s) to keyserver
     4.1 --- a/src/pgp_gpg.c	Mon Aug 15 20:18:43 2016 +0200
     4.2 +++ b/src/pgp_gpg.c	Mon Aug 15 21:06:38 2016 +0200
     4.3 @@ -1225,15 +1225,15 @@
     4.4      return PEP_STATUS_OK;
     4.5  }
     4.6  
     4.7 -PEP_STATUS pgp_list_keys(PEP_SESSION session, stringpair_list_t** key_email_list) {
     4.8 +PEP_STATUS pgp_list_keys(PEP_SESSION session, identity_list** id_list) {
     4.9      gpgme_error_t gpgme_error;
    4.10      assert(session);
    4.11 -    assert(key_email_list);
    4.12 +    assert(id_list);
    4.13      
    4.14 -    if (!session || !key_email_list)
    4.15 +    if (!session || !id_list)
    4.16          return PEP_ILLEGAL_VALUE;
    4.17      
    4.18 -    *key_email_list = NULL;
    4.19 +    *id_list = NULL;
    4.20      
    4.21      gpgme_error = gpg.gpgme_op_keylist_start(session->ctx, NULL, 0);
    4.22      gpgme_error = _GPGERR(gpgme_error);
    4.23 @@ -1250,10 +1250,10 @@
    4.24      };
    4.25      
    4.26      gpgme_key_t key;
    4.27 -    stringpair_list_t* _key_email_list = new_stringpair_list(NULL);
    4.28 -    stringpair_list_t* list_curr = _key_email_list;
    4.29 -    stringpair_t* key_email_pair = NULL;
    4.30 -    
    4.31 +    identity_list* _id_list = new_identity_list(NULL);
    4.32 +    identity_list* list_curr = _id_list;
    4.33 +    pEp_identity* new_id = NULL;
    4.34 +        
    4.35      do {
    4.36          gpgme_error = gpg.gpgme_op_keylist_next(session->ctx, &key);
    4.37          gpgme_error = _GPGERR(gpgme_error);
    4.38 @@ -1270,27 +1270,31 @@
    4.39                  // first subkey is primary key
    4.40                  char* fpr = key->subkeys->fpr;
    4.41                  char* primary_email = key->uids->email;
    4.42 +                char* uname = key->uids->name;
    4.43 +                char* uid = key->uids->uid;
    4.44 +                
    4.45                  assert(fpr);
    4.46                  assert(primary_email);
    4.47                  if (!fpr || !primary_email)
    4.48                      return PEP_GET_KEY_FAILED;
    4.49                  
    4.50 -                key_email_pair = new_stringpair(fpr, primary_email);
    4.51 -                assert(key_email_pair);
    4.52 +                new_id = new_identity(primary_email, fpr, uid, uname);
    4.53 +
    4.54 +                assert(new_id);
    4.55                  
    4.56 -                if (key_email_pair) {
    4.57 -                    list_curr = stringpair_list_add(list_curr, key_email_pair);
    4.58 -                    key_email_pair = NULL;
    4.59 +                if (new_id) {
    4.60 +                    list_curr = identity_list_add(list_curr, new_id);
    4.61 +                    new_id = NULL;
    4.62                      
    4.63                      assert(list_curr);
    4.64                      if (list_curr != NULL)
    4.65                          break;
    4.66                      else
    4.67 -                        free_stringpair(key_email_pair);
    4.68 +                        free_identity(new_id);
    4.69                  }
    4.70                  // else fallthrough (list_curr or key_email_pair wasn't allocateable)
    4.71              case GPG_ERR_ENOMEM:
    4.72 -                free_stringpair_list(_key_email_list);
    4.73 +                free_identity_list(_id_list);
    4.74                  gpg.gpgme_op_keylist_end(session->ctx);
    4.75                  return PEP_OUT_OF_MEMORY;
    4.76              default:
    4.77 @@ -1299,12 +1303,12 @@
    4.78          }
    4.79      } while (gpgme_error != GPG_ERR_EOF);
    4.80      
    4.81 -    if (_key_email_list->value == NULL) {
    4.82 -        free_stringpair_list(_key_email_list);
    4.83 -        _key_email_list = NULL;
    4.84 +    if (_id_list->ident == NULL) {
    4.85 +        free_identity_list(_id_list);
    4.86 +        _id_list = NULL;
    4.87      }
    4.88      
    4.89 -    *key_email_list = _key_email_list;
    4.90 +    *id_list = _id_list;
    4.91      
    4.92      return PEP_STATUS_OK;
    4.93  }
     5.1 --- a/src/pgp_gpg.h	Mon Aug 15 20:18:43 2016 +0200
     5.2 +++ b/src/pgp_gpg.h	Mon Aug 15 21:06:38 2016 +0200
     5.3 @@ -27,7 +27,7 @@
     5.4      );
     5.5  
     5.6  PEP_STATUS pgp_list_keys(
     5.7 -    PEP_SESSION session, stringpair_list_t** key_email_list
     5.8 +    PEP_SESSION session, identity_list** id_list
     5.9      );
    5.10      
    5.11  PEP_STATUS pgp_find_keys(
     6.1 --- a/src/pgp_netpgp.c	Mon Aug 15 20:18:43 2016 +0200
     6.2 +++ b/src/pgp_netpgp.c	Mon Aug 15 21:06:38 2016 +0200
     6.3 @@ -1706,7 +1706,7 @@
     6.4      }
     6.5  }
     6.6  
     6.7 -PEP_STATUS list_keys(
     6.8 +PEP_STATUS pgp_list_keys(
     6.9          PEP_SESSION session, 
    6.10          identity_list_t** id_list)
    6.11  {
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/pgp_list_keys_test.cc	Mon Aug 15 21:06:38 2016 +0200
     7.3 @@ -0,0 +1,29 @@
     7.4 +#include <iostream>
     7.5 +#include <string>
     7.6 +#include <assert.h>
     7.7 +#include "pEpEngine.h"
     7.8 +#include "identity_list.h"
     7.9 +
    7.10 +using namespace std;
    7.11 +
    7.12 +int main() {
    7.13 +    cout << "\n*** pgp_list_keys_test ***\n\n";
    7.14 +
    7.15 +    PEP_SESSION session;
    7.16 +    
    7.17 +    cout << "calling init()\n";
    7.18 +    PEP_STATUS status1 = init(&session);   
    7.19 +    assert(status1 == PEP_STATUS_OK);
    7.20 +    assert(session);
    7.21 +    cout << "init() completed.\n";
    7.22 +
    7.23 +    identity_list* all_the_ids = NULL;
    7.24 +    list_keys(session, &all_the_ids);
    7.25 +    free_identity_list(all_the_ids);
    7.26 +
    7.27 +
    7.28 +    cout << "calling release()\n";
    7.29 +    release(session);
    7.30 +    return 0;
    7.31 +}
    7.32 +