Skip to content

log: Remove optional log dependancy #131

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 3 commits into from
Jan 9, 2020
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
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,13 @@ matrix:
- cargo test --benches
# Check that setting various features does not break the build
- cargo build --features=std
- cargo build --features=log
# remove cached documentation, otherwise files from previous PRs can get included
- rm -rf target/doc
- cargo doc --no-deps --features=std
- cargo deadlinks --dir target/doc
# also test minimum dependency versions are usable
- cargo generate-lockfile -Z minimal-versions
- cargo test --features=std,log
- cargo test --features=std

- <<: *nightly_and_docs
name: "OSX, nightly, docs"
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ travis-ci = { repository = "rust-random/getrandom" }
appveyor = { repository = "rust-random/getrandom" }

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

# When built as part of libstd
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Add this to your `Cargo.toml`:

```toml
[dependencies]
getrandom = "0.1"
getrandom = "0.2"
```

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

The `log` library is supported as an optional dependency. If enabled, error
reporting will be improved on some platforms.

For the `wasm32-unknown-unknown` target, one of the following features should be
enabled:

Expand Down
1 change: 0 additions & 1 deletion src/bsd_arandom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ fn kern_arnd(buf: &mut [u8]) -> libc::ssize_t {
)
};
if ret == -1 {
error!("sysctl kern.arandom: syscall failed");
-1
} else {
len as libc::ssize_t
Expand Down
1 change: 0 additions & 1 deletion src/cloudabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ extern "C" {
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
let errno = unsafe { cloudabi_sys_random_get(dest.as_mut_ptr(), dest.len()) };
if let Some(code) = NonZeroU32::new(errno as u32) {
error!("cloudabi_sys_random_get: failed with {}", errno);
Err(Error::from(code))
} else {
Ok(()) // Zero means success for CloudABI
Expand Down
21 changes: 0 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,27 +132,6 @@
#[macro_use]
extern crate cfg_if;

cfg_if! {
if #[cfg(feature = "log")] {
#[allow(unused)]
#[macro_use]
extern crate log;
} else {
#[allow(unused)]
macro_rules! error {
($($x:tt)*) => {};
}
#[allow(unused)]
macro_rules! warn {
($($x:tt)*) => {};
}
#[allow(unused)]
macro_rules! info {
($($x:tt)*) => {};
}
}
}

mod error;
mod util;

Expand Down
4 changes: 1 addition & 3 deletions src/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
for chunk in dest.chunks_mut(256) {
let ret = unsafe { func(chunk.as_mut_ptr(), chunk.len()) };
if ret != 0 {
let err = last_os_error();
error!("getentropy syscall failed");
return Err(err);
return Err(last_os_error());
}
}
Ok(())
Expand Down
4 changes: 1 addition & 3 deletions src/openbsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
for chunk in dest.chunks_mut(256) {
let ret = unsafe { libc::getentropy(chunk.as_mut_ptr() as *mut libc::c_void, chunk.len()) };
if ret == -1 {
let err = last_os_error();
error!("libc::getentropy call failed");
return Err(err);
return Err(last_os_error());
}
}
Ok(())
Expand Down
1 change: 0 additions & 1 deletion src/rdrand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ unsafe fn rdrand() -> Result<[u8; WORD_SIZE], Error> {
if el != 0 && el != !0 {
return Ok(el.to_ne_bytes());
}
error!("RDRAND returned {:X}, CPU RNG may be broken", el);
// Keep looping in case this was a false positive.
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/wasm32_stdweb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ use core::mem;
use std::sync::Once;

use stdweb::js;
use stdweb::unstable::TryInto;
use stdweb::web::error::Error as WebError;

use crate::Error;

Expand Down Expand Up @@ -68,8 +66,6 @@ fn getrandom_init() -> Result<RngSource, Error> {
unreachable!()
}
} else {
let _err: WebError = js! { return @{ result }.error }.try_into().unwrap();
error!("getrandom unavailable: {}", _err);
Err(Error::STDWEB_NO_RNG)
}
}
Expand Down Expand Up @@ -104,8 +100,6 @@ fn getrandom_fill(source: RngSource, dest: &mut [u8]) -> Result<(), Error> {
};

if js! { return @{ result.as_ref() }.success } != true {
let _err: WebError = js! { return @{ result }.error }.try_into().unwrap();
error!("getrandom failed: {}", _err);
return Err(Error::STDWEB_RNG_FAILED);
}
}
Expand Down
30 changes: 10 additions & 20 deletions src/windows_uwp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,16 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
BCRYPT_USE_SYSTEM_PREFERRED_RNG,
)
};
// NTSTATUS codes use two highest bits for severity status
match ret >> 30 {
0b01 => {
info!("BCryptGenRandom: information code 0x{:08X}", ret);
}
0b10 => {
warn!("BCryptGenRandom: warning code 0x{:08X}", ret);
}
0b11 => {
error!("BCryptGenRandom: failed with 0x{:08X}", ret);
// We zeroize the highest bit, so the error code will reside
// inside the range of designated for OS codes.
let code = ret ^ (1 << 31);
// SAFETY: the second highest bit is always equal to one,
// so it's impossible to get zero. Unfortunately compiler
// is not smart enough to figure out it yet.
let code = unsafe { NonZeroU32::new_unchecked(code) };
return Err(Error::from(code));
}
_ => (),
// NTSTATUS codes use the two highest bits for severity status.
if ret >> 30 == 0b11 {
// We zeroize the highest bit, so the error code will reside
// inside the range designated for OS codes.
let code = ret ^ (1 << 31);
// SAFETY: the second highest bit is always equal to one,
// so it's impossible to get zero. Unfortunately the type
// system does not have a way to express this yet.
let code = unsafe { NonZeroU32::new_unchecked(code) };
return Err(Error::from(code));
}
}
Ok(())
Expand Down