aboutsummaryrefslogtreecommitdiff
path: root/plugins/openpgp/src/in_file_processor.vala
blob: 2a06bbdfb350eb33c69f2b87eb160affcafe83a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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);
        }
    }
}

}