Merge branch 'crypt-unsafe-blocks' into 'master'
Use unsafe blocks in crypt.h implementation See merge request redox-os/relibc!503
This commit is contained in:
+13
-6
@@ -1,3 +1,6 @@
|
||||
// TODO: set this for entire crate when possible
|
||||
#![deny(unsafe_op_in_unsafe_fn)]
|
||||
|
||||
use ::scrypt::password_hash::{Salt, SaltString};
|
||||
use alloc::{
|
||||
ffi::CString,
|
||||
@@ -54,12 +57,14 @@ pub unsafe extern "C" fn crypt_r(
|
||||
setting: *const c_char,
|
||||
data: *mut crypt_data,
|
||||
) -> *mut c_char {
|
||||
if (*data).initialized == 0 {
|
||||
*data = crypt_data::new();
|
||||
if unsafe { (*data).initialized } == 0 {
|
||||
unsafe { *data = crypt_data::new() };
|
||||
}
|
||||
|
||||
let key = CStr::from_ptr(key).to_str().expect("key must be utf-8");
|
||||
let setting = CStr::from_ptr(setting)
|
||||
let key = unsafe { CStr::from_ptr(key) }
|
||||
.to_str()
|
||||
.expect("key must be utf-8");
|
||||
let setting = unsafe { CStr::from_ptr(setting) }
|
||||
.to_str()
|
||||
.expect("setting must be utf-8");
|
||||
let setting_bytes = setting.as_bytes();
|
||||
@@ -89,8 +94,10 @@ pub unsafe extern "C" fn crypt_r(
|
||||
let len = inner.len();
|
||||
if let Ok(ret) = CString::new(inner) {
|
||||
let ret_ptr = ret.into_raw();
|
||||
let dst = (*data).buff.as_mut_ptr();
|
||||
ptr::copy_nonoverlapping(ret_ptr, dst.cast(), len);
|
||||
let dst = unsafe { (*data).buff }.as_mut_ptr();
|
||||
unsafe {
|
||||
ptr::copy_nonoverlapping(ret_ptr, dst.cast(), len);
|
||||
}
|
||||
ret_ptr.cast()
|
||||
} else {
|
||||
ptr::null_mut()
|
||||
|
||||
Reference in New Issue
Block a user