Browse Source

devicechannel: check for decryption errors

bboozzoo/device-cache
Maciek Borzecki 10 years ago
parent
commit
ff855cf052
1 changed files with 13 additions and 3 deletions
  1. +13
    -3
      src/devicechannel.vala

+ 13
- 3
src/devicechannel.vala View File

@ -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);


Loading…
Cancel
Save