Stowing changes to work on another bug ENGINE-73
authorKrista Grothoff <krista@pep-project.org>
Mon, 15 Aug 2016 13:37:11 +0200
branchENGINE-73
changeset 101024a4bc80878f
parent 1005 8e2c8253a385
child 1017 555d74646dbf
Stowing changes to work on another bug
src/cryptotech.c
src/cryptotech.h
src/pEpEngine.c
src/pEpEngine.h
src/pgp_gpg.c
src/pgp_gpg.h
src/pgp_netpgp.c
     1.1 --- a/src/cryptotech.c	Fri Aug 12 14:15:45 2016 +0200
     1.2 +++ b/src/cryptotech.c	Mon Aug 15 13:37:11 2016 +0200
     1.3 @@ -46,7 +46,7 @@
     1.4          cryptotech[PEP_crypt_OpenPGP].revoke_key = pgp_revoke_key;
     1.5          cryptotech[PEP_crypt_OpenPGP].key_expired = pgp_key_expired;
     1.6          cryptotech[PEP_crypt_OpenPGP].key_revoked = pgp_key_revoked;
     1.7 -        cryptotech[PEP_crypt_OpenPGP].list_key_email_pairs = pgp_list_key_email_pairs;
     1.8 +        cryptotech[PEP_crypt_OpenPGP].list_keys = pgp_list_keys;
     1.9  #ifdef PGP_BINARY_PATH
    1.10          cryptotech[PEP_crypt_OpenPGP].binary_path = PGP_BINARY_PATH;
    1.11  #endif
     2.1 --- a/src/cryptotech.h	Fri Aug 12 14:15:45 2016 +0200
     2.2 +++ b/src/cryptotech.h	Mon Aug 15 13:37:11 2016 +0200
     2.3 @@ -68,7 +68,7 @@
     2.4  
     2.5  typedef PEP_STATUS (*binary_path_t)(const char **path);
     2.6  
     2.7 -typedef PEP_STATUS (*list_key_email_pairs_t)(PEP_SESSION session, 
     2.8 +typedef PEP_STATUS (*list_keys_t)(PEP_SESSION session, 
     2.9                                               stringpair_list_t** key_email_list);
    2.10  
    2.11  typedef struct _PEP_cryptotech_t {
    2.12 @@ -92,7 +92,7 @@
    2.13      key_expired_t key_expired;
    2.14      key_revoked_t key_revoked;
    2.15      binary_path_t binary_path;
    2.16 -    list_key_email_pairs_t list_key_email_pairs;
    2.17 +    list_keys_t list_keys;
    2.18  } PEP_cryptotech_t;
    2.19  
    2.20  extern PEP_cryptotech_t cryptotech[PEP_crypt__count];
     3.1 --- a/src/pEpEngine.c	Fri Aug 12 14:15:45 2016 +0200
     3.2 +++ b/src/pEpEngine.c	Mon Aug 15 13:37:11 2016 +0200
     3.3 @@ -1234,7 +1234,7 @@
     3.4      return session->cryptotech[PEP_crypt_OpenPGP].find_keys(session, pattern, keylist);
     3.5  }
     3.6  
     3.7 -DYNAMIC_API PEP_STATUS list_key_email_pairs(
     3.8 +DYNAMIC_API PEP_STATUS list_keys(
     3.9          PEP_SESSION session, stringpair_list_t **key_email_list
    3.10      )
    3.11  {
    3.12 @@ -1244,7 +1244,7 @@
    3.13      if (!(session && key_email_list))
    3.14          return PEP_ILLEGAL_VALUE;
    3.15  
    3.16 -    return session->cryptotech[PEP_crypt_OpenPGP].list_key_email_pairs(session, key_email_list);
    3.17 +    return session->cryptotech[PEP_crypt_OpenPGP].list_keys(session, key_email_list);
    3.18  }
    3.19  
    3.20  DYNAMIC_API PEP_STATUS generate_keypair(
     4.1 --- a/src/pEpEngine.h	Fri Aug 12 14:15:45 2016 +0200
     4.2 +++ b/src/pEpEngine.h	Mon Aug 15 13:37:11 2016 +0200
     4.3 @@ -657,7 +657,7 @@
     4.4  //  caveat: FIXME
     4.5  //        the ownerships of keylist isgoing to the caller
     4.6  //        the caller must use free_stringlist() to free it
     4.7 -DYNAMIC_API PEP_STATUS list_key_email_pairs(
     4.8 +DYNAMIC_API PEP_STATUS list_keys(
     4.9          PEP_SESSION session, stringpair_list_t** key_email_pairs
    4.10      );
    4.11  
     5.1 --- a/src/pgp_gpg.c	Fri Aug 12 14:15:45 2016 +0200
     5.2 +++ b/src/pgp_gpg.c	Mon Aug 15 13:37:11 2016 +0200
     5.3 @@ -1225,7 +1225,7 @@
     5.4      return PEP_STATUS_OK;
     5.5  }
     5.6  
     5.7 -PEP_STATUS pgp_list_key_email_pairs(PEP_SESSION session, stringpair_list_t** key_email_list) {
     5.8 +PEP_STATUS pgp_list_keys(PEP_SESSION session, stringpair_list_t** key_email_list) {
     5.9      gpgme_error_t gpgme_error;
    5.10      assert(session);
    5.11      assert(key_email_list);
     6.1 --- a/src/pgp_gpg.h	Fri Aug 12 14:15:45 2016 +0200
     6.2 +++ b/src/pgp_gpg.h	Mon Aug 15 13:37:11 2016 +0200
     6.3 @@ -26,7 +26,7 @@
     6.4          PEP_SESSION session, const char *fpr, char **key_data, size_t *size
     6.5      );
     6.6  
     6.7 -PEP_STATUS pgp_list_key_email_pairs(
     6.8 +PEP_STATUS pgp_list_keys(
     6.9      PEP_SESSION session, stringpair_list_t** key_email_list
    6.10      );
    6.11      
     7.1 --- a/src/pgp_netpgp.c	Fri Aug 12 14:15:45 2016 +0200
     7.2 +++ b/src/pgp_netpgp.c	Mon Aug 15 13:37:11 2016 +0200
     7.3 @@ -1644,3 +1644,75 @@
     7.4      
     7.5      return PEP_STATUS_OK;
     7.6  }
     7.7 +
     7.8 +PEP_STATUS list_keys(
     7.9 +        PEP_SESSION session, 
    7.10 +        identity_list_t** id_list)
    7.11 +{
    7.12 +    
    7.13 +    pgp_key_t *key;
    7.14 +
    7.15 +    PEP_STATUS result;
    7.16 +
    7.17 +    unsigned from = 0;
    7.18 +    result = PEP_KEY_NOT_FOUND;
    7.19 +    
    7.20 +    // get all available keys
    7.21 +    unsigned n = 0; // type from netpgp...
    7.22 +    
    7.23 +    pgp_keyring_t* pubkeys = (pgp_keyring_t *)netpgp.pubring; 
    7.24 +    int keyring_end = pubkeys->keyc;
    7.25 +    
    7.26 +    if (keyring_end < 1)
    7.27 +        return result;
    7.28 +    
    7.29 +    for (key = keyring->keys; n < keyring_end; ++n, ++key) {
    7.30 +        assert(key)
    7.31 +        if (!key)
    7.32 +            continue;
    7.33 +        char* primary_userid = (char*)pgp_key_get_primary_userid(key);
    7.34 +        
    7.35 +            
    7.36 +    }
    7.37 +        
    7.38 +    
    7.39 +    
    7.40 +    
    7.41 +    // Try find a fingerprint in pattern
    7.42 +    if (str_to_fpr(pattern, fpr, &length)) {
    7.43 +        unsigned from = 0;
    7.44 +
    7.45 +
    7.46 +        // Only one fingerprint can match
    7.47 +        if ((key = (pgp_key_t *)pgp_getkeybyfpr(
    7.48 +                        netpgp.io,
    7.49 +                        (pgp_keyring_t *)netpgp.pubring, 
    7.50 +                        (const uint8_t *)fpr, length,
    7.51 +                        &from,
    7.52 +                        NULL, 0, 0)) == NULL) {
    7.53 +
    7.54 +            return PEP_KEY_NOT_FOUND;
    7.55 +        }
    7.56 +
    7.57 +        result = cb(cb_arg, key);
    7.58 +
    7.59 +    } else {
    7.60 +        // Search by name for pattern. Can match many.
    7.61 +        unsigned from = 0;
    7.62 +        result = PEP_KEY_NOT_FOUND;
    7.63 +        while((key = (pgp_key_t *)pgp_getnextkeybyname(
    7.64 +                        netpgp.io,
    7.65 +                        (pgp_keyring_t *)netpgp.pubring, 
    7.66 +			            (const char *)pattern,
    7.67 +                        &from)) != NULL) {
    7.68 +
    7.69 +            result = cb(cb_arg, key);
    7.70 +            if (result != PEP_STATUS_OK)
    7.71 +                break;
    7.72 +
    7.73 +            from++;
    7.74 +        }
    7.75 +    }
    7.76 +
    7.77 +    return result;
    7.78 +}