Skip to content

Commit 819a282

Browse files
authored
Merge pull request #19 from pitdicker/drop_pnacl
Drop support for PNaCL
2 parents c4eb96c + b9d9987 commit 819a282

File tree

1 file changed

+0
-66
lines changed

1 file changed

+0
-66
lines changed

src/os.rs

-66
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use {Rng, Error};
2929
/// - Windows: calls `RtlGenRandom`, exported from `advapi32.dll` as
3030
/// `SystemFunction036`.
3131
/// - iOS: calls SecRandomCopyBytes as /dev/(u)random is sandboxed.
32-
/// - PNaCl: calls into the `nacl-irt-random-0.1` IRT interface.
3332
///
3433
/// This usually does not block. On some systems (e.g. FreeBSD, OpenBSD,
3534
/// Max OS X, and modern Linux) this may block very early in the init
@@ -419,71 +418,6 @@ mod imp {
419418
}
420419
}
421420

422-
#[cfg(target_os = "nacl")]
423-
mod imp {
424-
extern crate libc;
425-
426-
use std::io;
427-
use std::mem;
428-
429-
#[derive(Debug)]
430-
pub struct OsRng(extern fn(dest: *mut libc::c_void,
431-
bytes: libc::size_t,
432-
read: *mut libc::size_t) -> libc::c_int);
433-
434-
extern {
435-
fn nacl_interface_query(name: *const libc::c_char,
436-
table: *mut libc::c_void,
437-
table_size: libc::size_t) -> libc::size_t;
438-
}
439-
440-
const INTERFACE: &'static [u8] = b"nacl-irt-random-0.1\0";
441-
442-
#[repr(C)]
443-
struct NaClIRTRandom {
444-
get_random_bytes: Option<extern fn(dest: *mut libc::c_void,
445-
bytes: libc::size_t,
446-
read: *mut libc::size_t) -> libc::c_int>,
447-
}
448-
449-
impl OsRng {
450-
pub fn new() -> Result<OsRng, Error> {
451-
let mut iface = NaClIRTRandom {
452-
get_random_bytes: None,
453-
};
454-
let result = unsafe {
455-
nacl_interface_query(INTERFACE.as_ptr() as *const _,
456-
mem::transmute(&mut iface),
457-
mem::size_of::<NaClIRTRandom>() as libc::size_t)
458-
};
459-
if result != 0 {
460-
assert!(iface.get_random_bytes.is_some());
461-
let result = OsRng(iface.get_random_bytes.take().unwrap());
462-
Ok(result)
463-
} else {
464-
// let error = io::ErrorKind::NotFound;
465-
// let error = io::Error::new(error, "IRT random interface missing");
466-
Err(Result)
467-
}
468-
}
469-
pub fn try_fill(&mut self, v: &mut [u8]) -> Result<(), Error> {
470-
let mut read = 0;
471-
loop {
472-
let mut r: libc::size_t = 0;
473-
let len = v.len();
474-
let error = (self.0)(v[read..].as_mut_ptr() as *mut _,
475-
(len - read) as libc::size_t,
476-
&mut r as *mut _);
477-
assert!(error == 0, "`get_random_bytes` failed!");
478-
read += r as usize;
479-
480-
if read >= v.len() { break; }
481-
}
482-
Ok(())
483-
}
484-
}
485-
}
486-
487421

488422
#[cfg(test)]
489423
mod test {

0 commit comments

Comments
 (0)