blob: dbf2e6bd496f3edf1b17691dfa8a1e426a3e097c (
plain)
1 // GPGEdit edits GPG encrypted files
2 // Copyright (C) 2018 Aaron Ball <nullspoon@oper.io>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17 #include "gpgedit_config.h"
18
19 struct gpgedit_config* gpgedit_config_new() {
20 struct gpgedit_config* c = NULL;
21 c = malloc(sizeof(struct gpgedit_config));
22 c->file = NULL;
23 c->recipients = strll_new();
24
25 return c;
26 }
27
28
29 void gpgedit_config_file_set(struct gpgedit_config* c, char* file) {
30 c->file = malloc(strlen(file) + 1);
31 strcpy(c->file, file);
32 }
33
34
35 void gpgedit_config_recipients_add(struct gpgedit_config* c, char* recipient) {
36 strll_add(c->recipients, recipient);
37 }
38
39 void gpgedit_config_release(struct gpgedit_config* c) {
40 free(c->file);
41 strll_release(c->recipients);
42 free(c);
43 }
44
45 // gpgedit_config_recip_from_gpgme_recip:
46 // Converts a gpgme_recipient_t linked list to a string array of key ids. This
47 // is useful when storing a list of recipients for an already-encrypted file to
48 // be used when later re-encrypting that file.
49 //
50 // @keyids Pointer to existing keyids string array. Note that the pointer
51 // to this will be updated by the array growth process.
52 // @firstrecip First recipient in the linked list. The list will be traversed
53 // starting here.
54 void gpgedit_config_recip_from_gpgme_recip(struct gpgedit_config* c, gpgme_recipient_t firstrecip) {
55 gpgme_recipient_t recip = firstrecip; // Current recipient object
56
57 // Write each recipient key id to the char array
58 while(recip != NULL) {
59 strll_add(c->recipients, recip->keyid);
60 recip = recip->next;
61 }
62 }
|