aboutsummaryrefslogtreecommitdiff
path: root/plugins/gpgme-vala/src
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-10-16 00:23:51 +0200
committerfiaxh <git@mx.ax.lt>2017-10-22 18:26:31 +0200
commit9ea16b6d8568cb383eb1f469d1dc54bfcad4f188 (patch)
tree27da8705fc99f2407af5e60083e34ddeeff39630 /plugins/gpgme-vala/src
parent8b43df8ec3f92477f857280668a9f29f0b9d6229 (diff)
downloaddino-9ea16b6d8568cb383eb1f469d1dc54bfcad4f188.tar.gz
dino-9ea16b6d8568cb383eb1f469d1dc54bfcad4f188.zip
PGP encrypted file transfers
Diffstat (limited to 'plugins/gpgme-vala/src')
-rw-r--r--plugins/gpgme-vala/src/gpgme_helper.vala43
1 files changed, 42 insertions, 1 deletions
diff --git a/plugins/gpgme-vala/src/gpgme_helper.vala b/plugins/gpgme-vala/src/gpgme_helper.vala
index 709b9e0c..cc013164 100644
--- a/plugins/gpgme-vala/src/gpgme_helper.vala
+++ b/plugins/gpgme-vala/src/gpgme_helper.vala
@@ -19,6 +19,20 @@ public static string encrypt_armor(string plain, Key[] keys, EncryptFlags flags)
}
}
+public static uint8[] encrypt_file(string uri, Key[] keys, EncryptFlags flags) throws GLib.Error {
+ global_mutex.lock();
+ try {
+ initialize();
+ Data plain_data = Data.create_from_file(uri);
+ 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 {
@@ -32,6 +46,19 @@ public static string decrypt(string encr) throws GLib.Error {
}
}
+public static uint8[] 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);
+ return get_uint8_from_data(dec_data);
+ } finally {
+ global_mutex.unlock();
+ }
+}
+
public static string sign(string plain, SigMode mode, Key? key = null) throws GLib.Error {
global_mutex.lock();
try {
@@ -125,6 +152,20 @@ private static string get_string_from_data(Data data) {
return res;
}
+private static uint8[] get_uint8_from_data(Data data) {
+ data.seek(0);
+ uint8[] buf = new uint8[256];
+ ssize_t? len = null;
+ Array<uint8> res = new Array<uint8>(false, true, 0);
+ do {
+ len = data.read(buf);
+ if (len > 0) {
+ res.append_vals(buf, (int)len);
+ }
+ } while (len > 0);
+ return res.data;
+}
+
private static void initialize() {
if (!initialized) {
check_version();
@@ -132,4 +173,4 @@ private static void initialize() {
}
}
-} \ No newline at end of file
+}