aboutsummaryrefslogtreecommitdiff
path: root/rand.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rand.rs')
-rw-r--r--rand.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/rand.rs b/rand.rs
index 72acdd19..96565084 100644
--- a/rand.rs
+++ b/rand.rs
@@ -1,4 +1,4 @@
-use libc::{c_uchar, c_int};
+use core::libc::c_int;
#[link_name = "crypto"]
#[abi = "cdecl"]
@@ -10,8 +10,10 @@ pub fn rand_bytes(len: uint) -> ~[u8] {
let mut out = vec::with_capacity(len);
do vec::as_mut_buf(out) |out_buf, len| {
- let r = libcrypto::RAND_bytes(out_buf, len as c_int);
- if r != 1 as c_int { fail }
+ unsafe {
+ let r = libcrypto::RAND_bytes(out_buf, len as c_int);
+ if r != 1 as c_int { fail!() }
+ }
}
unsafe { vec::raw::set_len(&mut out, len); }
@@ -21,6 +23,8 @@ pub fn rand_bytes(len: uint) -> ~[u8] {
#[cfg(test)]
mod tests {
+ use super::*;
+
#[test]
fn test_rand_bytes() {
let bytes = rand_bytes(32u);