forked from proxmox-mirrors/proxmox
cargo fmt --all
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
71f2d48c2e
commit
024930f63c
@ -1,4 +1,3 @@
|
|||||||
//! This is a system utility crate used by all our rust projects.
|
//! This is a system utility crate used by all our rust projects.
|
||||||
|
|
||||||
|
|
||||||
pub mod linux;
|
pub mod linux;
|
||||||
|
@ -5,7 +5,6 @@ use proxmox_tools as tools;
|
|||||||
|
|
||||||
/// Get pseudo random data (/dev/urandom)
|
/// Get pseudo random data (/dev/urandom)
|
||||||
pub fn random_data(size: usize) -> Result<Vec<u8>, Error> {
|
pub fn random_data(size: usize) -> Result<Vec<u8>, Error> {
|
||||||
|
|
||||||
let mut buffer = tools::vec::undefined(size);
|
let mut buffer = tools::vec::undefined(size);
|
||||||
fill_with_random_data(&mut buffer)?;
|
fill_with_random_data(&mut buffer)?;
|
||||||
|
|
||||||
@ -16,7 +15,6 @@ pub fn random_data(size: usize) -> Result<Vec<u8>, Error> {
|
|||||||
///
|
///
|
||||||
/// This code uses the Linux syscall getrandom() - see "man 2 getrandom".
|
/// This code uses the Linux syscall getrandom() - see "man 2 getrandom".
|
||||||
pub fn fill_with_random_data(buffer: &mut [u8]) -> Result<(), Error> {
|
pub fn fill_with_random_data(buffer: &mut [u8]) -> Result<(), Error> {
|
||||||
|
|
||||||
let res = unsafe {
|
let res = unsafe {
|
||||||
libc::syscall(
|
libc::syscall(
|
||||||
libc::SYS_getrandom,
|
libc::SYS_getrandom,
|
||||||
@ -30,7 +28,8 @@ pub fn fill_with_random_data(buffer: &mut [u8]) -> Result<(), Error> {
|
|||||||
return Err(std::io::Error::last_os_error().into());
|
return Err(std::io::Error::last_os_error().into());
|
||||||
}
|
}
|
||||||
|
|
||||||
if res as usize != buffer.len() { // should not happen
|
if res as usize != buffer.len() {
|
||||||
|
// should not happen
|
||||||
bail!("short getrandom read");
|
bail!("short getrandom read");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
pub use proxmox_tools as tools;
|
|
||||||
pub use proxmox_sys as sys;
|
pub use proxmox_sys as sys;
|
||||||
|
pub use proxmox_tools as tools;
|
||||||
|
|
||||||
// Both `proxmox_api` and the 2 macros from `proxmox_api_macro` should be
|
// Both `proxmox_api` and the 2 macros from `proxmox_api_macro` should be
|
||||||
// exposed via `proxmox::api`.
|
// exposed via `proxmox::api`.
|
||||||
|
Loading…
Reference in New Issue
Block a user