From ec315918cd905cdeed84bc4c5b80087e04d68d5d Mon Sep 17 00:00:00 2001 From: roblabla Date: Thu, 11 Jun 2020 14:50:03 +0000 Subject: [PATCH] Cleanly error out when building without the alloc feature --- .travis.yml | 2 +- src/lib.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 31f5818..2419d9e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ script: - if [[ "$TRAVIS_NIGHTLY" == "true" ]]; then cargo test --verbose --all-features; fi - if [[ "$TRAVIS_NIGHTLY" == "true" ]]; then cargo bench --verbose --all-features --no-run; fi - if [[ "$TRAVIS_NIGHTLY" == "true" ]]; then rustup target add thumbv7m-none-eabi; fi - - if [[ "$TRAVIS_NIGHTLY" == "true" ]]; then cargo build --verbose --no-default-features --target thumbv7m-none-eabi; fi + - if [[ "$TRAVIS_NIGHTLY" == "true" ]]; then cargo build --verbose --no-default-features --features=alloc --target thumbv7m-none-eabi; fi - if [[ "$TRAVIS_NIGHTLY" != "true" ]]; then cargo test --verbose; fi cache: cargo diff --git a/src/lib.rs b/src/lib.rs index e40336c..bbcf2b7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,6 +49,9 @@ //! ``` #![cfg_attr(not(test), no_std)] +#[cfg(not(feature = "alloc"))] +compile_error!("This crate does not yet support environments without liballoc. See https://github.com/RustCrypto/RSA/issues/51."); + #[cfg(feature = "alloc")] extern crate alloc; #[cfg(feature = "std")] @@ -67,40 +70,55 @@ extern crate hex; #[cfg(all(test, feature = "serde"))] extern crate serde_test; +#[cfg(feature = "alloc")] pub use num_bigint::BigUint; /// Useful algorithms. +#[cfg(feature = "alloc")] pub mod algorithms; /// Error types. +#[cfg(feature = "alloc")] pub mod errors; /// Supported hash functions. +#[cfg(feature = "alloc")] pub mod hash; /// Supported padding schemes. +#[cfg(feature = "alloc")] pub mod padding; #[cfg(feature = "pem")] pub use pem; +#[cfg(feature = "alloc")] mod key; +#[cfg(feature = "alloc")] mod oaep; #[cfg(feature = "std")] mod parse; +#[cfg(feature = "alloc")] mod pkcs1v15; +#[cfg(feature = "alloc")] mod pss; +#[cfg(feature = "alloc")] mod raw; +#[cfg(feature = "alloc")] pub use self::hash::Hash; +#[cfg(feature = "alloc")] pub use self::key::{PublicKey, PublicKeyParts, RSAPrivateKey, RSAPublicKey}; +#[cfg(feature = "alloc")] pub use self::padding::PaddingScheme; // Optionally expose internals if requested via feature-flag. #[cfg(not(feature = "expose-internals"))] +#[cfg(feature = "alloc")] mod internals; /// Internal raw RSA functions. #[cfg(feature = "expose-internals")] +#[cfg(feature = "alloc")] pub mod internals;