refactor(oauth): safe oauth2 and remove custom json parser (#80)

* refactor(oauth): safe oauth2 and remove custom json parser

Closes #46,#53
This commit is contained in:
Friedel Ziegelmayer
2019-05-26 22:49:52 +02:00
committed by GitHub
parent 94aa314f30
commit a247e5b143
14 changed files with 491 additions and 1095 deletions

View File

@@ -1645,6 +1645,22 @@ pub unsafe fn dc_make_rel_and_copy(
success
}
pub fn to_cstring<S: AsRef<str>>(s: S) -> std::ffi::CString {
std::ffi::CString::new(s.as_ref()).unwrap()
}
pub fn to_string(s: *const libc::c_char) -> String {
if s.is_null() {
return "".into();
}
unsafe { std::ffi::CStr::from_ptr(s).to_str().unwrap().to_string() }
}
pub fn to_str<'a>(s: *const libc::c_char) -> &'a str {
assert!(!s.is_null(), "cannot be used on null pointers");
unsafe { std::ffi::CStr::from_ptr(s).to_str().unwrap() }
}
#[cfg(test)]
mod tests {
use super::*;
@@ -1952,19 +1968,3 @@ mod tests {
}
}
}
pub fn to_cstring<S: AsRef<str>>(s: S) -> std::ffi::CString {
std::ffi::CString::new(s.as_ref()).unwrap()
}
pub fn to_string(s: *const libc::c_char) -> String {
if s.is_null() {
return "".into();
}
unsafe { std::ffi::CStr::from_ptr(s).to_str().unwrap().to_string() }
}
pub fn to_str<'a>(s: *const libc::c_char) -> &'a str {
assert!(!s.is_null(), "cannot be used on null pointers");
unsafe { std::ffi::CStr::from_ptr(s).to_str().unwrap() }
}