aboutsummaryrefslogtreecommitdiff
path: root/plugins/gpgme-vala/src
diff options
context:
space:
mode:
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
+}