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 c5532e7a..d8597cf7 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 7a42c72c..631605a1 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 6fb7211e..f51a6bce 100644 --- a/sasl/src/server/mod.rs +++ b/sasl/src/server/mod.rs @@ -1,8 +1,12 @@ use common::{Identity, Credentials}; + +#[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>; } @@ -55,6 +59,7 @@ pub mod mechanisms { } } + #[cfg(feature = "scram")] mod scram { use std::marker::PhantomData; @@ -215,5 +220,6 @@ pub mod mechanisms { } pub use self::plain::Plain; + #[cfg(feature = "scram")] pub use self::scram::Scram; }