From a8f8744e21d6c5ff68c9cbf17ba0df45cf9b39f5 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Sat, 25 Mar 2017 14:44:22 +0100 Subject: [PATCH] isolate scram behind a compilation feature --- sasl/Cargo.toml | 9 ++++++++- sasl/src/client/mechanisms/mod.rs | 4 ++++ sasl/src/common/mod.rs | 1 + sasl/src/error.rs | 3 +++ sasl/src/lib.rs | 2 ++ sasl/src/server/mod.rs | 8 +++++++- 6 files changed, 25 insertions(+), 2 deletions(-) diff --git a/sasl/Cargo.toml b/sasl/Cargo.toml index 2f957112..e4b6c486 100644 --- a/sasl/Cargo.toml +++ b/sasl/Cargo.toml @@ -13,6 +13,13 @@ license = "LGPL-3.0+" [badges] gitlab = { repository = "lumi/sasl-rs" } +[features] +default = ["scram"] +scram = ["openssl"] + [dependencies] -openssl = "0.9.7" base64 = "0.4.0" + +[dependencies.openssl] +version = "0.9.7" +optional = true diff --git a/sasl/src/client/mechanisms/mod.rs b/sasl/src/client/mechanisms/mod.rs index 6dba5581..bde2fcbf 100644 --- a/sasl/src/client/mechanisms/mod.rs +++ b/sasl/src/client/mechanisms/mod.rs @@ -2,8 +2,12 @@ mod anonymous; mod plain; + +#[cfg(feature = "scram")] mod scram; pub use self::anonymous::Anonymous; pub use self::plain::Plain; + +#[cfg(feature = "scram")] pub use self::scram::Scram; diff --git a/sasl/src/common/mod.rs b/sasl/src/common/mod.rs index 8e2016a7..21444f78 100644 --- a/sasl/src/common/mod.rs +++ b/sasl/src/common/mod.rs @@ -4,6 +4,7 @@ use std::convert::From; use std::string::FromUtf8Error; +#[cfg(feature = "scram")] pub mod scram; #[derive(Clone, Debug, PartialEq, Eq)] diff --git a/sasl/src/error.rs b/sasl/src/error.rs index 284406bd..6d79df25 100644 --- a/sasl/src/error.rs +++ b/sasl/src/error.rs @@ -1,14 +1,17 @@ +#[cfg(feature = "scram")] use openssl::error::ErrorStack; /// A wrapper enum for things that could go wrong in this crate. #[derive(Debug)] pub enum Error { + #[cfg(feature = "scram")] /// An error in OpenSSL. OpenSslErrorStack(ErrorStack), /// An error in a SASL mechanism. SaslError(String), } +#[cfg(feature = "scram")] impl From for Error { fn from(err: ErrorStack) -> Error { Error::OpenSslErrorStack(err) diff --git a/sasl/src/lib.rs b/sasl/src/lib.rs index b05f6803..af40cd3a 100644 --- a/sasl/src/lib.rs +++ b/sasl/src/lib.rs @@ -124,6 +124,8 @@ //! ``` extern crate base64; + +#[cfg(feature = "scram")] extern crate openssl; mod error; diff --git a/sasl/src/server/mod.rs b/sasl/src/server/mod.rs index 0d28d5e8..ede741a2 100644 --- a/sasl/src/server/mod.rs +++ b/sasl/src/server/mod.rs @@ -1,8 +1,12 @@ -use common::scram::ScramProvider; use common::{Credentials, Identity}; +#[cfg(feature = "scram")] +use common::scram::ScramProvider; + pub trait Validator { fn validate_credentials(&self, credentials: &Credentials) -> Result; + + #[cfg(feature = "scram")] fn request_pbkdf2(&self) -> Result<(Vec, usize, Vec), String>; } @@ -63,6 +67,7 @@ pub mod mechanisms { } } + #[cfg(feature = "scram")] mod scram { use std::marker::PhantomData; @@ -235,5 +240,6 @@ pub mod mechanisms { } pub use self::plain::Plain; + #[cfg(feature = "scram")] pub use self::scram::Scram; }