Skip to content
Snippets Groups Projects
Commit 3c2bc982 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Merge branch 'crypt-unsafe-blocks' into 'master'

Use unsafe blocks in crypt.h implementation

See merge request !503
parents bf46e331 d806e79d
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 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()
......
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