diff --git a/python/src/deltachat/message.py b/python/src/deltachat/message.py index 745893f40..bfd5a95b1 100644 --- a/python/src/deltachat/message.py +++ b/python/src/deltachat/message.py @@ -110,7 +110,13 @@ class Message(object): def continue_key_transfer(self, setup_code): """ extract key and use it as primary key for this account. """ - lib.dc_continue_key_transfer(self._dc_context, self.id, as_dc_charpointer(setup_code)) + res = lib.dc_continue_key_transfer( + self._dc_context, + self.id, + as_dc_charpointer(setup_code) + ) + if res == 0: + raise ValueError("could not decrypt") @props.with_doc def time_sent(self): diff --git a/python/tests/test_account.py b/python/tests/test_account.py index c0090d27e..43963d9aa 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -537,6 +537,9 @@ class TestOnlineAccount: ev = ac2._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED") msg = ac2.get_message_by_id(ev[2]) assert msg.is_setup_message() + # first try a bad setup code + with pytest.raises(ValueError): + msg.continue_key_transfer(str(reversed(setup_code))) print("*************** Incoming ASM File at: ", msg.filename) print("*************** Setup Code: ", setup_code) msg.continue_key_transfer(setup_code) diff --git a/src/pgp.rs b/src/pgp.rs index 3aa018d68..2a86504b1 100644 --- a/src/pgp.rs +++ b/src/pgp.rs @@ -289,10 +289,11 @@ pub fn dc_pgp_symm_decrypt(passphrase: &str, ctext: &[u8]) -> Option> { enc_msg .and_then(|msg| { - let mut decryptor = msg - .decrypt_with_password(|| passphrase.into()) - .expect("failed decryption"); - decryptor.next().expect("no message") + let mut decryptor = msg.decrypt_with_password(|| passphrase.into())?; + match decryptor.next() { + Some(x) => x, + None => Err(pgp::errors::Error::InvalidInput), + } }) .and_then(|msg| msg.get_content()) .ok()