Skip to content
Snippets Groups Projects
Commit d806e79d authored by Peter Limkilde Svendsen's avatar Peter Limkilde Svendsen Committed by Jeremy Soller
Browse files

Use unsafe blocks in crypt.h implementation

parent 3da3ff11
No related branches found
No related tags found
No related merge requests found
// TODO: set this for entire crate when possible
#![deny(unsafe_op_in_unsafe_fn)]
use ::scrypt::password_hash::{Salt, SaltString}; use ::scrypt::password_hash::{Salt, SaltString};
use alloc::{ use alloc::{
ffi::CString, ffi::CString,
...@@ -54,12 +57,14 @@ pub unsafe extern "C" fn crypt_r( ...@@ -54,12 +57,14 @@ pub unsafe extern "C" fn crypt_r(
setting: *const c_char, setting: *const c_char,
data: *mut crypt_data, data: *mut crypt_data,
) -> *mut c_char { ) -> *mut c_char {
if (*data).initialized == 0 { if unsafe { (*data).initialized } == 0 {
*data = crypt_data::new(); unsafe { *data = crypt_data::new() };
} }
let key = CStr::from_ptr(key).to_str().expect("key must be utf-8"); let key = unsafe { CStr::from_ptr(key) }
let setting = CStr::from_ptr(setting) .to_str()
.expect("key must be utf-8");
let setting = unsafe { CStr::from_ptr(setting) }
.to_str() .to_str()
.expect("setting must be utf-8"); .expect("setting must be utf-8");
let setting_bytes = setting.as_bytes(); let setting_bytes = setting.as_bytes();
...@@ -89,8 +94,10 @@ pub unsafe extern "C" fn crypt_r( ...@@ -89,8 +94,10 @@ pub unsafe extern "C" fn crypt_r(
let len = inner.len(); let len = inner.len();
if let Ok(ret) = CString::new(inner) { if let Ok(ret) = CString::new(inner) {
let ret_ptr = ret.into_raw(); let ret_ptr = ret.into_raw();
let dst = (*data).buff.as_mut_ptr(); let dst = unsafe { (*data).buff }.as_mut_ptr();
ptr::copy_nonoverlapping(ret_ptr, dst.cast(), len); unsafe {
ptr::copy_nonoverlapping(ret_ptr, dst.cast(), len);
}
ret_ptr.cast() ret_ptr.cast()
} else { } else {
ptr::null_mut() ptr::null_mut()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment