refactor: remove poke_public_key() and dc_key_set_from_file() 🔥

This commit is contained in:
Lars-Magnus Skog
2019-05-03 12:47:24 +02:00
parent 95e1cc67b9
commit e65284ff9d
2 changed files with 0 additions and 145 deletions

View File

@@ -198,47 +198,6 @@ unsafe extern "C" fn dc_poke_eml_file(
free(data as *mut libc::c_void);
return success;
}
unsafe extern "C" fn poke_public_key(
mut context: &dc_context_t,
mut addr: *const libc::c_char,
mut public_key_file: *const libc::c_char,
) -> libc::c_int {
/* mainly for testing: if the partner does not support Autocrypt,
encryption is disabled as soon as the first messages comes from the partner */
let mut header: *mut dc_aheader_t = dc_aheader_new();
let mut peerstate: *mut dc_apeerstate_t = dc_apeerstate_new(context);
let mut success: libc::c_int = 0i32;
if !(addr.is_null() || public_key_file.is_null() || peerstate.is_null() || header.is_null()) {
(*header).addr = dc_strdup(addr);
(*header).prefer_encrypt = 1i32;
if 0 == dc_key_set_from_file((*header).public_key, public_key_file, context)
|| 0 == dc_pgp_is_valid_key(context, (*header).public_key)
{
dc_log_warning(
context,
0i32,
b"No valid key found in \"%s\".\x00" as *const u8 as *const libc::c_char,
public_key_file,
);
} else {
if 0 != dc_apeerstate_load_by_addr(
peerstate,
&context.sql.clone().read().unwrap(),
addr,
) {
dc_apeerstate_apply_header(peerstate, header, time(0 as *mut time_t));
dc_apeerstate_save_to_db(peerstate, &context.sql.clone().read().unwrap(), 0i32);
} else {
dc_apeerstate_init_from_header(peerstate, header, time(0 as *mut time_t));
dc_apeerstate_save_to_db(peerstate, &context.sql.clone().read().unwrap(), 1i32);
}
success = 1i32
}
}
dc_apeerstate_unref(peerstate);
dc_aheader_unref(header);
return success;
}
/* *
* Import a file to the database.
* For testing, import a folder with eml-files, a single eml-file, e-mail plus public key and so on.
@@ -307,28 +266,6 @@ unsafe extern "C" fn poke_spec(
read_cnt += 1
}
current_block = 1622411330066726685;
} else if !suffix.is_null()
&& (strcmp(suffix, b"pem\x00" as *const u8 as *const libc::c_char) == 0i32
|| strcmp(suffix, b"asc\x00" as *const u8 as *const libc::c_char) == 0i32)
{
/* import a publix key */
let mut separator: *mut libc::c_char = strchr(real_spec, ' ' as i32);
if separator.is_null() {
dc_log_error(
context,
0i32,
b"Import: Key files must be specified as \"<addr> <key-file>\".\x00"
as *const u8 as *const libc::c_char,
);
current_block = 8522321847195001863;
} else {
*separator = 0i32 as libc::c_char;
if 0 != poke_public_key(context, real_spec, separator.offset(1isize)) {
read_cnt += 1
}
*separator = ' ' as i32 as libc::c_char;
current_block = 1622411330066726685;
}
} else {
/* import a directory */
dir = opendir(real_spec);

View File

@@ -146,88 +146,6 @@ pub unsafe fn dc_key_set_from_base64(
mmap_string_unref(result);
return 1i32;
}
pub unsafe fn dc_key_set_from_file(
mut key: *mut dc_key_t,
mut pathNfilename: *const libc::c_char,
mut context: &dc_context_t,
) -> libc::c_int {
let mut current_block: u64;
let mut buf: *mut libc::c_char = 0 as *mut libc::c_char;
// just pointer inside buf, must not be freed
let mut headerline: *const libc::c_char = 0 as *const libc::c_char;
// - " -
let mut base64: *const libc::c_char = 0 as *const libc::c_char;
let mut buf_bytes: size_t = 0i32 as size_t;
let mut type_0: libc::c_int = -1i32;
let mut success: libc::c_int = 0i32;
dc_key_empty(key);
if !(key.is_null() || pathNfilename.is_null()) {
if !(0
== dc_read_file(
context,
pathNfilename,
&mut buf as *mut *mut libc::c_char as *mut *mut libc::c_void,
&mut buf_bytes,
)
|| buf_bytes < 50)
{
/* error is already loged */
if !(0
== dc_split_armored_data(
buf,
&mut headerline,
0 as *mut *const libc::c_char,
0 as *mut *const libc::c_char,
&mut base64,
)
|| headerline.is_null()
|| base64.is_null())
{
if strcmp(
headerline,
b"-----BEGIN PGP PUBLIC KEY BLOCK-----\x00" as *const u8 as *const libc::c_char,
) == 0i32
{
type_0 = 0i32;
current_block = 7149356873433890176;
} else if strcmp(
headerline,
b"-----BEGIN PGP PRIVATE KEY BLOCK-----\x00" as *const u8
as *const libc::c_char,
) == 0i32
{
type_0 = 1i32;
current_block = 7149356873433890176;
} else {
dc_log_warning(
context,
0i32,
b"Header missing for key \"%s\".\x00" as *const u8 as *const libc::c_char,
pathNfilename,
);
current_block = 7704194852291245876;
}
match current_block {
7704194852291245876 => {}
_ => {
if 0 == dc_key_set_from_base64(key, base64, type_0) {
dc_log_warning(
context,
0i32,
b"Bad data in key \"%s\".\x00" as *const u8 as *const libc::c_char,
pathNfilename,
);
} else {
success = 1i32
}
}
}
}
}
}
free(buf as *mut libc::c_void);
return success;
}
pub unsafe fn dc_key_equals(mut key: *const dc_key_t, mut o: *const dc_key_t) -> libc::c_int {
if key.is_null()
|| o.is_null()