aboutsummaryrefslogtreecommitdiff
path: root/plugins/crypto-vala/src/cipher_converter.vala
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2019-09-16 23:47:38 +0200
committerMarvin W <git@larma.de>2019-09-16 23:57:48 +0200
commit9daf18f031058ae4c1f13edbf62624bc0345c96f (patch)
tree6dc4d43bc7c4a5681e3814aa95da2c9a24f3268c /plugins/crypto-vala/src/cipher_converter.vala
parent392cb472abcdff9424197c8504175ee79c22dde5 (diff)
downloaddino-9daf18f031058ae4c1f13edbf62624bc0345c96f.tar.gz
dino-9daf18f031058ae4c1f13edbf62624bc0345c96f.zip
Fix warnings and compilation with older valac
Diffstat (limited to 'plugins/crypto-vala/src/cipher_converter.vala')
-rw-r--r--plugins/crypto-vala/src/cipher_converter.vala78
1 files changed, 45 insertions, 33 deletions
diff --git a/plugins/crypto-vala/src/cipher_converter.vala b/plugins/crypto-vala/src/cipher_converter.vala
index 72e11dcd..f1363fb0 100644
--- a/plugins/crypto-vala/src/cipher_converter.vala
+++ b/plugins/crypto-vala/src/cipher_converter.vala
@@ -16,7 +16,11 @@ public abstract class SymmetricCipherConverter : Converter, Object {
}
public void reset() {
- cipher.reset();
+ try {
+ cipher.reset();
+ } catch (Crypto.Error e) {
+ warning(@"$(e.domain) error while resetting cipher: $(e.message)");
+ }
}
}
@@ -33,22 +37,26 @@ public class SymmetricCipherEncrypter : SymmetricCipherConverter {
if ((flags & ConverterFlags.INPUT_AT_END) != 0 && inbuf.length + attached_taglen > outbuf.length) {
throw new IOError.NO_SPACE("CipherConverter needs additional output space to attach tag");
}
- if (inbuf.length > 0) {
- cipher.encrypt(outbuf, inbuf);
- }
- bytes_read = inbuf.length;
- bytes_written = inbuf.length;
- if ((flags & ConverterFlags.INPUT_AT_END) != 0) {
- if (attached_taglen > 0) {
- Memory.copy((uint8*)outbuf + inbuf.length, get_tag(attached_taglen), attached_taglen);
- bytes_written = inbuf.length + attached_taglen;
+ try {
+ if (inbuf.length > 0) {
+ cipher.encrypt(outbuf, inbuf);
}
- return ConverterResult.FINISHED;
- }
- if ((flags & ConverterFlags.FLUSH) != 0) {
- return ConverterResult.FLUSHED;
+ bytes_read = inbuf.length;
+ bytes_written = inbuf.length;
+ if ((flags & ConverterFlags.INPUT_AT_END) != 0) {
+ if (attached_taglen > 0) {
+ Memory.copy((uint8*)outbuf + inbuf.length, get_tag(attached_taglen), attached_taglen);
+ bytes_written = inbuf.length + attached_taglen;
+ }
+ return ConverterResult.FINISHED;
+ }
+ if ((flags & ConverterFlags.FLUSH) != 0) {
+ return ConverterResult.FLUSHED;
+ }
+ return ConverterResult.CONVERTED;
+ } catch (Crypto.Error e) {
+ throw new IOError.FAILED(@"$(e.domain) error while decrypting: $(e.message)");
}
- return ConverterResult.CONVERTED;
}
}
@@ -67,26 +75,30 @@ public class SymmetricCipherDecrypter : SymmetricCipherConverter {
} else if ((flags & ConverterFlags.INPUT_AT_END) == 0 && inbuf.length < attached_taglen + 1) {
throw new IOError.PARTIAL_INPUT("CipherConverter needs additional input to make sure to not accidentally read tag");
}
- inbuf.length -= (int) attached_taglen;
- if (inbuf.length > 0) {
- cipher.decrypt(outbuf, inbuf);
- }
- bytes_read = inbuf.length;
- bytes_written = inbuf.length;
- inbuf.length += (int) attached_taglen;
- if ((flags & ConverterFlags.INPUT_AT_END) != 0) {
- if (attached_taglen > 0) {
- print("Checking tag\n");
- check_tag(inbuf[(inbuf.length - attached_taglen):inbuf.length]);
- print("tag ok\n");
- bytes_read = inbuf.length;
+ try {
+ inbuf.length -= (int) attached_taglen;
+ if (inbuf.length > 0) {
+ cipher.decrypt(outbuf, inbuf);
}
- return ConverterResult.FINISHED;
- }
- if ((flags & ConverterFlags.FLUSH) != 0) {
- return ConverterResult.FLUSHED;
+ bytes_read = inbuf.length;
+ bytes_written = inbuf.length;
+ inbuf.length += (int) attached_taglen;
+ if ((flags & ConverterFlags.INPUT_AT_END) != 0) {
+ if (attached_taglen > 0) {
+ print("Checking tag\n");
+ check_tag(inbuf[(inbuf.length - attached_taglen):inbuf.length]);
+ print("tag ok\n");
+ bytes_read = inbuf.length;
+ }
+ return ConverterResult.FINISHED;
+ }
+ if ((flags & ConverterFlags.FLUSH) != 0) {
+ return ConverterResult.FLUSHED;
+ }
+ return ConverterResult.CONVERTED;
+ } catch (Crypto.Error e) {
+ throw new IOError.FAILED(@"$(e.domain) error while decrypting: $(e.message)");
}
- return ConverterResult.CONVERTED;
}
}
} \ No newline at end of file