Skip to content
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

MSRV bump, module changes #15

Merged
merged 5 commits into from
Mar 23, 2019
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
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ sudo: false

matrix:
include:
- rust: 1.28.0
env: DESCRIPTION="Linux, 1.28.0"
- rust: 1.32.0
env: DESCRIPTION="Linux, 1.32.0"
os: linux

- rust: 1.28.0
env: DESCRIPTION="OSX, 1.22.0"
- rust: 1.32.0
env: DESCRIPTION="OSX, 1.32.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason not to use 1.31 as the MSRV? Also you need to update the note in the README.

Copy link
Member Author

@newpavlov newpavlov Mar 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extern crate std; and use std::<..>; in modules does not work on 1.31.0. It fails with "error[E0658]: imports can only refer to extern crate names passed with --extern on stable channel (see issue #53130)". I think we could fix it by moving extern crate std; to lib.rs, but it will add a sizable cfg attribute.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. 1.32 is barely over two months old, but there doesn't appear to be much demand for back compatibility. Perhaps we should not do the same for the main Rand project yet though just in case we need to revert this.

os: osx

- rust: stable
Expand Down Expand Up @@ -123,7 +123,7 @@ matrix:
- source ~/.cargo/env || true
script:
- bash utils/ci/script.sh

- rust: stable
sudo: required
dist: trusty
Expand Down
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "getrandom"
version = "0.1.0"
edition = "2018"
authors = ["The Rand Project Developers"]
license = "MIT OR Apache-2.0"
description = "A small cross-platform library for retrieving random data from system source"
Expand All @@ -14,9 +15,7 @@ travis-ci = { repository = "rust-random/getrandom" }
appveyor = { repository = "rust-random/getrandom" }

[workspace]
members = [
"tests/wasm_bindgen",
]
members = ["tests/wasm_bindgen"]

[dependencies]
log = { version = "0.4", optional = true }
Expand All @@ -36,3 +35,6 @@ fuchsia-cprng = "0.1"
[target.wasm32-unknown-unknown.dependencies]
wasm-bindgen = { version = "0.2.29", optional = true }
stdweb = { version = "0.4.9", optional = true }

[features]
std = []
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ the same set of platforms as Rust's `std` lib.
This is a low-level API. Most users should prefer using high-level random-number
library like [`rand`].

[Rand]: https://crates.io/crates/rand
[`rand`]: https://crates.io/crates/rand


## Usage
Expand Down Expand Up @@ -53,7 +53,7 @@ one of the following features must be enabled:

## Minimum Supported Rust Version

This crate requires Rustc version 1.28.0 or later due to usage of `NonZeroU32`.
This crate requires Rust 1.32.0 or later.


# License
Expand Down
5 changes: 1 addition & 4 deletions src/cloudabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
// except according to those terms.

//! Implementation for CloudABI

extern crate cloudabi;

use core::num::NonZeroU32;
use Error;
use crate::Error;

pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
let errno = unsafe { cloudabi::random_get(dest) };
Expand Down
29 changes: 0 additions & 29 deletions src/dragonfly_haiku.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

//! A dummy implementation for unsupported targets which always returns
//! `Err(Error::UNAVAILABLE)`
use std::num::NonZeroU32;
use Error;
use core::num::NonZeroU32;
use crate::Error;

pub fn getrandom_inner(_: &mut [u8]) -> Result<(), Error> {
error!("no support for this platform");
Expand Down
35 changes: 0 additions & 35 deletions src/emscripten.rs

This file was deleted.

33 changes: 3 additions & 30 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use core::num::NonZeroU32;
use core::convert::From;
use core::fmt;
#[cfg(not(target_env = "sgx"))]
use std::{io, error};

// A randomly-chosen 24-bit prefix for our codes
pub(crate) const CODE_PREFIX: u32 = 0x57f4c500;
Expand All @@ -21,7 +18,7 @@ const CODE_UNAVAILABLE: u32 = CODE_PREFIX | 0x01;
///
/// This type is small and no-std compatible.
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct Error(NonZeroU32);
pub struct Error(pub(crate) NonZeroU32);

impl Error {
/// An unknown error.
Expand All @@ -44,7 +41,7 @@ impl Error {
self.0
}

fn msg(&self) -> Option<&'static str> {
pub(crate) fn msg(&self) -> Option<&'static str> {
if let Some(msg) = super::error_msg_inner(self.0) {
Some(msg)
} else {
Expand Down Expand Up @@ -81,33 +78,9 @@ impl From<NonZeroU32> for Error {
}
}

#[cfg(not(target_env = "sgx"))]
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
err.raw_os_error()
.and_then(|code| NonZeroU32::new(code as u32))
.map(|code| Error(code))
// in practice this should never happen
.unwrap_or(Error::UNKNOWN)
}
}

#[cfg(not(target_env = "sgx"))]
impl From<Error> for io::Error {
fn from(err: Error) -> Self {
match err.msg() {
Some(msg) => io::Error::new(io::ErrorKind::Other, msg),
None => io::Error::from_raw_os_error(err.0.get() as i32),
}
}
}

#[cfg(not(target_env = "sgx"))]
impl error::Error for Error { }

#[cfg(test)]
mod tests {
use std::mem::size_of;
use core::mem::size_of;
use super::Error;

#[test]
Expand Down
34 changes: 34 additions & 0 deletions src/error_impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2018 Developers of the Rand project.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate std;

use std::{io, error};
use core::convert::From;
use core::num::NonZeroU32;
use crate::error::Error;

impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
err.raw_os_error()
.and_then(|code| NonZeroU32::new(code as u32))
.map(|code| Error(code))
// in practice this should never happen
.unwrap_or(Error::UNKNOWN)
}
}

impl From<Error> for io::Error {
fn from(err: Error) -> Self {
match err.msg() {
Some(msg) => io::Error::new(io::ErrorKind::Other, msg),
None => io::Error::from_raw_os_error(err.0.get() as i32),
}
}
}

impl error::Error for Error { }
8 changes: 4 additions & 4 deletions src/freebsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
// except according to those terms.

//! Implementation for FreeBSD
extern crate libc;
extern crate std;

use Error;
use core::ptr;
use crate::Error;
use std::io;
use std::num::NonZeroU32;
use core::ptr;
use core::num::NonZeroU32;

pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
let mib = [libc::CTL_KERN, libc::KERN_ARND];
Expand Down
6 changes: 2 additions & 4 deletions src/fuchsia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
// except according to those terms.

//! Implementation for Fuchsia Zircon
extern crate fuchsia_cprng;

use std::num::NonZeroU32;
use Error;
use core::num::NonZeroU32;
use crate::Error;

pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
fuchsia_cprng::cprng_draw(dest);
Expand Down
Loading