RPM build fix (reverted CI changes which will need to be un-reverted or made conditional) and vendor Rust dependencies to make builds much faster in any CI system.
This commit is contained in:
39
zeroidc/vendor/security-framework/src/random.rs
vendored
Normal file
39
zeroidc/vendor/security-framework/src/random.rs
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
//! Randomness support.
|
||||
|
||||
use security_framework_sys::random::*;
|
||||
use std::io;
|
||||
|
||||
/// A source of random data.
|
||||
pub struct SecRandom(SecRandomRef);
|
||||
|
||||
unsafe impl Sync for SecRandom {}
|
||||
unsafe impl Send for SecRandom {}
|
||||
|
||||
impl Default for SecRandom {
|
||||
#[inline(always)]
|
||||
fn default() -> Self {
|
||||
unsafe { Self(kSecRandomDefault) }
|
||||
}
|
||||
}
|
||||
|
||||
impl SecRandom {
|
||||
/// Fills the buffer with cryptographically secure random bytes.
|
||||
pub fn copy_bytes(&self, buf: &mut [u8]) -> io::Result<()> {
|
||||
if unsafe { SecRandomCopyBytes(self.0, buf.len(), buf.as_mut_ptr() as *mut _) } == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(io::Error::last_os_error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn basic() {
|
||||
let mut buf = [0; 10];
|
||||
SecRandom::default().copy_bytes(&mut buf).unwrap();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user