summaryrefslogtreecommitdiff
path: root/src/gpgedit_config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpgedit_config.c')
-rw-r--r--src/gpgedit_config.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/gpgedit_config.c b/src/gpgedit_config.c
new file mode 100644
index 0000000..dbf2e6b
--- /dev/null
+++ b/src/gpgedit_config.c
@@ -0,0 +1,63 @@
+// GPGEdit edits GPG encrypted files
+// Copyright (C) 2018 Aaron Ball <nullspoon@oper.io>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+#include "gpgedit_config.h"
+
+struct gpgedit_config* gpgedit_config_new() {
+ struct gpgedit_config* c = NULL;
+ c = malloc(sizeof(struct gpgedit_config));
+ c->file = NULL;
+ c->recipients = strll_new();
+
+ return c;
+}
+
+
+void gpgedit_config_file_set(struct gpgedit_config* c, char* file) {
+ c->file = malloc(strlen(file) + 1);
+ strcpy(c->file, file);
+}
+
+
+void gpgedit_config_recipients_add(struct gpgedit_config* c, char* recipient) {
+ strll_add(c->recipients, recipient);
+}
+
+void gpgedit_config_release(struct gpgedit_config* c) {
+ free(c->file);
+ strll_release(c->recipients);
+ free(c);
+}
+
+// gpgedit_config_recip_from_gpgme_recip:
+// Converts a gpgme_recipient_t linked list to a string array of key ids. This
+// is useful when storing a list of recipients for an already-encrypted file to
+// be used when later re-encrypting that file.
+//
+// @keyids Pointer to existing keyids string array. Note that the pointer
+// to this will be updated by the array growth process.
+// @firstrecip First recipient in the linked list. The list will be traversed
+// starting here.
+void gpgedit_config_recip_from_gpgme_recip(struct gpgedit_config* c, gpgme_recipient_t firstrecip) {
+ gpgme_recipient_t recip = firstrecip; // Current recipient object
+
+ // Write each recipient key id to the char array
+ while(recip != NULL) {
+ strll_add(c->recipients, recip->keyid);
+ recip = recip->next;
+ }
+}
+

Generated by cgit