#![deny(missing_docs)]
extern crate openssl;
extern crate base64;
mod error;
pub use error::Error;
#[derive(Clone, Debug)]
pub struct SaslCredentials {
pub username: Option<String>,
pub secret: SaslSecret,
pub channel_binding: ChannelBinding,
}
impl Default for SaslCredentials {
fn default() -> SaslCredentials {
SaslCredentials {
username: None,
secret: SaslSecret::None,
channel_binding: ChannelBinding::None,
}
}
}
impl SaslCredentials {
pub fn with_username<N: Into<String>>(mut self, username: N) -> SaslCredentials {
self.username = Some(username.into());
self
}
pub fn with_password<P: Into<String>>(mut self, password: P) -> SaslCredentials {
self.secret = SaslSecret::Password(password.into());
self
}
pub fn with_channel_binding(mut self, channel_binding: ChannelBinding) -> SaslCredentials {
self.channel_binding = channel_binding;
self
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ChannelBinding {
None,
TlsUnique(Vec<u8>),
}
impl ChannelBinding {
pub fn header(&self) -> &[u8] {
match *self {
ChannelBinding::None => b"n,,",
ChannelBinding::TlsUnique(_) => b"p=tls-unique,,",
}
}
pub fn data(&self) -> &[u8] {
match *self {
ChannelBinding::None => &[],
ChannelBinding::TlsUnique(ref data) => data,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum SaslSecret {
None,
Password(String),
}
pub trait SaslMechanism {
fn name(&self) -> &str;
fn from_credentials(credentials: SaslCredentials) -> Result<Self, String> where Self: Sized;
fn initial(&mut self) -> Result<Vec<u8>, String> {
Ok(Vec::new())
}
fn response(&mut self, _challenge: &[u8]) -> Result<Vec<u8>, String> {
Ok(Vec::new())
}
fn success(&mut self, _data: &[u8]) -> Result<(), String> {
Ok(())
}
}
pub mod mechanisms;