summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/src/main.c b/src/main.c
index 7eed5b2..a5afe97 100644
--- a/src/main.c
+++ b/src/main.c
@@ -21,8 +21,8 @@
#include <gpgme.h>
#include "gpg.h"
-#include "gpg_keyids.h"
-#include "strarray.h"
+#include "gpgedit_config.h"
+#include "strll.h"
void system_edit(char* file) {
char cmd[256]; // Buffer for editor command
@@ -31,17 +31,36 @@ void system_edit(char* file) {
}
+void parseargs(int argc, char* argv[], struct gpgedit_config* config) {
+ int i = 1;
+
+ while(i < argc) {
+ if(strcmp(argv[i], "-r") == 0 || strcmp(argv[i], "--recipient") == 0) {
+ i++;
+ //printf("Adding recipient %s\n", argv[i]);
+ strll_add(config->recipients, argv[i]);
+ } else {
+ gpgedit_config_file_set(config, argv[i]);
+ }
+ i++;
+ }
+}
+
+
int main(int argc, char* argv[]) {
char tmpfile[32] = "/tmp/gpgedit-XXXXXX";
gpgme_ctx_t decctx;
gpgme_error_t err;
- char** keyids;
+ struct gpgedit_config* config;
if(argc == 1) {
printf("Please specify a gpg encrypted file to edit\n");
return 1;
}
+ config = gpgedit_config_new();
+ parseargs(argc, argv, config);
+
// Initialize decryption context, create tmp file to write decrypted contents
// to, and run decryption operation.
err = init_gpg(&decctx, GPGME_PROTOCOL_OPENPGP);
@@ -51,22 +70,24 @@ int main(int argc, char* argv[]) {
}
mkstemp(tmpfile);
- gpgme_decrypt_result_t res = gpg_decrypt_file(argv[1], tmpfile, decctx);
+ gpgme_decrypt_result_t res = gpg_decrypt_file(config->file, tmpfile, decctx);
// Get keyids array from recipients list
- keyids = strarray_new();
- gpg_keyids_load_from_recip(&keyids, res->recipients);
+ gpgedit_config_recip_from_gpgme_recip(config, res->recipients);
// Freedom!
gpgme_release(decctx);
// Open the system editor
system_edit(tmpfile);
+ printf("Recipients:\n");
+ strll_dump(config->recipients);
+
// Re-encrypt the plaintext tmp file
- //printf("Re-encrypting file '%s' -> '%s'\n", tmpfile, argv[1]);
- gpg_encrypt_file(tmpfile, argv[1], keyids);
+ //printf("Re-encrypting file '%s' -> '%s'\n", tmpfile, config->file);
+ gpg_encrypt_file(tmpfile, config->file, config->recipients);
// Clean up tmpfile
- strarray_release(&keyids);
+ gpgedit_config_release(config);
unlink(tmpfile);
return 0;
}

Generated by cgit