Fix warnings and compilation with older valac

This commit is contained in:
Marvin W 2019-09-16 23:47:38 +02:00
parent 392cb472ab
commit 9daf18f031
No known key found for this signature in database
GPG key ID: 072E9235DB996F2A
4 changed files with 59 additions and 47 deletions

View file

@ -11,18 +11,18 @@ public class SymmetricCipher {
private static unowned string mode_to_string(GCrypt.Cipher.Mode mode) { private static unowned string mode_to_string(GCrypt.Cipher.Mode mode) {
switch (mode) { switch (mode) {
case ECB: return "ECB"; case GCrypt.Cipher.Mode.ECB: return "ECB";
case CFB: return "CFB"; case GCrypt.Cipher.Mode.CFB: return "CFB";
case CBC: return "CBC"; case GCrypt.Cipher.Mode.CBC: return "CBC";
case STREAM: return "STREAM"; case GCrypt.Cipher.Mode.STREAM: return "STREAM";
case OFB: return "OFB"; case GCrypt.Cipher.Mode.OFB: return "OFB";
case CTR: return "CTR"; case GCrypt.Cipher.Mode.CTR: return "CTR";
case AESWRAP: return "AESWRAP"; case GCrypt.Cipher.Mode.AESWRAP: return "AESWRAP";
case GCM: return "GCM"; case GCrypt.Cipher.Mode.GCM: return "GCM";
case POLY1305: return "POLY1305"; case GCrypt.Cipher.Mode.POLY1305: return "POLY1305";
case OCB: return "OCB"; case GCrypt.Cipher.Mode.OCB: return "OCB";
case CFB8: return "CFB8"; case GCrypt.Cipher.Mode.CFB8: return "CFB8";
case XTS: return "XTS"; case GCrypt.Cipher.Mode.XTS: return "XTS";
} }
return "NONE"; return "NONE";
} }

View file

@ -16,7 +16,11 @@ public abstract class SymmetricCipherConverter : Converter, Object {
} }
public void reset() { public void reset() {
try {
cipher.reset(); cipher.reset();
} catch (Crypto.Error e) {
warning(@"$(e.domain) error while resetting cipher: $(e.message)");
}
} }
} }
@ -33,6 +37,7 @@ public class SymmetricCipherEncrypter : SymmetricCipherConverter {
if ((flags & ConverterFlags.INPUT_AT_END) != 0 && inbuf.length + attached_taglen > outbuf.length) { 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"); throw new IOError.NO_SPACE("CipherConverter needs additional output space to attach tag");
} }
try {
if (inbuf.length > 0) { if (inbuf.length > 0) {
cipher.encrypt(outbuf, inbuf); cipher.encrypt(outbuf, inbuf);
} }
@ -49,6 +54,9 @@ public class SymmetricCipherEncrypter : SymmetricCipherConverter {
return ConverterResult.FLUSHED; return ConverterResult.FLUSHED;
} }
return ConverterResult.CONVERTED; return ConverterResult.CONVERTED;
} catch (Crypto.Error e) {
throw new IOError.FAILED(@"$(e.domain) error while decrypting: $(e.message)");
}
} }
} }
@ -67,6 +75,7 @@ public class SymmetricCipherDecrypter : SymmetricCipherConverter {
} else if ((flags & ConverterFlags.INPUT_AT_END) == 0 && inbuf.length < attached_taglen + 1) { } 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"); throw new IOError.PARTIAL_INPUT("CipherConverter needs additional input to make sure to not accidentally read tag");
} }
try {
inbuf.length -= (int) attached_taglen; inbuf.length -= (int) attached_taglen;
if (inbuf.length > 0) { if (inbuf.length > 0) {
cipher.decrypt(outbuf, inbuf); cipher.decrypt(outbuf, inbuf);
@ -87,6 +96,9 @@ public class SymmetricCipherDecrypter : SymmetricCipherConverter {
return ConverterResult.FLUSHED; return ConverterResult.FLUSHED;
} }
return ConverterResult.CONVERTED; return ConverterResult.CONVERTED;
} catch (Crypto.Error e) {
throw new IOError.FAILED(@"$(e.domain) error while decrypting: $(e.message)");
}
} }
} }
} }

View file

@ -5,7 +5,7 @@ public errordomain Error {
GCRYPT GCRYPT
} }
internal void may_throw_gcrypt_error(GCrypt.Error e) throws GLib.Error { internal void may_throw_gcrypt_error(GCrypt.Error e) throws Error {
if (((int)e) != 0) { if (((int)e) != 0) {
throw new Crypto.Error.GCRYPT(e.to_string()); throw new Crypto.Error.GCRYPT(e.to_string());
} }

View file

@ -39,7 +39,7 @@ public class Module : XmppStreamModule, SecurityPrecondition {
string cipher = jet_options.cipher_uri; string cipher = jet_options.cipher_uri;
string type = jet_options.type_uri; string type = jet_options.type_uri;
if (!envelop_encodings.has_key(type) || !ciphers.has_key(cipher)) { if (!envelop_encodings.has_key(type) || !ciphers.has_key(cipher)) {
throw new IqError.NOT_IMPLEMENTED("JET cipher or type unknown"); throw new Jingle.Error.UNSUPPORTED_SECURITY("JET cipher or type unknown");
} }
EnvelopEncoding encoding = envelop_encodings[type]; EnvelopEncoding encoding = envelop_encodings[type];
return new SecurityParameters(ciphers[cipher], encoding, ciphers[cipher].generate_random_secret(), jet_options); return new SecurityParameters(ciphers[cipher], encoding, ciphers[cipher].generate_random_secret(), jet_options);