aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/rand.rs
diff options
context:
space:
mode:
authorErick Tryzelaar <[email protected]>2013-12-27 22:02:38 -0500
committerErick Tryzelaar <[email protected]>2013-12-27 22:02:38 -0500
commit85e6d1db12e63a24e9afc1d61c604597dc6c91d5 (patch)
treea75a30f41deba1b09966acd8df637ccfbfb533ce /src/crypto/rand.rs
parentSwitch over to rustpkg (diff)
downloadrust-openssl-85e6d1db12e63a24e9afc1d61c604597dc6c91d5.tar.xz
rust-openssl-85e6d1db12e63a24e9afc1d61c604597dc6c91d5.zip
update to rust 0.9-pre (a5fa1d9)
Diffstat (limited to 'src/crypto/rand.rs')
-rw-r--r--src/crypto/rand.rs24
1 files changed, 10 insertions, 14 deletions
diff --git a/src/crypto/rand.rs b/src/crypto/rand.rs
index 6510b9f4..4e95046b 100644
--- a/src/crypto/rand.rs
+++ b/src/crypto/rand.rs
@@ -1,31 +1,27 @@
use std::libc::c_int;
use std::vec;
-mod libcrypto {
- use std::libc::c_int;
-
- #[link(name = "crypto")]
- extern {
- pub fn RAND_bytes(buf: *mut u8, num: c_int) -> c_int;
- }
+#[link(name = "crypto")]
+extern {
+ fn RAND_bytes(buf: *mut u8, num: c_int) -> c_int;
}
pub fn rand_bytes(len: uint) -> ~[u8] {
- let mut out = vec::with_capacity(len);
+ unsafe {
+ let mut out = vec::with_capacity(len);
- out.as_mut_buf(|out_buf, len| {
- let r = unsafe { libcrypto::RAND_bytes(out_buf, len as c_int) };
+ let r = RAND_bytes(out.as_mut_ptr(), len as c_int);
if r != 1 as c_int { fail!() }
- });
- unsafe { out.set_len(len); }
+ out.set_len(len);
- out
+ out
+ }
}
#[cfg(test)]
mod tests {
- use super::*;
+ use super::rand_bytes;
#[test]
fn test_rand_bytes() {