Skip to content

Commit d6b75d1

Browse files
authored
log: Remove optional log dependancy (#131)
This feature isn't enabled by rand/rand_core and provides very little error information that isn't already conveyed through our Error values. This also simplifies the supported configuration space for getrandom. We update the docs and CI to match this change.
1 parent 0f14f2a commit d6b75d1

11 files changed

+14
-63
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,13 @@ matrix:
9191
- cargo test --benches
9292
# Check that setting various features does not break the build
9393
- cargo build --features=std
94-
- cargo build --features=log
9594
# remove cached documentation, otherwise files from previous PRs can get included
9695
- rm -rf target/doc
9796
- cargo doc --no-deps --features=std
9897
- cargo deadlinks --dir target/doc
9998
# also test minimum dependency versions are usable
10099
- cargo generate-lockfile -Z minimal-versions
101-
- cargo test --features=std,log
100+
- cargo test --features=std
102101

103102
- <<: *nightly_and_docs
104103
name: "OSX, nightly, docs"

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ travis-ci = { repository = "rust-random/getrandom" }
1515
appveyor = { repository = "rust-random/getrandom" }
1616

1717
[dependencies]
18-
log = { version = "0.4", optional = true }
1918
cfg-if = "0.1.2"
2019

2120
# When built as part of libstd

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Add this to your `Cargo.toml`:
2424

2525
```toml
2626
[dependencies]
27-
getrandom = "0.1"
27+
getrandom = "0.2"
2828
```
2929

3030
Then invoke the `getrandom` function:
@@ -44,9 +44,6 @@ usually requires calling some external system API. This means most platforms
4444
will require linking against system libraries (i.e. `libc` for Unix,
4545
`Advapi32.dll` for Windows, Security framework on iOS, etc...).
4646

47-
The `log` library is supported as an optional dependency. If enabled, error
48-
reporting will be improved on some platforms.
49-
5047
For the `wasm32-unknown-unknown` target, one of the following features should be
5148
enabled:
5249

src/bsd_arandom.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ fn kern_arnd(buf: &mut [u8]) -> libc::ssize_t {
2525
)
2626
};
2727
if ret == -1 {
28-
error!("sysctl kern.arandom: syscall failed");
2928
-1
3029
} else {
3130
len as libc::ssize_t

src/cloudabi.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ extern "C" {
1717
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1818
let errno = unsafe { cloudabi_sys_random_get(dest.as_mut_ptr(), dest.len()) };
1919
if let Some(code) = NonZeroU32::new(errno as u32) {
20-
error!("cloudabi_sys_random_get: failed with {}", errno);
2120
Err(Error::from(code))
2221
} else {
2322
Ok(()) // Zero means success for CloudABI

src/lib.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -132,27 +132,6 @@
132132
#[macro_use]
133133
extern crate cfg_if;
134134

135-
cfg_if! {
136-
if #[cfg(feature = "log")] {
137-
#[allow(unused)]
138-
#[macro_use]
139-
extern crate log;
140-
} else {
141-
#[allow(unused)]
142-
macro_rules! error {
143-
($($x:tt)*) => {};
144-
}
145-
#[allow(unused)]
146-
macro_rules! warn {
147-
($($x:tt)*) => {};
148-
}
149-
#[allow(unused)]
150-
macro_rules! info {
151-
($($x:tt)*) => {};
152-
}
153-
}
154-
}
155-
156135
mod error;
157136
mod util;
158137

src/macos.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
2020
for chunk in dest.chunks_mut(256) {
2121
let ret = unsafe { func(chunk.as_mut_ptr(), chunk.len()) };
2222
if ret != 0 {
23-
let err = last_os_error();
24-
error!("getentropy syscall failed");
25-
return Err(err);
23+
return Err(last_os_error());
2624
}
2725
}
2826
Ok(())

src/openbsd.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1414
for chunk in dest.chunks_mut(256) {
1515
let ret = unsafe { libc::getentropy(chunk.as_mut_ptr() as *mut libc::c_void, chunk.len()) };
1616
if ret == -1 {
17-
let err = last_os_error();
18-
error!("libc::getentropy call failed");
19-
return Err(err);
17+
return Err(last_os_error());
2018
}
2119
}
2220
Ok(())

src/rdrand.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ unsafe fn rdrand() -> Result<[u8; WORD_SIZE], Error> {
3232
if el != 0 && el != !0 {
3333
return Ok(el.to_ne_bytes());
3434
}
35-
error!("RDRAND returned {:X}, CPU RNG may be broken", el);
3635
// Keep looping in case this was a false positive.
3736
}
3837
}

src/wasm32_stdweb.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ use core::mem;
1313
use std::sync::Once;
1414

1515
use stdweb::js;
16-
use stdweb::unstable::TryInto;
17-
use stdweb::web::error::Error as WebError;
1816

1917
use crate::Error;
2018

@@ -68,8 +66,6 @@ fn getrandom_init() -> Result<RngSource, Error> {
6866
unreachable!()
6967
}
7068
} else {
71-
let _err: WebError = js! { return @{ result }.error }.try_into().unwrap();
72-
error!("getrandom unavailable: {}", _err);
7369
Err(Error::STDWEB_NO_RNG)
7470
}
7571
}
@@ -104,8 +100,6 @@ fn getrandom_fill(source: RngSource, dest: &mut [u8]) -> Result<(), Error> {
104100
};
105101

106102
if js! { return @{ result.as_ref() }.success } != true {
107-
let _err: WebError = js! { return @{ result }.error }.try_into().unwrap();
108-
error!("getrandom failed: {}", _err);
109103
return Err(Error::STDWEB_RNG_FAILED);
110104
}
111105
}

src/windows_uwp.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,16 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
3333
BCRYPT_USE_SYSTEM_PREFERRED_RNG,
3434
)
3535
};
36-
// NTSTATUS codes use two highest bits for severity status
37-
match ret >> 30 {
38-
0b01 => {
39-
info!("BCryptGenRandom: information code 0x{:08X}", ret);
40-
}
41-
0b10 => {
42-
warn!("BCryptGenRandom: warning code 0x{:08X}", ret);
43-
}
44-
0b11 => {
45-
error!("BCryptGenRandom: failed with 0x{:08X}", ret);
46-
// We zeroize the highest bit, so the error code will reside
47-
// inside the range of designated for OS codes.
48-
let code = ret ^ (1 << 31);
49-
// SAFETY: the second highest bit is always equal to one,
50-
// so it's impossible to get zero. Unfortunately compiler
51-
// is not smart enough to figure out it yet.
52-
let code = unsafe { NonZeroU32::new_unchecked(code) };
53-
return Err(Error::from(code));
54-
}
55-
_ => (),
36+
// NTSTATUS codes use the two highest bits for severity status.
37+
if ret >> 30 == 0b11 {
38+
// We zeroize the highest bit, so the error code will reside
39+
// inside the range designated for OS codes.
40+
let code = ret ^ (1 << 31);
41+
// SAFETY: the second highest bit is always equal to one,
42+
// so it's impossible to get zero. Unfortunately the type
43+
// system does not have a way to express this yet.
44+
let code = unsafe { NonZeroU32::new_unchecked(code) };
45+
return Err(Error::from(code));
5646
}
5747
}
5848
Ok(())

0 commit comments

Comments
 (0)