mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 07:16:31 +03:00
Make dc_split_armored_data return bool (#251)
* Make dc_split_armored_data return bool * Remove double negations
This commit is contained in:
committed by
Lars-Magnus Skog
parent
9314a5a8fd
commit
707c8c2830
@@ -462,20 +462,18 @@ pub unsafe fn dc_decrypt_setup_file(
|
|||||||
|
|
||||||
let mut payload: *mut libc::c_char = 0 as *mut libc::c_char;
|
let mut payload: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
fc_buf = dc_strdup(filecontent);
|
fc_buf = dc_strdup(filecontent);
|
||||||
if !(0
|
if dc_split_armored_data(
|
||||||
== dc_split_armored_data(
|
fc_buf,
|
||||||
fc_buf,
|
&mut fc_headerline,
|
||||||
&mut fc_headerline,
|
0 as *mut *const libc::c_char,
|
||||||
0 as *mut *const libc::c_char,
|
0 as *mut *const libc::c_char,
|
||||||
0 as *mut *const libc::c_char,
|
&mut fc_base64,
|
||||||
&mut fc_base64,
|
) && !fc_headerline.is_null()
|
||||||
)
|
&& strcmp(
|
||||||
|| fc_headerline.is_null()
|
|
||||||
|| strcmp(
|
|
||||||
fc_headerline,
|
fc_headerline,
|
||||||
b"-----BEGIN PGP MESSAGE-----\x00" as *const u8 as *const libc::c_char,
|
b"-----BEGIN PGP MESSAGE-----\x00" as *const u8 as *const libc::c_char,
|
||||||
) != 0i32
|
) == 0
|
||||||
|| fc_base64.is_null())
|
&& !fc_base64.is_null()
|
||||||
{
|
{
|
||||||
/* convert base64 to binary */
|
/* convert base64 to binary */
|
||||||
/*must be freed using mmap_string_unref()*/
|
/*must be freed using mmap_string_unref()*/
|
||||||
@@ -1154,7 +1152,7 @@ unsafe fn import_self_keys(context: &Context, dir_name: *const libc::c_char) ->
|
|||||||
private_key = buf;
|
private_key = buf;
|
||||||
free(buf2 as *mut libc::c_void);
|
free(buf2 as *mut libc::c_void);
|
||||||
buf2 = dc_strdup(buf);
|
buf2 = dc_strdup(buf);
|
||||||
if 0 != dc_split_armored_data(
|
if dc_split_armored_data(
|
||||||
buf2,
|
buf2,
|
||||||
&mut buf2_headerline,
|
&mut buf2_headerline,
|
||||||
0 as *mut *const libc::c_char,
|
0 as *mut *const libc::c_char,
|
||||||
|
|||||||
@@ -1031,19 +1031,17 @@ pub unsafe fn dc_msg_get_setupcodebegin(msg: *const dc_msg_t) -> *mut libc::c_ch
|
|||||||
|| buf.is_null()
|
|| buf.is_null()
|
||||||
|| buf_bytes <= 0)
|
|| buf_bytes <= 0)
|
||||||
{
|
{
|
||||||
if !(0
|
if dc_split_armored_data(
|
||||||
== dc_split_armored_data(
|
buf,
|
||||||
buf,
|
&mut buf_headerline,
|
||||||
&mut buf_headerline,
|
&mut buf_setupcodebegin,
|
||||||
&mut buf_setupcodebegin,
|
0 as *mut *const libc::c_char,
|
||||||
0 as *mut *const libc::c_char,
|
0 as *mut *const libc::c_char,
|
||||||
0 as *mut *const libc::c_char,
|
) && strcmp(
|
||||||
)
|
buf_headerline,
|
||||||
|| strcmp(
|
b"-----BEGIN PGP MESSAGE-----\x00" as *const u8 as *const libc::c_char,
|
||||||
buf_headerline,
|
) == 0
|
||||||
b"-----BEGIN PGP MESSAGE-----\x00" as *const u8 as *const libc::c_char,
|
&& !buf_setupcodebegin.is_null()
|
||||||
) != 0i32
|
|
||||||
|| buf_setupcodebegin.is_null())
|
|
||||||
{
|
{
|
||||||
ret = dc_strdup(buf_setupcodebegin)
|
ret = dc_strdup(buf_setupcodebegin)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,14 @@ use crate::keyring::*;
|
|||||||
use crate::types::*;
|
use crate::types::*;
|
||||||
use crate::x::*;
|
use crate::x::*;
|
||||||
|
|
||||||
// TODO should return bool /rtn
|
|
||||||
pub unsafe fn dc_split_armored_data(
|
pub unsafe fn dc_split_armored_data(
|
||||||
buf: *mut libc::c_char,
|
buf: *mut libc::c_char,
|
||||||
ret_headerline: *mut *const libc::c_char,
|
ret_headerline: *mut *const libc::c_char,
|
||||||
ret_setupcodebegin: *mut *const libc::c_char,
|
ret_setupcodebegin: *mut *const libc::c_char,
|
||||||
ret_preferencrypt: *mut *const libc::c_char,
|
ret_preferencrypt: *mut *const libc::c_char,
|
||||||
ret_base64: *mut *const libc::c_char,
|
ret_base64: *mut *const libc::c_char,
|
||||||
) -> libc::c_int {
|
) -> bool {
|
||||||
let mut success: libc::c_int = 0i32;
|
let mut success = false;
|
||||||
let mut line_chars: size_t = 0i32 as size_t;
|
let mut line_chars: size_t = 0i32 as size_t;
|
||||||
let mut line: *mut libc::c_char = buf;
|
let mut line: *mut libc::c_char = buf;
|
||||||
let mut p1: *mut libc::c_char = buf;
|
let mut p1: *mut libc::c_char = buf;
|
||||||
@@ -128,7 +127,7 @@ pub unsafe fn dc_split_armored_data(
|
|||||||
if !ret_base64.is_null() {
|
if !ret_base64.is_null() {
|
||||||
*ret_base64 = base64
|
*ret_base64 = base64
|
||||||
}
|
}
|
||||||
success = 1i32
|
success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -273,7 +273,6 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
assert!(res.contains(" configured_send_port "));
|
assert!(res.contains(" configured_send_port "));
|
||||||
assert!(res.contains(" configured_server_flags "));
|
assert!(res.contains(" configured_server_flags "));
|
||||||
|
|
||||||
let mut ok: libc::c_int;
|
|
||||||
let mut buf_0: *mut libc::c_char;
|
let mut buf_0: *mut libc::c_char;
|
||||||
let mut headerline: *const libc::c_char = 0 as *const libc::c_char;
|
let mut headerline: *const libc::c_char = 0 as *const libc::c_char;
|
||||||
let mut setupcodebegin: *const libc::c_char = 0 as *const libc::c_char;
|
let mut setupcodebegin: *const libc::c_char = 0 as *const libc::c_char;
|
||||||
@@ -283,14 +282,14 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
b"-----BEGIN PGP MESSAGE-----\nNoVal:\n\ndata\n-----END PGP MESSAGE-----\x00" as *const u8
|
b"-----BEGIN PGP MESSAGE-----\nNoVal:\n\ndata\n-----END PGP MESSAGE-----\x00" as *const u8
|
||||||
as *const libc::c_char,
|
as *const libc::c_char,
|
||||||
);
|
);
|
||||||
ok = dc_split_armored_data(
|
let ok = dc_split_armored_data(
|
||||||
buf_0,
|
buf_0,
|
||||||
&mut headerline,
|
&mut headerline,
|
||||||
&mut setupcodebegin,
|
&mut setupcodebegin,
|
||||||
0 as *mut *const libc::c_char,
|
0 as *mut *const libc::c_char,
|
||||||
&mut base64,
|
&mut base64,
|
||||||
);
|
);
|
||||||
assert_eq!(ok, 1);
|
assert!(ok);
|
||||||
assert!(!headerline.is_null());
|
assert!(!headerline.is_null());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
strcmp(
|
strcmp(
|
||||||
@@ -308,7 +307,7 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
buf_0 =
|
buf_0 =
|
||||||
strdup(b"-----BEGIN PGP MESSAGE-----\n\ndat1\n-----END PGP MESSAGE-----\n-----BEGIN PGP MESSAGE-----\n\ndat2\n-----END PGP MESSAGE-----\x00"
|
strdup(b"-----BEGIN PGP MESSAGE-----\n\ndat1\n-----END PGP MESSAGE-----\n-----BEGIN PGP MESSAGE-----\n\ndat2\n-----END PGP MESSAGE-----\x00"
|
||||||
as *const u8 as *const libc::c_char);
|
as *const u8 as *const libc::c_char);
|
||||||
ok = dc_split_armored_data(
|
let ok = dc_split_armored_data(
|
||||||
buf_0,
|
buf_0,
|
||||||
&mut headerline,
|
&mut headerline,
|
||||||
&mut setupcodebegin,
|
&mut setupcodebegin,
|
||||||
@@ -316,7 +315,7 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
&mut base64,
|
&mut base64,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(ok, 1);
|
assert!(ok);
|
||||||
assert!(!headerline.is_null());
|
assert!(!headerline.is_null());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
strcmp(
|
strcmp(
|
||||||
@@ -335,7 +334,7 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
b"foo \n -----BEGIN PGP MESSAGE----- \n base64-123 \n -----END PGP MESSAGE-----\x00"
|
b"foo \n -----BEGIN PGP MESSAGE----- \n base64-123 \n -----END PGP MESSAGE-----\x00"
|
||||||
as *const u8 as *const libc::c_char,
|
as *const u8 as *const libc::c_char,
|
||||||
);
|
);
|
||||||
ok = dc_split_armored_data(
|
let ok = dc_split_armored_data(
|
||||||
buf_0,
|
buf_0,
|
||||||
&mut headerline,
|
&mut headerline,
|
||||||
&mut setupcodebegin,
|
&mut setupcodebegin,
|
||||||
@@ -343,7 +342,7 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
&mut base64,
|
&mut base64,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(ok, 1);
|
assert!(ok);
|
||||||
assert!(!headerline.is_null());
|
assert!(!headerline.is_null());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
strcmp(
|
strcmp(
|
||||||
@@ -360,7 +359,7 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
free(buf_0 as *mut libc::c_void);
|
free(buf_0 as *mut libc::c_void);
|
||||||
|
|
||||||
buf_0 = strdup(b"foo-----BEGIN PGP MESSAGE-----\x00" as *const u8 as *const libc::c_char);
|
buf_0 = strdup(b"foo-----BEGIN PGP MESSAGE-----\x00" as *const u8 as *const libc::c_char);
|
||||||
ok = dc_split_armored_data(
|
let ok = dc_split_armored_data(
|
||||||
buf_0,
|
buf_0,
|
||||||
&mut headerline,
|
&mut headerline,
|
||||||
&mut setupcodebegin,
|
&mut setupcodebegin,
|
||||||
@@ -368,19 +367,19 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
&mut base64,
|
&mut base64,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(ok, 0);
|
assert!(!ok);
|
||||||
free(buf_0 as *mut libc::c_void);
|
free(buf_0 as *mut libc::c_void);
|
||||||
buf_0 =
|
buf_0 =
|
||||||
strdup(b"foo \n -----BEGIN PGP MESSAGE-----\n Passphrase-BeGIN : 23 \n \n base64-567 \r\n abc \n -----END PGP MESSAGE-----\n\n\n\x00"
|
strdup(b"foo \n -----BEGIN PGP MESSAGE-----\n Passphrase-BeGIN : 23 \n \n base64-567 \r\n abc \n -----END PGP MESSAGE-----\n\n\n\x00"
|
||||||
as *const u8 as *const libc::c_char);
|
as *const u8 as *const libc::c_char);
|
||||||
ok = dc_split_armored_data(
|
let ok = dc_split_armored_data(
|
||||||
buf_0,
|
buf_0,
|
||||||
&mut headerline,
|
&mut headerline,
|
||||||
&mut setupcodebegin,
|
&mut setupcodebegin,
|
||||||
0 as *mut *const libc::c_char,
|
0 as *mut *const libc::c_char,
|
||||||
&mut base64,
|
&mut base64,
|
||||||
);
|
);
|
||||||
assert_eq!(ok, 1);
|
assert!(ok);
|
||||||
assert!(!headerline.is_null());
|
assert!(!headerline.is_null());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
strcmp(
|
strcmp(
|
||||||
@@ -407,14 +406,14 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
buf_0 =
|
buf_0 =
|
||||||
strdup(b"-----BEGIN PGP PRIVATE KEY BLOCK-----\n Autocrypt-Prefer-Encrypt : mutual \n\nbase64\n-----END PGP PRIVATE KEY BLOCK-----\x00"
|
strdup(b"-----BEGIN PGP PRIVATE KEY BLOCK-----\n Autocrypt-Prefer-Encrypt : mutual \n\nbase64\n-----END PGP PRIVATE KEY BLOCK-----\x00"
|
||||||
as *const u8 as *const libc::c_char);
|
as *const u8 as *const libc::c_char);
|
||||||
ok = dc_split_armored_data(
|
let ok = dc_split_armored_data(
|
||||||
buf_0,
|
buf_0,
|
||||||
&mut headerline,
|
&mut headerline,
|
||||||
0 as *mut *const libc::c_char,
|
0 as *mut *const libc::c_char,
|
||||||
&mut preferencrypt,
|
&mut preferencrypt,
|
||||||
&mut base64,
|
&mut base64,
|
||||||
);
|
);
|
||||||
assert_eq!(ok, 1);
|
assert!(ok);
|
||||||
assert!(!headerline.is_null());
|
assert!(!headerline.is_null());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
strcmp(
|
strcmp(
|
||||||
@@ -470,16 +469,13 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
let mut setupcodebegin_0: *const libc::c_char = 0 as *const libc::c_char;
|
let mut setupcodebegin_0: *const libc::c_char = 0 as *const libc::c_char;
|
||||||
let mut preferencrypt_0: *const libc::c_char = 0 as *const libc::c_char;
|
let mut preferencrypt_0: *const libc::c_char = 0 as *const libc::c_char;
|
||||||
buf_1 = strdup(S_EM_SETUPFILE);
|
buf_1 = strdup(S_EM_SETUPFILE);
|
||||||
assert_ne!(
|
assert!(dc_split_armored_data(
|
||||||
0,
|
buf_1,
|
||||||
dc_split_armored_data(
|
&mut headerline_0,
|
||||||
buf_1,
|
&mut setupcodebegin_0,
|
||||||
&mut headerline_0,
|
&mut preferencrypt_0,
|
||||||
&mut setupcodebegin_0,
|
0 as *mut *const libc::c_char,
|
||||||
&mut preferencrypt_0,
|
));
|
||||||
0 as *mut *const libc::c_char,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
assert!(!headerline_0.is_null());
|
assert!(!headerline_0.is_null());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
0,
|
0,
|
||||||
@@ -499,16 +495,13 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
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);
|
buf_1 = dc_decrypt_setup_file(context, S_EM_SETUPCODE, S_EM_SETUPFILE);
|
||||||
assert!(!buf_1.is_null());
|
assert!(!buf_1.is_null());
|
||||||
assert_ne!(
|
assert!(dc_split_armored_data(
|
||||||
0,
|
buf_1,
|
||||||
dc_split_armored_data(
|
&mut headerline_0,
|
||||||
buf_1,
|
&mut setupcodebegin_0,
|
||||||
&mut headerline_0,
|
&mut preferencrypt_0,
|
||||||
&mut setupcodebegin_0,
|
0 as *mut *const libc::c_char,
|
||||||
&mut preferencrypt_0,
|
));
|
||||||
0 as *mut *const libc::c_char,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
assert!(!headerline_0.is_null());
|
assert!(!headerline_0.is_null());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
strcmp(
|
strcmp(
|
||||||
@@ -549,16 +542,13 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
let buf_2: *mut libc::c_char = dc_strdup(setupfile);
|
let buf_2: *mut libc::c_char = dc_strdup(setupfile);
|
||||||
let mut headerline_1: *const libc::c_char = 0 as *const libc::c_char;
|
let mut headerline_1: *const libc::c_char = 0 as *const libc::c_char;
|
||||||
let mut setupcodebegin_1: *const libc::c_char = 0 as *const libc::c_char;
|
let mut setupcodebegin_1: *const libc::c_char = 0 as *const libc::c_char;
|
||||||
assert_eq!(
|
assert!(!dc_split_armored_data(
|
||||||
0,
|
buf_2,
|
||||||
dc_split_armored_data(
|
&mut headerline_1,
|
||||||
buf_2,
|
&mut setupcodebegin_1,
|
||||||
&mut headerline_1,
|
0 as *mut *const libc::c_char,
|
||||||
&mut setupcodebegin_1,
|
0 as *mut *const libc::c_char,
|
||||||
0 as *mut *const libc::c_char,
|
));
|
||||||
0 as *mut *const libc::c_char,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
assert!(!headerline_1.is_null());
|
assert!(!headerline_1.is_null());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
strcmp(
|
strcmp(
|
||||||
@@ -577,16 +567,13 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
let mut headerline_2: *const libc::c_char = 0 as *const libc::c_char;
|
let mut headerline_2: *const libc::c_char = 0 as *const libc::c_char;
|
||||||
payload = dc_decrypt_setup_file(context, setupcode, setupfile);
|
payload = dc_decrypt_setup_file(context, setupcode, setupfile);
|
||||||
assert!(payload.is_null());
|
assert!(payload.is_null());
|
||||||
assert_eq!(
|
assert!(!dc_split_armored_data(
|
||||||
0,
|
payload,
|
||||||
dc_split_armored_data(
|
&mut headerline_2,
|
||||||
payload,
|
0 as *mut *const libc::c_char,
|
||||||
&mut headerline_2,
|
0 as *mut *const libc::c_char,
|
||||||
0 as *mut *const libc::c_char,
|
0 as *mut *const libc::c_char,
|
||||||
0 as *mut *const libc::c_char,
|
));
|
||||||
0 as *mut *const libc::c_char,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
assert!(!headerline_2.is_null());
|
assert!(!headerline_2.is_null());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
strcmp(
|
strcmp(
|
||||||
|
|||||||
Reference in New Issue
Block a user