auto merge of #14511 : Sawyer47/rust/osrng-rename, r=alexcrichton

According to Rust's style guide acronyms in type names should be
CamelCase.

[breaking-change]
This commit is contained in:
bors 2014-05-29 22:56:44 -07:00
commit af7c030310
5 changed files with 30 additions and 30 deletions

View File

@ -977,8 +977,8 @@ fn to_fn(self) -> |&mut Scheduler, Box<GreenTask>| {
// 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)

View File

@ -24,7 +24,7 @@
///
/// 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
@ -231,7 +231,7 @@ fn rand<R: Rng>(other: &mut R) -> IsaacRng {
///
/// 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

View File

@ -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

View File

@ -32,7 +32,7 @@
# 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.
@ -91,7 +91,7 @@
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;
@ -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() })
}
}
@ -151,7 +151,7 @@ fn from_seed(seed: &'a [uint]) -> 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)
}
@ -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>();
@ -483,7 +483,7 @@ fn rand_xorshift(b: &mut Bencher) {
#[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>();
@ -494,7 +494,7 @@ fn rand_isaac(b: &mut Bencher) {
#[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>();

View File

@ -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 {
@ -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()
}
@ -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
}
@ -105,9 +105,9 @@ fn CryptGenRandom(hProv: HCRYPTPROV,
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,
@ -154,12 +154,12 @@ pub fn new() -> IoResult<OSRng> {
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);
@ -181,7 +181,7 @@ fn fill_bytes(&mut self, v: &mut [u8]) {
}
}
impl Drop for OSRng {
impl Drop for OsRng {
fn drop(&mut self) {
let ret = unsafe {
CryptReleaseContext(self.hcryptprov, 0)
@ -197,13 +197,13 @@ fn drop(&mut self) {
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();
@ -225,7 +225,7 @@ fn test_os_rng_tasks() {
// 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];