Pass setup_code to dc_continue_key_transfer as &str

This commit is contained in:
Alexander Krotov
2019-09-25 02:01:48 +03:00
committed by holger krekel
parent 8165b76001
commit 60bd053095
3 changed files with 7 additions and 15 deletions

View File

@@ -1573,7 +1573,9 @@ pub unsafe extern "C" fn dc_continue_key_transfer(
}
let ffi_context = &*context;
ffi_context
.with_inner(|ctx| dc_imex::dc_continue_key_transfer(ctx, msg_id, setup_code) as libc::c_int)
.with_inner(|ctx| {
dc_imex::dc_continue_key_transfer(ctx, msg_id, as_str(setup_code)) as libc::c_int
})
.unwrap_or(0)
}

View File

@@ -327,11 +327,6 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
arg1.strdup() as *const _
};
let arg2 = args.next().unwrap_or_default();
let arg2_c = if arg2.is_empty() {
std::ptr::null()
} else {
arg2.strdup() as *const _
};
match arg0 {
"help" | "?" => match arg1 {
@@ -451,7 +446,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
!arg1.is_empty() && !arg2.is_empty(),
"Arguments <msg-id> <setup-code> expected"
);
if !dc_continue_key_transfer(context, arg1.parse()?, arg2_c) {
if !dc_continue_key_transfer(context, arg1.parse()?, &arg2) {
bail!("Continue key transfer failed");
}
}
@@ -1001,7 +996,6 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
}
free(arg1_c as *mut _);
free(arg2_c as *mut _);
Ok(())
}

View File

@@ -253,12 +253,8 @@ pub fn dc_create_setup_code(_context: &Context) -> String {
ret
}
pub unsafe fn dc_continue_key_transfer(
context: &Context,
msg_id: u32,
setup_code: *const libc::c_char,
) -> bool {
if msg_id <= 9i32 as libc::c_uint || setup_code.is_null() {
pub unsafe fn dc_continue_key_transfer(context: &Context, msg_id: u32, setup_code: &str) -> bool {
if msg_id <= 9i32 as libc::c_uint {
return false;
}
@@ -275,7 +271,7 @@ pub unsafe fn dc_continue_key_transfer(
if let Some(filename) = msg.get_file(context) {
if let Ok(buf) = dc_read_file(context, filename) {
let norm_sc = CString::yolo(dc_normalize_setup_code(as_str(setup_code)));
let norm_sc = CString::yolo(dc_normalize_setup_code(setup_code));
let armored_key = dc_decrypt_setup_file(context, norm_sc.as_ptr(), buf.as_ptr().cast());
if armored_key.is_null() {
warn!(context, "Cannot decrypt Autocrypt Setup Message.",);