client: Remove Result from Mechanism::initial().

This commit is contained in:
Emmanuel Gil Peyrot 2020-02-25 23:31:21 +01:00
parent c96bdc847b
commit 77460e4a28
3 changed files with 8 additions and 8 deletions

View file

@ -39,12 +39,12 @@ impl Mechanism for Plain {
}
}
fn initial(&mut self) -> Result<Vec<u8>, String> {
fn initial(&mut self) -> Vec<u8> {
let mut auth = Vec::new();
auth.push(0);
auth.extend(self.username.bytes());
auth.push(0);
auth.extend(self.password.bytes());
Ok(auth)
auth
}
}

View file

@ -81,7 +81,7 @@ impl<S: ScramProvider> Mechanism for Scram<S> {
}
}
fn initial(&mut self) -> Result<Vec<u8>, String> {
fn initial(&mut self) -> Vec<u8> {
let mut gs2_header = Vec::new();
gs2_header.extend(self.channel_binding.header());
let mut bare = Vec::new();
@ -93,7 +93,7 @@ impl<S: ScramProvider> Mechanism for Scram<S> {
data.extend(&gs2_header);
data.extend(bare.clone());
self.state = ScramState::SentInitialMessage { initial_message: bare, gs2_header: gs2_header };
Ok(data)
data
}
fn response(&mut self, challenge: &[u8]) -> Result<Vec<u8>, String> {
@ -182,7 +182,7 @@ mod tests {
let client_final = b"c=biws,r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,p=v0X8v3Bz2T0CJGbJQyF0X+HI4Ts=";
let server_final = b"v=rmF9pqV8S7suAoZWja4dJRkFsKQ=";
let mut mechanism = Scram::<Sha1>::new_with_nonce(username, password, client_nonce.to_owned());
let init = mechanism.initial().unwrap();
let init = mechanism.initial();
assert_eq!( String::from_utf8(init.clone()).unwrap()
, String::from_utf8(client_init[..].to_owned()).unwrap() ); // depends on ordering…
let resp = mechanism.response(&server_init[..]).unwrap();
@ -201,7 +201,7 @@ mod tests {
let client_final = b"c=biws,r=rOprNGfwEbeRWgbNEkqO%hvYDpWUa2RaTCAfuxFIlj)hNlF$k0,p=dHzbZapWIk4jUhN+Ute9ytag9zjfMHgsqmmiz7AndVQ=";
let server_final = b"v=6rriTRBi23WpRR/wtup+mMhUZUn/dB5nLTJRsjl95G4=";
let mut mechanism = Scram::<Sha256>::new_with_nonce(username, password, client_nonce.to_owned());
let init = mechanism.initial().unwrap();
let init = mechanism.initial();
assert_eq!( String::from_utf8(init.clone()).unwrap()
, String::from_utf8(client_init[..].to_owned()).unwrap() ); // depends on ordering…
let resp = mechanism.response(&server_init[..]).unwrap();

View file

@ -9,8 +9,8 @@ pub trait Mechanism {
fn from_credentials(credentials: Credentials) -> Result<Self, String> where Self: Sized;
/// Provides initial payload of the SASL mechanism.
fn initial(&mut self) -> Result<Vec<u8>, String> {
Ok(Vec::new())
fn initial(&mut self) -> Vec<u8> {
Vec::new()
}
/// Creates a response to the SASL challenge.