diff options
Diffstat (limited to 'src/gpg.c')
-rw-r--r-- | src/gpg.c | 38 |
1 files changed, 34 insertions, 4 deletions
@@ -101,6 +101,37 @@ int gpg_recip_count(gpgme_recipient_t firstrecip) { } +// gpg_strll_to_key_t: +// Converts a string linked list containing keyids (multiple identifier types +// are supported) into an array of gpgme_key_t objects. +// +// @ctx GPGME context (already initialized) +// @firstrecip First linkedlist recipient item +// +// @return gpgme_key_t* Array of gpgme_key_t objects, one for each keyid string +gpgme_key_t* gpg_strll_to_key_t(gpgme_ctx_t ctx, struct strll* firstrecip) { + gpgme_key_t* out; + gpgme_error_t err; + int i = 0; + struct strll* recip = firstrecip; + + // Initialize the gpgme_key_t pointer array + out = (gpgme_key_t*) malloc(1); + out = NULL; + + // Loop over the keys back to zero + while(recip != NULL) { + out = realloc(out, sizeof(gpgme_key_t) * (i + 1)); + err = gpgme_get_key(ctx, recip->str, &out[i], 0); + gpg_failiferr(err); + recip = recip->next; + i++; + } + out[i] = NULL; + return out; +} + + void gpg_key_dump(gpgme_key_t key) { printf("Recipient: %s\n", key->fpr); printf(" protocol: %d\n", key->protocol); @@ -114,15 +145,13 @@ void gpg_key_dump(gpgme_key_t key) { printf(" can_auth: %d\n", key->can_authenticate); printf(" qualified: %d\n", key->is_qualified); printf(" secret: %d\n", key->secret); - printf(" origin: %d\n", key->origin); printf(" issuer_serial: %s\n", key->issuer_serial); printf(" issuer_name: %s\n", key->issuer_name); printf(" chain_id: %s\n", key->chain_id); - printf(" last_update: %ld\n", key->last_update); } -size_t gpg_encrypt_file(char* infile, char* outfile, char** keyids) { +size_t gpg_encrypt_file(char* infile, char* outfile, struct strll* recipll) { gpgme_ctx_t ctx; gpgme_data_t indata; gpgme_data_t outdata; @@ -141,7 +170,8 @@ size_t gpg_encrypt_file(char* infile, char* outfile, char** keyids) { gpg_failiferr(err); // Get key id objects from keyids char array - keys = gpg_keyids_to_key_t(ctx, keyids); + keys = gpg_strll_to_key_t(ctx, recipll); + // For debugging purposes // int i = 0; // while(keys[i] != NULL) { |