Skip to content

Commit

Permalink
Simplify core vs std usage
Browse files Browse the repository at this point in the history
  • Loading branch information
josephlr committed Jun 13, 2019
1 parent 1097eb9 commit 73d6f76
Show file tree
Hide file tree
Showing 19 changed files with 20 additions and 39 deletions.
1 change: 0 additions & 1 deletion src/aead/chacha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use super::{
Block, BLOCK_LEN,
};
use crate::{endian::*, polyfill::convert::*};
use core;
use libc::size_t;

#[repr(C)]
Expand Down
2 changes: 1 addition & 1 deletion src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// as possible.

use crate::{cpu, debug, endian::*, polyfill};
use core::{self, num::Wrapping};
use core::num::Wrapping;
use libc::size_t;

mod sha1;
Expand Down
2 changes: 1 addition & 1 deletion src/digest/sha1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

use crate::polyfill;
use core::{self, num::Wrapping};
use core::num::Wrapping;
use libc::size_t;

pub const BLOCK_LEN: usize = 512 / 8;
Expand Down
1 change: 0 additions & 1 deletion src/ec/curve25519/ed25519/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use crate::{
rand,
signature::{self, KeyPair as SigningKeyPair},
};
use core;
use untrusted;

use super::digest::*;
Expand Down
1 change: 0 additions & 1 deletion src/ec/curve25519/ed25519/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use super::super::ops::*;
use crate::{error, polyfill::convert::*, sealed, signature};
use core;
use untrusted;

use super::digest::*;
Expand Down
1 change: 0 additions & 1 deletion src/ec/suite_b/ecdh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ fn ecdh(
mod tests {
use super::super::ops;
use crate::{agreement, ec, limb, test};
use core;

static SUPPORTED_SUITE_B_ALGS: [(&str, &agreement::Algorithm, &ec::Curve, &ops::CommonOps); 2] = [
(
Expand Down
1 change: 0 additions & 1 deletion src/ec/suite_b/ecdsa/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use crate::{
io::der,
limb, pkcs8, rand, sealed, signature,
};
use core;
use untrusted;

/// An ECDSA signing algorithm.
Expand Down
1 change: 0 additions & 1 deletion src/ec/suite_b/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ extern "C" {
mod tests {
use super::*;
use crate::test;
use std;
use untrusted;

const ZERO_SCALAR: Scalar = Scalar {
Expand Down
7 changes: 1 addition & 6 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@
//! Error reporting.

use crate::polyfill::convert::*;
use core;
use untrusted;

#[cfg(feature = "use_heap")]
use std;

/// An error with absolutely no details.
///
/// *ring* uses this unit type as the error type in most of its results
Expand Down Expand Up @@ -212,8 +208,7 @@ impl std::error::Error for KeyRejected {
}
}

#[cfg(feature = "use_heap")]
impl std::fmt::Display for KeyRejected {
impl core::fmt::Display for KeyRejected {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.write_str(self.description_())
}
Expand Down
1 change: 1 addition & 0 deletions src/io/der_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

use super::{der::*, writer::*, *};
use std::boxed::Box;

pub(crate) fn write_positive_integer(output: &mut Accumulator, value: &Positive) {
let first_byte = value.first_byte();
Expand Down
2 changes: 2 additions & 0 deletions src/io/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

use std::{boxed::Box, vec::Vec};

pub trait Accumulator {
fn write_byte(&mut self, value: u8);
fn write_bytes(&mut self, value: &[u8]);
Expand Down
17 changes: 4 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,12 @@
unused_results,
warnings
)]
#![cfg_attr(
any(
target_os = "redox",
all(
not(test),
not(feature = "use_heap"),
unix,
not(any(target_os = "macos", target_os = "ios")),
any(not(target_os = "linux"), feature = "dev_urandom_fallback")
)
),
no_std
)]
#![no_std]
#![cfg_attr(feature = "internal_benches", allow(unstable_features), feature(test))]

#[cfg(any(test, feature = "use_heap"))]
extern crate std;

#[macro_use]
mod debug;

Expand Down
1 change: 0 additions & 1 deletion src/pkcs8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
//! [RFC 5958]: https://tools.ietf.org/html/rfc5958.

use crate::{ec, error, io::der};
use core;
use untrusted;

pub(crate) enum Version {
Expand Down
2 changes: 0 additions & 2 deletions src/polyfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
//! Polyfills for functionality that will (hopefully) be added to Rust's
//! standard library soon.

use core;

#[macro_use]
pub mod convert;

Expand Down
2 changes: 0 additions & 2 deletions src/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ mod sysrand_chunk {
#[cfg(windows)]
mod sysrand_chunk {
use crate::{error, polyfill};
use core;

#[inline]
pub fn chunk(dest: &mut [u8]) -> Result<usize, error::Unspecified> {
Expand Down Expand Up @@ -212,7 +211,6 @@ mod sysrand {
))]
mod urandom {
use crate::error;
use std;

pub fn fill(dest: &mut [u8]) -> Result<(), error::Unspecified> {
use lazy_static::lazy_static;
Expand Down
8 changes: 6 additions & 2 deletions src/rsa/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ use crate::{
limb::{self, Limb, LimbMask, LIMB_BITS, LIMB_BYTES},
};
use core::{
self,
marker::PhantomData,
ops::{Deref, DerefMut},
};
use libc::size_t;
use std::borrow::ToOwned as _; // TODO: Remove; Redundant as of Rust 1.36.
use std::{
borrow::ToOwned as _, // TODO: Remove; Redundant as of Rust 1.36.
boxed::Box,
vec,
vec::Vec,
};
use untrusted;

pub unsafe trait Prime {}
Expand Down
1 change: 1 addition & 0 deletions src/rsa/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::{
io::{self, der, der_writer},
pkcs8, rand, signature,
};
use std::boxed::Box;
use untrusted;

/// An RSA key pair, used for signing.
Expand Down
1 change: 0 additions & 1 deletion src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@
//! ```

use crate::{cpu, ec, error, sealed};
use core;
use untrusted;

pub use crate::ec::{
Expand Down
7 changes: 3 additions & 4 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ use crate::bits;

use crate::{digest, error};

use core;
use std::{self, string::String, vec::Vec};
use std::{format, string::String, vec::Vec};
use std::{panic, println};

/// `compile_time_assert_clone::<T>();` fails to compile if `T` doesn't
/// implement `Clone`.
Expand Down Expand Up @@ -310,7 +310,7 @@ where

#[allow(box_pointers)]
while let Some(mut test_case) = parse_test_case(&mut current_section, lines) {
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
let result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
f(&current_section, &mut test_case)
}));
let result = match result {
Expand Down Expand Up @@ -455,7 +455,6 @@ fn parse_test_case(
#[allow(missing_docs)]
pub mod rand {
use crate::{error, polyfill, rand, sealed};
use core;

/// An implementation of `SecureRandom` that always fills the output slice
/// with the given byte.
Expand Down

0 comments on commit 73d6f76

Please sign in to comment.