Skip to content

Rename OSRng to OsRng #14511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libgreen/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,8 +977,8 @@ impl ClosureConverter for UnsafeTaskReceiver {
// worry there.
#[cfg(windows)]
fn new_sched_rng() -> XorShiftRng {
use std::rand::OSRng;
match OSRng::new() {
use std::rand::OsRng;
match OsRng::new() {
Ok(mut r) => r.gen(),
Err(e) => {
rtabort!("sched: failed to create seeded RNG: {}", e)
Expand Down
4 changes: 2 additions & 2 deletions src/librand/isaac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static RAND_SIZE: u32 = 1 << RAND_SIZE_LEN;
///
/// The ISAAC algorithm is generally accepted as suitable for
/// cryptographic purposes, but this implementation has not be
/// verified as such. Prefer a generator like `OSRng` that defers to
/// verified as such. Prefer a generator like `OsRng` that defers to
/// the operating system for cases that need high security.
///
/// [1]: Bob Jenkins, [*ISAAC: A fast cryptographic random number
Expand Down Expand Up @@ -231,7 +231,7 @@ static RAND_SIZE_64: uint = 1 << RAND_SIZE_64_LEN;
///
/// The ISAAC algorithm is generally accepted as suitable for
/// cryptographic purposes, but this implementation has not be
/// verified as such. Prefer a generator like `OSRng` that defers to
/// verified as such. Prefer a generator like `OsRng` that defers to
/// the operating system for cases that need high security.
///
/// [1]: Bob Jenkins, [*ISAAC: A fast cryptographic random number
Expand Down
2 changes: 1 addition & 1 deletion src/librand/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ pub trait SeedableRng<Seed>: Rng {
///
/// The Xorshift algorithm is not suitable for cryptographic purposes
/// but is very fast. If you do not know for sure that it fits your
/// requirements, use a more secure one such as `IsaacRng` or `OSRng`.
/// requirements, use a more secure one such as `IsaacRng` or `OsRng`.
///
/// [1]: Marsaglia, George (July 2003). ["Xorshift
/// RNGs"](http://www.jstatsoft.org/v08/i14/paper). *Journal of
Expand Down
16 changes: 8 additions & 8 deletions src/libstd/rand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ after generating 32 KiB of random data.
# Cryptographic security

An application that requires an entropy source for cryptographic purposes
must use `OSRng`, which reads randomness from the source that the operating
must use `OsRng`, which reads randomness from the source that the operating
system provides (e.g. `/dev/urandom` on Unixes or `CryptGenRandom()` on Windows).
The other random number generators provided by this module are not suitable
for such purposes.
Expand Down Expand Up @@ -91,7 +91,7 @@ use IsaacWordRng = core_rand::Isaac64Rng;
pub use core_rand::{Rand, Rng, SeedableRng, Open01, Closed01};
pub use core_rand::{XorShiftRng, IsaacRng, Isaac64Rng};
pub use core_rand::{distributions, reseeding};
pub use rand::os::OSRng;
pub use rand::os::OsRng;

pub mod os;
pub mod reader;
Expand All @@ -113,7 +113,7 @@ impl StdRng {
/// Reading the randomness from the OS may fail, and any error is
/// propagated via the `IoResult` return value.
pub fn new() -> IoResult<StdRng> {
OSRng::new().map(|mut r| StdRng { rng: r.gen() })
OsRng::new().map(|mut r| StdRng { rng: r.gen() })
}
}

Expand Down Expand Up @@ -151,7 +151,7 @@ impl<'a> SeedableRng<&'a [uint]> for StdRng {
/// This will read randomness from the operating system to seed the
/// generator.
pub fn weak_rng() -> XorShiftRng {
match OSRng::new() {
match OsRng::new() {
Ok(mut r) => r.gen(),
Err(e) => fail!("weak_rng: failed to create seeded RNG: {}", e)
}
Expand Down Expand Up @@ -467,12 +467,12 @@ mod bench {

use self::test::Bencher;
use super::{XorShiftRng, StdRng, IsaacRng, Isaac64Rng, Rng, RAND_BENCH_N};
use super::{OSRng, weak_rng};
use super::{OsRng, weak_rng};
use mem::size_of;

#[bench]
fn rand_xorshift(b: &mut Bencher) {
let mut rng: XorShiftRng = OSRng::new().unwrap().gen();
let mut rng: XorShiftRng = OsRng::new().unwrap().gen();
b.iter(|| {
for _ in range(0, RAND_BENCH_N) {
rng.gen::<uint>();
Expand All @@ -483,7 +483,7 @@ mod bench {

#[bench]
fn rand_isaac(b: &mut Bencher) {
let mut rng: IsaacRng = OSRng::new().unwrap().gen();
let mut rng: IsaacRng = OsRng::new().unwrap().gen();
b.iter(|| {
for _ in range(0, RAND_BENCH_N) {
rng.gen::<uint>();
Expand All @@ -494,7 +494,7 @@ mod bench {

#[bench]
fn rand_isaac64(b: &mut Bencher) {
let mut rng: Isaac64Rng = OSRng::new().unwrap().gen();
let mut rng: Isaac64Rng = OsRng::new().unwrap().gen();
b.iter(|| {
for _ in range(0, RAND_BENCH_N) {
rng.gen::<uint>();
Expand Down
34 changes: 17 additions & 17 deletions src/libstd/rand/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! Interfaces to the operating system provided random number
//! generators.

pub use self::imp::OSRng;
pub use self::imp::OsRng;

#[cfg(unix)]
mod imp {
Expand All @@ -31,21 +31,21 @@ mod imp {
///
/// This does not block.
#[cfg(unix)]
pub struct OSRng {
pub struct OsRng {
inner: ReaderRng<File>
}

impl OSRng {
/// Create a new `OSRng`.
pub fn new() -> IoResult<OSRng> {
impl OsRng {
/// Create a new `OsRng`.
pub fn new() -> IoResult<OsRng> {
let reader = try!(File::open(&Path::new("/dev/urandom")));
let reader_rng = ReaderRng::new(reader);

Ok(OSRng { inner: reader_rng })
Ok(OsRng { inner: reader_rng })
}
}

impl Rng for OSRng {
impl Rng for OsRng {
fn next_u32(&mut self) -> u32 {
self.inner.next_u32()
}
Expand Down Expand Up @@ -84,7 +84,7 @@ mod imp {
/// service provider with the `PROV_RSA_FULL` type.
///
/// This does not block.
pub struct OSRng {
pub struct OsRng {
hcryptprov: HCRYPTPROV
}

Expand All @@ -105,9 +105,9 @@ mod imp {
fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> BOOL;
}

impl OSRng {
/// Create a new `OSRng`.
pub fn new() -> IoResult<OSRng> {
impl OsRng {
/// Create a new `OsRng`.
pub fn new() -> IoResult<OsRng> {
let mut hcp = 0;
let mut ret = unsafe {
CryptAcquireContextA(&mut hcp, 0 as LPCSTR, 0 as LPCSTR,
Expand Down Expand Up @@ -154,12 +154,12 @@ mod imp {
if ret == 0 {
Err(IoError::last_error())
} else {
Ok(OSRng { hcryptprov: hcp })
Ok(OsRng { hcryptprov: hcp })
}
}
}

impl Rng for OSRng {
impl Rng for OsRng {
fn next_u32(&mut self) -> u32 {
let mut v = [0u8, .. 4];
self.fill_bytes(v);
Expand All @@ -181,7 +181,7 @@ mod imp {
}
}

impl Drop for OSRng {
impl Drop for OsRng {
fn drop(&mut self) {
let ret = unsafe {
CryptReleaseContext(self.hcryptprov, 0)
Expand All @@ -197,13 +197,13 @@ mod imp {
mod test {
use prelude::*;

use super::OSRng;
use super::OsRng;
use rand::Rng;
use task;

#[test]
fn test_os_rng() {
let mut r = OSRng::new().unwrap();
let mut r = OsRng::new().unwrap();

r.next_u32();
r.next_u64();
Expand All @@ -225,7 +225,7 @@ mod test {

// deschedule to attempt to interleave things as much
// as possible (XXX: is this a good test?)
let mut r = OSRng::new().unwrap();
let mut r = OsRng::new().unwrap();
task::deschedule();
let mut v = [0u8, .. 1000];

Expand Down