mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 21:06:31 +03:00
fix #538 -- don't crash on wrong setup codes for ac-message, don't use "expect(), added test
This commit is contained in:
@@ -110,7 +110,13 @@ class Message(object):
|
|||||||
|
|
||||||
def continue_key_transfer(self, setup_code):
|
def continue_key_transfer(self, setup_code):
|
||||||
""" extract key and use it as primary key for this account. """
|
""" 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
|
@props.with_doc
|
||||||
def time_sent(self):
|
def time_sent(self):
|
||||||
|
|||||||
@@ -537,6 +537,9 @@ class TestOnlineAccount:
|
|||||||
ev = ac2._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
ev = ac2._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
||||||
msg = ac2.get_message_by_id(ev[2])
|
msg = ac2.get_message_by_id(ev[2])
|
||||||
assert msg.is_setup_message()
|
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("*************** Incoming ASM File at: ", msg.filename)
|
||||||
print("*************** Setup Code: ", setup_code)
|
print("*************** Setup Code: ", setup_code)
|
||||||
msg.continue_key_transfer(setup_code)
|
msg.continue_key_transfer(setup_code)
|
||||||
|
|||||||
@@ -289,10 +289,11 @@ pub fn dc_pgp_symm_decrypt(passphrase: &str, ctext: &[u8]) -> Option<Vec<u8>> {
|
|||||||
|
|
||||||
enc_msg
|
enc_msg
|
||||||
.and_then(|msg| {
|
.and_then(|msg| {
|
||||||
let mut decryptor = msg
|
let mut decryptor = msg.decrypt_with_password(|| passphrase.into())?;
|
||||||
.decrypt_with_password(|| passphrase.into())
|
match decryptor.next() {
|
||||||
.expect("failed decryption");
|
Some(x) => x,
|
||||||
decryptor.next().expect("no message")
|
None => Err(pgp::errors::Error::InvalidInput),
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.and_then(|msg| msg.get_content())
|
.and_then(|msg| msg.get_content())
|
||||||
.ok()
|
.ok()
|
||||||
|
|||||||
Reference in New Issue
Block a user