aboutsummaryrefslogtreecommitdiff
path: root/plugins/gpgme-vala/src
diff options
context:
space:
mode:
authorMiquel Lionel <lionel@les-miquelots.net>2023-10-30 21:48:08 +0100
committerMiquel Lionel <lionel@les-miquelots.net>2023-10-30 21:48:08 +0100
commitd761e8ccd5293d2f30a889b0cbe302c985aee68c (patch)
tree922bb248a7fee4cdff3da114abc7d77200f3d0da /plugins/gpgme-vala/src
parent302e954c99c71d670201828c6746dfaa40276d6d (diff)
parent3de716446819550514d50a8112f5b6dd0c662702 (diff)
downloaddino-add_conversation_account_indicator.tar.gz
dino-add_conversation_account_indicator.zip
Show which account is currently used in conversation details in the about sectionadd_conversation_account_indicator
Diffstat (limited to 'plugins/gpgme-vala/src')
-rw-r--r--plugins/gpgme-vala/src/gpgme_fix.c12
-rw-r--r--plugins/gpgme-vala/src/gpgme_fix.h12
-rw-r--r--plugins/gpgme-vala/src/gpgme_helper.vala184
3 files changed, 0 insertions, 208 deletions
diff --git a/plugins/gpgme-vala/src/gpgme_fix.c b/plugins/gpgme-vala/src/gpgme_fix.c
deleted file mode 100644
index 2bc139e9..00000000
--- a/plugins/gpgme-vala/src/gpgme_fix.c
+++ /dev/null
@@ -1,12 +0,0 @@
-#include <gpgme_fix.h>
-
-static GRecMutex gpgme_global_mutex = {0};
-
-gpgme_key_t gpgme_key_ref_vapi (gpgme_key_t key) {
- gpgme_key_ref(key);
- return key;
-}
-gpgme_key_t gpgme_key_unref_vapi (gpgme_key_t key) {
- gpgme_key_unref(key);
- return key;
-} \ No newline at end of file
diff --git a/plugins/gpgme-vala/src/gpgme_fix.h b/plugins/gpgme-vala/src/gpgme_fix.h
deleted file mode 100644
index 3daa7db0..00000000
--- a/plugins/gpgme-vala/src/gpgme_fix.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef GPGME_FIX
-#define GPGME_FIX 1
-
-#include <glib.h>
-#include <gpgme.h>
-
-static GRecMutex gpgme_global_mutex;
-
-gpgme_key_t gpgme_key_ref_vapi (gpgme_key_t key);
-gpgme_key_t gpgme_key_unref_vapi (gpgme_key_t key);
-
-#endif \ No newline at end of file
diff --git a/plugins/gpgme-vala/src/gpgme_helper.vala b/plugins/gpgme-vala/src/gpgme_helper.vala
deleted file mode 100644
index f28bc6d6..00000000
--- a/plugins/gpgme-vala/src/gpgme_helper.vala
+++ /dev/null
@@ -1,184 +0,0 @@
-using Gee;
-using GPG;
-
-namespace GPGHelper {
-
-private static bool initialized = false;
-
-public static string encrypt_armor(string plain, Key[] keys, EncryptFlags flags) throws GLib.Error {
- global_mutex.lock();
- try {
- initialize();
- Data plain_data = Data.create_from_memory(plain.data, false);
- Context context = Context.create();
- context.set_armor(true);
- Data enc_data = context.op_encrypt(keys, flags, plain_data);
- return get_string_from_data(enc_data);
- } finally {
- global_mutex.unlock();
- }
-}
-
-public static uint8[] encrypt_file(string uri, Key[] keys, EncryptFlags flags, string file_name) throws GLib.Error {
- global_mutex.lock();
- try {
- initialize();
- Data plain_data = Data.create_from_file(uri);
- plain_data.set_file_name(file_name);
- Context context = Context.create();
- context.set_armor(true);
- Data enc_data = context.op_encrypt(keys, flags, plain_data);
- return get_uint8_from_data(enc_data);
- } finally {
- global_mutex.unlock();
- }
-}
-
-public static string decrypt(string encr) throws GLib.Error {
- global_mutex.lock();
- try {
- initialize();
- Data enc_data = Data.create_from_memory(encr.data, false);
- Context context = Context.create();
- Data dec_data = context.op_decrypt(enc_data);
- return get_string_from_data(dec_data);
- } finally {
- global_mutex.unlock();
- }
-}
-
-public class DecryptedData {
- public uint8[] data { get; set; }
- public string filename { get; set; }
-}
-
-public static DecryptedData decrypt_data(uint8[] data) throws GLib.Error {
- global_mutex.lock();
- try {
- initialize();
- Data enc_data = Data.create_from_memory(data, false);
- Context context = Context.create();
- Data dec_data = context.op_decrypt(enc_data);
- DecryptResult* dec_res = context.op_decrypt_result();
- return new DecryptedData() { data=get_uint8_from_data(dec_data), filename=dec_res->file_name};
- } finally {
- global_mutex.unlock();
- }
-}
-
-public static string sign(string plain, SigMode mode, Key? key = null) throws GLib.Error {
- global_mutex.lock();
- try {
- initialize();
- Data plain_data = Data.create_from_memory(plain.data, false);
- Context context = Context.create();
- if (key != null) context.signers_add(key);
- Data signed_data = context.op_sign(plain_data, mode);
- return get_string_from_data(signed_data);
- } finally {
- global_mutex.unlock();
- }
-}
-
-public static string? get_sign_key(string signature, string? text) throws GLib.Error {
- global_mutex.lock();
- try {
- initialize();
- Data sig_data = Data.create_from_memory(signature.data, false);
- Data text_data;
- if (text != null) {
- text_data = Data.create_from_memory(text.data, false);
- } else {
- text_data = Data.create();
- }
- Context context = Context.create();
- context.op_verify(sig_data, text_data);
- VerifyResult* verify_res = context.op_verify_result();
- if (verify_res == null || verify_res.signatures == null) return null;
- return verify_res.signatures.fpr;
- } finally {
- global_mutex.unlock();
- }
-}
-
-public static Gee.List<Key> get_keylist(string? pattern = null, bool secret_only = false) throws GLib.Error {
- global_mutex.lock();
- try {
- initialize();
-
- Gee.List<Key> keys = new ArrayList<Key>();
- Context context = Context.create();
- context.op_keylist_start(pattern, secret_only ? 1 : 0);
- try {
- while (true) {
- Key key = context.op_keylist_next();
- keys.add(key);
- }
- } catch (Error e) {
- if (e.code != GPGError.ErrorCode.EOF) throw e;
- }
- return keys;
- } finally {
- global_mutex.unlock();
- }
-}
-
-public static Key? get_public_key(string sig) throws GLib.Error {
- return get_key(sig, false);
-}
-
-public static Key? get_private_key(string sig) throws GLib.Error {
- return get_key(sig, true);
-}
-
-private static Key? get_key(string sig, bool priv) throws GLib.Error {
- global_mutex.lock();
- try {
- initialize();
- Context context = Context.create();
- Key key = context.get_key(sig, priv);
- return key;
- } finally {
- global_mutex.unlock();
- }
-}
-
-private static string get_string_from_data(Data data) {
- const size_t BUF_SIZE = 256;
- data.seek(0);
- uint8[] buf = new uint8[BUF_SIZE + 1];
- ssize_t len = 0;
- string res = "";
- do {
- len = data.read(buf, BUF_SIZE);
- if (len > 0) {
- buf[len] = 0;
- res += (string) buf;
- }
- } while (len > 0);
- return res;
-}
-
-private static uint8[] get_uint8_from_data(Data data) {
- const size_t BUF_SIZE = 256;
- data.seek(0);
- uint8[] buf = new uint8[BUF_SIZE + 1];
- ssize_t len = 0;
- ByteArray res = new ByteArray();
- do {
- len = data.read(buf, BUF_SIZE);
- if (len > 0) {
- res.append(buf[0:len]);
- }
- } while (len > 0);
- return res.data;
-}
-
-private static void initialize() {
- if (!initialized) {
- check_version();
- initialized = true;
- }
-}
-
-}