blob: ae618f34a0ae8025a3400aaa57f8e974fbfd9593 (
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 c->log_level = LOG_INFO;
25
26 return c;
27 }
28
29
30 void gpgedit_config_file_set(struct gpgedit_config* c, char* file) {
31 c->file = malloc(strlen(file) + 1);
32 strcpy(c->file, file);
33 }
34
35
36 void gpgedit_config_recipients_add(struct gpgedit_config* c, char* recipient) {
37 strll_add(c->recipients, recipient);
38 }
39
40 void gpgedit_config_release(struct gpgedit_config* c) {
41 free(c->file);
42 strll_release(c->recipients);
43 free(c);
44 }
45
46 // gpgedit_config_recip_from_gpgme_recip:
47 // Converts a gpgme_recipient_t linked list to a string array of key ids. This
48 // is useful when storing a list of recipients for an already-encrypted file to
49 // be used when later re-encrypting that file.
50 //
51 // @keyids Pointer to existing keyids string array. Note that the pointer
52 // to this will be updated by the array growth process.
53 // @firstrecip First recipient in the linked list. The list will be traversed
54 // starting here.
55 void gpgedit_config_recip_from_gpgme_recip(struct gpgedit_config* c, gpgme_recipient_t firstrecip) {
56 gpgme_recipient_t recip = firstrecip; // Current recipient object
57
58 // Write each recipient key id to the char array
59 while(recip != NULL) {
60 strll_add(c->recipients, recip->keyid);
61 recip = recip->next;
62 }
63 }
|