In Authenticator::process change the challenge from a Vec<u8> to a &[u8]

This commit is contained in:
Kim Minh Kaplan 2018-11-10 08:54:46 +00:00
parent 9e0a5d7c8a
commit c2c7e2a3f7
3 changed files with 5 additions and 5 deletions

View file

@ -13,7 +13,7 @@ struct GmailOAuth2 {
impl Authenticator for GmailOAuth2 {
type Response = String;
#[allow(unused_variables)]
fn process(&self, data: Vec<u8>) -> Self::Response {
fn process(&self, data: &[u8]) -> Self::Response {
format!(
"user={}\x01auth=Bearer {}\x01\x01",
self.user, self.access_token

View file

@ -1,5 +1,5 @@
/// This will allow plugable authentication mechanisms.
pub trait Authenticator {
type Response: AsRef<[u8]>;
fn process(&self, Vec<u8>) -> Self::Response;
fn process(&self, &[u8]) -> Self::Response;
}

View file

@ -402,7 +402,7 @@ impl<T: Read + Write> Client<T> {
),
self
);
let raw_response = &authenticator.process(challenge);
let raw_response = &authenticator.process(&challenge);
let auth_response = base64::encode(raw_response);
ok_or_unauth_client_err!(
self.write_line(auth_response.into_bytes().as_slice()),
@ -956,9 +956,9 @@ mod tests {
enum Authenticate { Auth };
impl Authenticator for Authenticate {
type Response = Vec<u8>;
fn process(&self, challenge: Vec<u8>) -> Self::Response {
fn process(&self, challenge: &[u8]) -> Self::Response {
assert!(
challenge == b"bar".to_vec(),
challenge == b"bar",
"Invalid authenticate challenge"
);
b"foo".to_vec()