diff --git a/src/dc_imex.rs b/src/dc_imex.rs index a7e015a1e..16009c7e7 100644 --- a/src/dc_imex.rs +++ b/src/dc_imex.rs @@ -1093,7 +1093,7 @@ unsafe fn export_key_to_asc_file( } info!(context, "Exporting key {}", as_str(file_name),); dc_delete_file(context, as_path(file_name)); - if !key.write_asc_to_file(file_name, context) { + if !key.write_asc_to_file(as_path(file_name), context) { error!(context, "Cannot write key to {}", as_str(file_name),); } else { context.call_cb( diff --git a/src/key.rs b/src/key.rs index f6e09c351..c2eee7a5a 100644 --- a/src/key.rs +++ b/src/key.rs @@ -1,6 +1,7 @@ use std::collections::BTreeMap; use std::ffi::{CStr, CString}; use std::io::Cursor; +use std::path::Path; use libc; use pgp::composed::{Deserializable, SignedPublicKey, SignedSecretKey}; @@ -216,17 +217,13 @@ impl Key { .expect("failed to serialize key") } - pub fn write_asc_to_file(&self, file: *const libc::c_char, context: &Context) -> bool { - if file.is_null() { - return false; - } - + pub fn write_asc_to_file(&self, file: impl AsRef, context: &Context) -> bool { let file_content = self.to_asc(None).into_bytes(); - if dc_write_file_safe(context, as_path(file), &file_content) { + if dc_write_file_safe(context, &file, &file_content) { return true; } else { - error!(context, "Cannot write key to {}", as_str(file)); + error!(context, "Cannot write key to {}", file.as_ref().display()); return false; } }