aboutsummaryrefslogtreecommitdiff
path: root/plugins/openpgp/src/in_file_processor.vala
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/openpgp/src/in_file_processor.vala
parent8b43df8ec3f92477f857280668a9f29f0b9d6229 (diff)
downloaddino-9ea16b6d8568cb383eb1f469d1dc54bfcad4f188.tar.gz
dino-9ea16b6d8568cb383eb1f469d1dc54bfcad4f188.zip
PGP encrypted file transfers
Diffstat (limited to 'plugins/openpgp/src/in_file_processor.vala')
-rw-r--r--plugins/openpgp/src/in_file_processor.vala28
1 files changed, 28 insertions, 0 deletions
diff --git a/plugins/openpgp/src/in_file_processor.vala b/plugins/openpgp/src/in_file_processor.vala
new file mode 100644
index 00000000..2a06bbdf
--- /dev/null
+++ b/plugins/openpgp/src/in_file_processor.vala
@@ -0,0 +1,28 @@
+using Dino.Entities;
+
+namespace Dino.Plugins.OpenPgp {
+
+public class InFileProcessor : IncommingFileProcessor, Object {
+ public bool can_process(FileTransfer file_transfer) {
+ return file_transfer.file_name.has_suffix("pgp") || file_transfer.mime_type == "application/pgp-encrypted";
+ }
+
+ public void process(FileTransfer file_transfer) {
+ uint8[] buf = new uint8[256];
+ Array<uint8> data = new Array<uint8>(false, true, 0);
+ size_t len = -1;
+ do {
+ len = file_transfer.input_stream.read(buf);
+ data.append_vals(buf, (uint) len);
+ } while(len > 0);
+
+ uint8[] clear_data = GPGHelper.decrypt_data(data.data);
+ file_transfer.input_stream = new MemoryInputStream.from_data(clear_data, GLib.free);
+ file_transfer.encryption = Encryption.PGP;
+ if (file_transfer.file_name.has_suffix(".pgp")) {
+ file_transfer.file_name = file_transfer.file_name.substring(0, file_transfer.file_name.length - 4);
+ }
+ }
+}
+
+}