diff --git a/src/dc_imex.rs b/src/dc_imex.rs index c414fdbf1..8366d6570 100644 --- a/src/dc_imex.rs +++ b/src/dc_imex.rs @@ -462,20 +462,18 @@ pub unsafe fn dc_decrypt_setup_file( let mut payload: *mut libc::c_char = 0 as *mut libc::c_char; fc_buf = dc_strdup(filecontent); - if !(0 - == dc_split_armored_data( - fc_buf, - &mut fc_headerline, - 0 as *mut *const libc::c_char, - 0 as *mut *const libc::c_char, - &mut fc_base64, - ) - || fc_headerline.is_null() - || strcmp( + if dc_split_armored_data( + fc_buf, + &mut fc_headerline, + 0 as *mut *const libc::c_char, + 0 as *mut *const libc::c_char, + &mut fc_base64, + ) && !fc_headerline.is_null() + && strcmp( fc_headerline, b"-----BEGIN PGP MESSAGE-----\x00" as *const u8 as *const libc::c_char, - ) != 0i32 - || fc_base64.is_null()) + ) == 0 + && !fc_base64.is_null() { /* convert base64 to binary */ /*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; free(buf2 as *mut libc::c_void); buf2 = dc_strdup(buf); - if 0 != dc_split_armored_data( + if dc_split_armored_data( buf2, &mut buf2_headerline, 0 as *mut *const libc::c_char, diff --git a/src/dc_msg.rs b/src/dc_msg.rs index b6548f770..6df04d5cb 100644 --- a/src/dc_msg.rs +++ b/src/dc_msg.rs @@ -1031,19 +1031,17 @@ pub unsafe fn dc_msg_get_setupcodebegin(msg: *const dc_msg_t) -> *mut libc::c_ch || buf.is_null() || buf_bytes <= 0) { - if !(0 - == dc_split_armored_data( - buf, - &mut buf_headerline, - &mut buf_setupcodebegin, - 0 as *mut *const libc::c_char, - 0 as *mut *const libc::c_char, - ) - || strcmp( - buf_headerline, - b"-----BEGIN PGP MESSAGE-----\x00" as *const u8 as *const libc::c_char, - ) != 0i32 - || buf_setupcodebegin.is_null()) + if dc_split_armored_data( + buf, + &mut buf_headerline, + &mut buf_setupcodebegin, + 0 as *mut *const libc::c_char, + 0 as *mut *const libc::c_char, + ) && strcmp( + buf_headerline, + b"-----BEGIN PGP MESSAGE-----\x00" as *const u8 as *const libc::c_char, + ) == 0 + && !buf_setupcodebegin.is_null() { ret = dc_strdup(buf_setupcodebegin) } diff --git a/src/pgp.rs b/src/pgp.rs index 600a61fd2..bfc68f281 100644 --- a/src/pgp.rs +++ b/src/pgp.rs @@ -17,15 +17,14 @@ use crate::keyring::*; use crate::types::*; use crate::x::*; -// TODO should return bool /rtn pub unsafe fn dc_split_armored_data( buf: *mut libc::c_char, ret_headerline: *mut *const libc::c_char, ret_setupcodebegin: *mut *const libc::c_char, ret_preferencrypt: *mut *const libc::c_char, ret_base64: *mut *const libc::c_char, -) -> libc::c_int { - let mut success: libc::c_int = 0i32; +) -> bool { + let mut success = false; let mut line_chars: size_t = 0i32 as size_t; let mut line: *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() { *ret_base64 = base64 } - success = 1i32 + success = true; } } } diff --git a/tests/stress.rs b/tests/stress.rs index 1a1e19d87..5b3408686 100644 --- a/tests/stress.rs +++ b/tests/stress.rs @@ -273,7 +273,6 @@ unsafe fn stress_functions(context: &Context) { assert!(res.contains(" configured_send_port ")); assert!(res.contains(" configured_server_flags ")); - let mut ok: libc::c_int; let mut buf_0: *mut 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; @@ -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 as *const libc::c_char, ); - ok = dc_split_armored_data( + let ok = dc_split_armored_data( buf_0, &mut headerline, &mut setupcodebegin, 0 as *mut *const libc::c_char, &mut base64, ); - assert_eq!(ok, 1); + assert!(ok); assert!(!headerline.is_null()); assert_eq!( strcmp( @@ -308,7 +307,7 @@ unsafe fn stress_functions(context: &Context) { buf_0 = 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); - ok = dc_split_armored_data( + let ok = dc_split_armored_data( buf_0, &mut headerline, &mut setupcodebegin, @@ -316,7 +315,7 @@ unsafe fn stress_functions(context: &Context) { &mut base64, ); - assert_eq!(ok, 1); + assert!(ok); assert!(!headerline.is_null()); assert_eq!( 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" as *const u8 as *const libc::c_char, ); - ok = dc_split_armored_data( + let ok = dc_split_armored_data( buf_0, &mut headerline, &mut setupcodebegin, @@ -343,7 +342,7 @@ unsafe fn stress_functions(context: &Context) { &mut base64, ); - assert_eq!(ok, 1); + assert!(ok); assert!(!headerline.is_null()); assert_eq!( strcmp( @@ -360,7 +359,7 @@ unsafe fn stress_functions(context: &Context) { 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); - ok = dc_split_armored_data( + let ok = dc_split_armored_data( buf_0, &mut headerline, &mut setupcodebegin, @@ -368,19 +367,19 @@ unsafe fn stress_functions(context: &Context) { &mut base64, ); - assert_eq!(ok, 0); + assert!(!ok); free(buf_0 as *mut libc::c_void); 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" as *const u8 as *const libc::c_char); - ok = dc_split_armored_data( + let ok = dc_split_armored_data( buf_0, &mut headerline, &mut setupcodebegin, 0 as *mut *const libc::c_char, &mut base64, ); - assert_eq!(ok, 1); + assert!(ok); assert!(!headerline.is_null()); assert_eq!( strcmp( @@ -407,14 +406,14 @@ unsafe fn stress_functions(context: &Context) { buf_0 = 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); - ok = dc_split_armored_data( + let ok = dc_split_armored_data( buf_0, &mut headerline, 0 as *mut *const libc::c_char, &mut preferencrypt, &mut base64, ); - assert_eq!(ok, 1); + assert!(ok); assert!(!headerline.is_null()); assert_eq!( 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 preferencrypt_0: *const libc::c_char = 0 as *const libc::c_char; buf_1 = strdup(S_EM_SETUPFILE); - assert_ne!( - 0, - dc_split_armored_data( - buf_1, - &mut headerline_0, - &mut setupcodebegin_0, - &mut preferencrypt_0, - 0 as *mut *const libc::c_char, - ) - ); + assert!(dc_split_armored_data( + buf_1, + &mut headerline_0, + &mut setupcodebegin_0, + &mut preferencrypt_0, + 0 as *mut *const libc::c_char, + )); assert!(!headerline_0.is_null()); assert_eq!( 0, @@ -499,16 +495,13 @@ unsafe fn stress_functions(context: &Context) { free(buf_1 as *mut libc::c_void); buf_1 = dc_decrypt_setup_file(context, S_EM_SETUPCODE, S_EM_SETUPFILE); assert!(!buf_1.is_null()); - assert_ne!( - 0, - dc_split_armored_data( - buf_1, - &mut headerline_0, - &mut setupcodebegin_0, - &mut preferencrypt_0, - 0 as *mut *const libc::c_char, - ) - ); + assert!(dc_split_armored_data( + buf_1, + &mut headerline_0, + &mut setupcodebegin_0, + &mut preferencrypt_0, + 0 as *mut *const libc::c_char, + )); assert!(!headerline_0.is_null()); assert_eq!( strcmp( @@ -549,16 +542,13 @@ unsafe fn stress_functions(context: &Context) { 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 setupcodebegin_1: *const libc::c_char = 0 as *const libc::c_char; - assert_eq!( - 0, - dc_split_armored_data( - buf_2, - &mut headerline_1, - &mut setupcodebegin_1, - 0 as *mut *const libc::c_char, - 0 as *mut *const libc::c_char, - ) - ); + assert!(!dc_split_armored_data( + buf_2, + &mut headerline_1, + &mut setupcodebegin_1, + 0 as *mut *const libc::c_char, + 0 as *mut *const libc::c_char, + )); assert!(!headerline_1.is_null()); assert_eq!( 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; payload = dc_decrypt_setup_file(context, setupcode, setupfile); assert!(payload.is_null()); - assert_eq!( - 0, - dc_split_armored_data( - payload, - &mut headerline_2, - 0 as *mut *const libc::c_char, - 0 as *mut *const libc::c_char, - 0 as *mut *const libc::c_char, - ) - ); + assert!(!dc_split_armored_data( + payload, + &mut headerline_2, + 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_eq!( strcmp(