diff options
author | fiaxh <git@mx.ax.lt> | 2017-03-11 23:06:34 +0100 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-03-11 23:09:57 +0100 |
commit | 083df7e73775d8f81e380f12f6d63c2012a6b617 (patch) | |
tree | 4af5a61f1f8174036ebdc2b39efaca6ac232ec6c | |
parent | f40a34bdc1995e656b09cc1252a8dcce685e373f (diff) | |
download | dino-083df7e73775d8f81e380f12f6d63c2012a6b617.tar.gz dino-083df7e73775d8f81e380f12f6d63c2012a6b617.zip |
Move GPG initialization to gpgme-vala
-rw-r--r-- | gpgme-vala/src/gpgme_helper.vala | 23 | ||||
-rw-r--r-- | gpgme-vala/vapi/gpgme.vapi | 2 | ||||
-rw-r--r-- | xmpp-vala/src/module/xep/0027_pgp/module.vala | 1 |
3 files changed, 24 insertions, 2 deletions
diff --git a/gpgme-vala/src/gpgme_helper.vala b/gpgme-vala/src/gpgme_helper.vala index 2a27ba3e..9efa2b4c 100644 --- a/gpgme-vala/src/gpgme_helper.vala +++ b/gpgme-vala/src/gpgme_helper.vala @@ -3,7 +3,11 @@ using GPG; namespace GPGHelper { +private static bool initialized = false; + public static string encrypt_armor(string plain, Key[] keys, EncryptFlags flags) throws GLib.Error { + initialize(); + global_mutex.lock(); Data plain_data = Data.create_from_memory(plain.data, false); Context context = Context.create(); @@ -14,6 +18,8 @@ public static string encrypt_armor(string plain, Key[] keys, EncryptFlags flags) } public static string decrypt(string encr) throws GLib.Error { + initialize(); + global_mutex.lock(); Data enc_data = Data.create_from_memory(encr.data, false); Context context = Context.create(); @@ -23,6 +29,8 @@ public static string decrypt(string encr) throws GLib.Error { } public static string sign(string plain, SigMode mode) throws GLib.Error { + initialize(); + global_mutex.lock(); Data plain_data = Data.create_from_memory(plain.data, false); Context context = Context.create(); @@ -32,6 +40,8 @@ public static string sign(string plain, SigMode mode) throws GLib.Error { } public static string? get_sign_key(string signature, string? text) throws GLib.Error { + initialize(); + global_mutex.lock(); Data sig_data = Data.create_from_memory(signature.data, false); Data text_data; @@ -49,6 +59,8 @@ public static string? get_sign_key(string signature, string? text) throws GLib.E } public static Gee.List<Key> get_keylist(string? pattern = null, bool secret_only = false) throws GLib.Error { + initialize(); + Gee.List<Key> keys = new ArrayList<Key>(); Context context = Context.create(); context.op_keylist_start(pattern, secret_only ? 1 : 0); @@ -64,6 +76,8 @@ public static Gee.List<Key> get_keylist(string? pattern = null, bool secret_only } public static Key? get_public_key(string sig) throws GLib.Error { + initialize(); + global_mutex.lock(); Context context = Context.create(); Key key = context.get_key(sig, false); @@ -72,6 +86,8 @@ public static Key? get_public_key(string sig) throws GLib.Error { } private static string get_string_from_data(Data data) { + initialize(); + data.seek(0); uint8[] buf = new uint8[256]; ssize_t? len = null; @@ -87,4 +103,11 @@ private static string get_string_from_data(Data data) { return res; } +private static void initialize() { + if (!initialized) { + check_version(); + initialized = true; + } +} + }
\ No newline at end of file diff --git a/gpgme-vala/vapi/gpgme.vapi b/gpgme-vala/vapi/gpgme.vapi index 8c942f4b..48d11b8c 100644 --- a/gpgme-vala/vapi/gpgme.vapi +++ b/gpgme-vala/vapi/gpgme.vapi @@ -267,7 +267,7 @@ namespace GPG { public static Context create() throws GLib.Error { Context ctx; - @new(out ctx); + throw_if_error(@new(out ctx)); return ctx; } diff --git a/xmpp-vala/src/module/xep/0027_pgp/module.vala b/xmpp-vala/src/module/xep/0027_pgp/module.vala index 8d75a17d..5906abc3 100644 --- a/xmpp-vala/src/module/xep/0027_pgp/module.vala +++ b/xmpp-vala/src/module/xep/0027_pgp/module.vala @@ -17,7 +17,6 @@ namespace Xmpp.Xep.Pgp { private string? own_key_id; public Module() { - GPG.check_version(); signed_status = gpg_sign(""); if (signed_status != null) own_key_id = gpg_verify(signed_status, ""); } |