diff --git a/src/devicechannel.vala b/src/devicechannel.vala index 0ba7b19..d556a8d 100644 --- a/src/devicechannel.vala +++ b/src/devicechannel.vala @@ -179,15 +179,25 @@ class DeviceChannel : Object { return; } + bool failed = false; var msgbytes = new ByteArray(); arr.foreach_element((a, i, node) => { + // exit early + if (failed == true) + return; + debug("node data: %s", node.get_string()); // encrypted data is base64 encoded uchar[] data = Base64.decode(node.get_string()); var dbytes = new Bytes.take(data); - ByteArray decrypted = this._crypt.decrypt(dbytes); - debug("data length: %zu", decrypted.data.length); - msgbytes.append(decrypted.data); + try { + ByteArray decrypted = this._crypt.decrypt(dbytes); + debug("data length: %zu", decrypted.data.length); + msgbytes.append(decrypted.data); + } catch (Error e) { + critical("decryption failed: %s", e.message); + failed = true; + } }); // data should be complete now debug("total length of packet data: %zu", msgbytes.len);