Fixed not building when default-features = false

This commit is contained in:
Gustav Palmqvist 2022-05-20 07:51:51 +02:00
parent 259231bfcc
commit c9931f12a9
5 changed files with 29 additions and 5 deletions

View file

@ -15,8 +15,9 @@ edition = "2018"
gitlab = { repository = "lumi/sasl-rs" }
[features]
default = ["scram"]
default = ["scram", "anonymous"]
scram = ["base64", "getrandom", "sha-1", "sha2", "hmac", "pbkdf2"]
anonymous = ["getrandom"]
[dependencies]
base64 = { version = "0.13", optional = true }

View file

@ -1,8 +1,12 @@
use crate::common::scram::DeriveError;
use crate::common::Credentials;
use hmac::digest::InvalidLength;
use std::fmt;
use crate::common::Credentials;
#[cfg(feature = "scram")]
use crate::common::scram::DeriveError;
#[cfg(feature = "scram")]
use hmac::digest::InvalidLength;
#[derive(Debug, PartialEq)]
pub enum MechanismError {
AnonymousRequiresNoCredentials,
@ -18,7 +22,9 @@ pub enum MechanismError {
NoServerNonce,
NoServerSalt,
NoServerIterations,
#[cfg(feature = "scram")]
DeriveError(DeriveError),
#[cfg(feature = "scram")]
InvalidKeyLength(InvalidLength),
InvalidState,
@ -27,12 +33,14 @@ pub enum MechanismError {
NoSignatureInSuccessResponse,
}
#[cfg(feature = "scram")]
impl From<DeriveError> for MechanismError {
fn from(err: DeriveError) -> MechanismError {
MechanismError::DeriveError(err)
}
}
#[cfg(feature = "scram")]
impl From<InvalidLength> for MechanismError {
fn from(err: InvalidLength) -> MechanismError {
MechanismError::InvalidKeyLength(err)
@ -60,7 +68,9 @@ impl fmt::Display for MechanismError {
MechanismError::NoServerNonce => "no server nonce",
MechanismError::NoServerSalt => "no server salt",
MechanismError::NoServerIterations => "no server iterations",
#[cfg(feature = "scram")]
MechanismError::DeriveError(err) => return write!(fmt, "derive error: {}", err),
#[cfg(feature = "scram")]
MechanismError::InvalidKeyLength(err) =>
return write!(fmt, "invalid key length: {}", err),
MechanismError::InvalidState => "not in the right state to receive this response",

View file

@ -1,5 +1,6 @@
use crate::common::Identity;
use crate::server::{Mechanism, MechanismError, Response};
use getrandom::getrandom;
pub struct Anonymous;

View file

@ -1,8 +1,10 @@
#[cfg(feature = "anonymous")]
mod anonymous;
mod plain;
#[cfg(feature = "scram")]
mod scram;
#[cfg(feature = "anonymous")]
pub use self::anonymous::Anonymous;
pub use self::plain::Plain;
#[cfg(feature = "scram")]

View file

@ -1,8 +1,10 @@
use crate::common::scram::DeriveError;
use crate::common::Identity;
use crate::secret::Secret;
use std::fmt;
#[cfg(feature = "scram")]
use crate::common::scram::DeriveError;
#[macro_export]
macro_rules! impl_validator_using_provider {
( $validator:ty, $secret:ty ) => {
@ -33,6 +35,7 @@ pub trait Validator<S: Secret> {
#[derive(Debug, PartialEq)]
pub enum ProviderError {
AuthenticationFailed,
#[cfg(feature = "scram")]
DeriveError(DeriveError),
}
@ -61,7 +64,9 @@ pub enum MechanismError {
ProviderError(ProviderError),
CannotDecodeResponse,
#[cfg(feature = "scram")]
InvalidKeyLength(hmac::digest::InvalidLength),
#[cfg(any(feature = "scram", feature = "anonymous"))]
RandomFailure(getrandom::Error),
NoProof,
CannotDecodeProof,
@ -69,6 +74,7 @@ pub enum MechanismError {
SaslSessionAlreadyOver,
}
#[cfg(feature = "scram")]
impl From<DeriveError> for ProviderError {
fn from(err: DeriveError) -> ProviderError {
ProviderError::DeriveError(err)
@ -93,12 +99,14 @@ impl From<ValidatorError> for MechanismError {
}
}
#[cfg(feature = "scram")]
impl From<hmac::digest::InvalidLength> for MechanismError {
fn from(err: hmac::digest::InvalidLength) -> MechanismError {
MechanismError::InvalidKeyLength(err)
}
}
#[cfg(any(feature = "scram", feature = "anonymous"))]
impl From<getrandom::Error> for MechanismError {
fn from(err: getrandom::Error) -> MechanismError {
MechanismError::RandomFailure(err)
@ -145,7 +153,9 @@ impl fmt::Display for MechanismError {
MechanismError::ProviderError(err) => write!(fmt, "provider error: {}", err),
MechanismError::CannotDecodeResponse => write!(fmt, "cant decode response"),
#[cfg(feature = "scram")]
MechanismError::InvalidKeyLength(err) => write!(fmt, "invalid key length: {}", err),
#[cfg(any(feature = "scram", feature = "anonymous"))]
MechanismError::RandomFailure(err) => {
write!(fmt, "failure to get random data: {}", err)
}