sequoia: Simplify pgp_export_keydata sync
authorNeal H. Walfield <neal@pep.foundation>
Wed, 20 Mar 2019 19:40:40 +0100
branchsync
changeset 33579f3cca6deda9
parent 3356 e705998bf59c
child 3358 552f7ba5e109
sequoia: Simplify pgp_export_keydata

- In an early version of the Sequoia port, there were two DBs, one
for public keys and one for private keys. There is now only one.
Simplify the code accordingly.
src/pgp_sequoia.c
     1.1 --- a/src/pgp_sequoia.c	Wed Mar 20 19:32:56 2019 +0100
     1.2 +++ b/src/pgp_sequoia.c	Wed Mar 20 19:40:40 2019 +0100
     1.3 @@ -1597,8 +1597,8 @@
     1.4  {
     1.5      PEP_STATUS status = PEP_STATUS_OK;
     1.6      pgp_error_t err = NULL;
     1.7 -    pgp_tpk_t secret_key = NULL;
     1.8      pgp_tpk_t tpk = NULL;
     1.9 +    pgp_writer_t armor_writer = NULL;
    1.10  
    1.11      assert(session);
    1.12      assert(fpr);
    1.13 @@ -1610,36 +1610,16 @@
    1.14  
    1.15      T("(%s, %s)", fpr, secret ? "secret" : "public");
    1.16  
    1.17 -    if (secret) {
    1.18 -        status = tpk_find_by_fpr_hex(session, fpr, true, &secret_key, NULL);
    1.19 -        if (status == PEP_KEY_NOT_FOUND)
    1.20 -            status = PEP_STATUS_OK;
    1.21 -        ERROR_OUT(NULL, status, "Looking up TSK for %s", fpr);
    1.22 -    }
    1.23 -
    1.24 -    pgp_fingerprint_t pgp_fpr = pgp_fingerprint_from_hex(fpr);
    1.25 -    status = tpk_find_by_fpr(session, pgp_fpr, false, &tpk, NULL);
    1.26 -    pgp_fingerprint_free(pgp_fpr);
    1.27 -    ERROR_OUT(NULL, status, "Looking up TPK for %s", fpr);
    1.28 -
    1.29 -    if (secret_key) {
    1.30 -        tpk = pgp_tpk_merge(&err, tpk, secret_key);
    1.31 -        // pgp_tpk_merge can return NULL if the primary keys don't
    1.32 -        // match.  But, we looked up the tpk by the secret key's
    1.33 -        // fingerprint so this should not be possible.
    1.34 -        assert(tpk);
    1.35 -        if (! tpk)
    1.36 -            ERROR_OUT(err, PEP_UNKNOWN_ERROR, "merging TPKs");
    1.37 -        secret_key = NULL;
    1.38 -    }
    1.39 +    // If the caller asks for a secret key and we only have a
    1.40 +    // public key, then we return an error.
    1.41 +    status = tpk_find_by_fpr_hex(session, fpr, true, &tpk, NULL);
    1.42 +    ERROR_OUT(NULL, status, "Looking up TSK for %s", fpr);
    1.43  
    1.44      pgp_writer_t memory_writer = pgp_writer_alloc((void **) key_data, size);
    1.45      if (! memory_writer)
    1.46          ERROR_OUT(NULL, PEP_UNKNOWN_ERROR, "creating memory writer");
    1.47 -    pgp_writer_t armor_writer = pgp_armor_writer_new(&err,
    1.48 -                                                     memory_writer,
    1.49 -                                                     PGP_ARMOR_KIND_PUBLICKEY,
    1.50 -                                                     NULL, 0);
    1.51 +    armor_writer = pgp_armor_writer_new(&err, memory_writer,
    1.52 +                                        PGP_ARMOR_KIND_PUBLICKEY, NULL, 0);
    1.53      if (! armor_writer) {
    1.54          pgp_writer_free(memory_writer);
    1.55          ERROR_OUT(err, PEP_UNKNOWN_ERROR, "creating armored writer");
    1.56 @@ -1656,14 +1636,11 @@
    1.57      }
    1.58  
    1.59   out:
    1.60 -    if (tpk)
    1.61 -        pgp_tpk_free(tpk);
    1.62 -
    1.63      if (armor_writer)
    1.64          pgp_writer_free(armor_writer);
    1.65  
    1.66 -    if (secret_key)
    1.67 -        pgp_tpk_free(secret_key);
    1.68 +    if (tpk)
    1.69 +        pgp_tpk_free(tpk);
    1.70  
    1.71      T("(%s) -> %s", fpr, pep_status_to_string(status));
    1.72      return status;