mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
Return Result<String> from dc_decrypt_setup_file
This commit is contained in:
committed by
holger krekel
parent
02b73207f9
commit
cb499ae502
@@ -244,14 +244,15 @@ pub fn dc_continue_key_transfer(context: &Context, msg_id: u32, setup_code: &str
|
|||||||
if let Some(filename) = msg.get_file(context) {
|
if let Some(filename) = msg.get_file(context) {
|
||||||
if let Ok(buf) = dc_read_file(context, filename) {
|
if let Ok(buf) = dc_read_file(context, filename) {
|
||||||
let norm_sc = CString::yolo(dc_normalize_setup_code(setup_code));
|
let norm_sc = CString::yolo(dc_normalize_setup_code(setup_code));
|
||||||
let armored_key: String;
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let sc = dc_decrypt_setup_file(context, norm_sc.as_ptr(), buf.as_ptr().cast());
|
if let Ok(armored_key) =
|
||||||
ensure!(!sc.is_null(), "bad setup code");
|
dc_decrypt_setup_file(context, norm_sc.as_ptr(), buf.as_ptr().cast())
|
||||||
armored_key = to_string(sc);
|
{
|
||||||
free(sc as *mut libc::c_void);
|
set_self_key(context, &armored_key, true, true)?;
|
||||||
|
} else {
|
||||||
|
bail!("Bad setup code.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
set_self_key(context, &armored_key, true, true)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
bail!("Cannot read Autocrypt Setup Message file.");
|
bail!("Cannot read Autocrypt Setup Message file.");
|
||||||
@@ -333,7 +334,7 @@ pub unsafe fn dc_decrypt_setup_file(
|
|||||||
context: &Context,
|
context: &Context,
|
||||||
passphrase: *const libc::c_char,
|
passphrase: *const libc::c_char,
|
||||||
filecontent: *const libc::c_char,
|
filecontent: *const libc::c_char,
|
||||||
) -> *mut libc::c_char {
|
) -> Result<String> {
|
||||||
let fc_buf: *mut libc::c_char;
|
let fc_buf: *mut libc::c_char;
|
||||||
let mut fc_headerline = String::default();
|
let mut fc_headerline = String::default();
|
||||||
let mut fc_base64: *const libc::c_char = ptr::null();
|
let mut fc_base64: *const libc::c_char = ptr::null();
|
||||||
@@ -341,7 +342,8 @@ pub unsafe fn dc_decrypt_setup_file(
|
|||||||
let mut binary_bytes: libc::size_t = 0;
|
let mut binary_bytes: libc::size_t = 0;
|
||||||
let mut indx: libc::size_t = 0;
|
let mut indx: libc::size_t = 0;
|
||||||
|
|
||||||
let mut payload: *mut libc::c_char = ptr::null_mut();
|
let mut payload: Result<String> = Err(format_err!("Failed to decrypt"));
|
||||||
|
|
||||||
fc_buf = dc_strdup(filecontent);
|
fc_buf = dc_strdup(filecontent);
|
||||||
if dc_split_armored_data(
|
if dc_split_armored_data(
|
||||||
fc_buf,
|
fc_buf,
|
||||||
@@ -369,12 +371,10 @@ pub unsafe fn dc_decrypt_setup_file(
|
|||||||
as_str(passphrase),
|
as_str(passphrase),
|
||||||
std::slice::from_raw_parts(binary as *const u8, binary_bytes),
|
std::slice::from_raw_parts(binary as *const u8, binary_bytes),
|
||||||
) {
|
) {
|
||||||
Ok(plain) => {
|
Ok(plain) => payload = Ok(String::from_utf8(plain).unwrap()),
|
||||||
let payload_c = CString::new(plain).unwrap();
|
|
||||||
payload = strdup(payload_c.as_ptr());
|
|
||||||
}
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!(context, "Failed to decrypt message: {:?}", err);
|
error!(context, "Failed to decrypt message: {:?}", err);
|
||||||
|
payload = Err(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,7 +209,8 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
|
|
||||||
assert!(preferencrypt_0.is_null());
|
assert!(preferencrypt_0.is_null());
|
||||||
free(buf_1 as *mut libc::c_void);
|
free(buf_1 as *mut libc::c_void);
|
||||||
buf_1 = dc_decrypt_setup_file(context, S_EM_SETUPCODE, S_EM_SETUPFILE);
|
let decrypted = dc_decrypt_setup_file(context, S_EM_SETUPCODE, S_EM_SETUPFILE).unwrap();
|
||||||
|
buf_1 = decrypted.strdup();
|
||||||
assert!(!buf_1.is_null());
|
assert!(!buf_1.is_null());
|
||||||
assert!(dc_split_armored_data(
|
assert!(dc_split_armored_data(
|
||||||
buf_1,
|
buf_1,
|
||||||
|
|||||||
Reference in New Issue
Block a user