From c2c7e2a3f74e46ba25ec423da08d456dbadd98e1 Mon Sep 17 00:00:00 2001 From: Kim Minh Kaplan Date: Sat, 10 Nov 2018 08:54:46 +0000 Subject: [PATCH] In Authenticator::process change the challenge from a Vec to a &[u8] --- examples/gmail_oauth2.rs | 2 +- src/authenticator.rs | 2 +- src/client.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/gmail_oauth2.rs b/examples/gmail_oauth2.rs index 0fe212c..769be3d 100644 --- a/examples/gmail_oauth2.rs +++ b/examples/gmail_oauth2.rs @@ -13,7 +13,7 @@ struct GmailOAuth2 { impl Authenticator for GmailOAuth2 { type Response = String; #[allow(unused_variables)] - fn process(&self, data: Vec) -> Self::Response { + fn process(&self, data: &[u8]) -> Self::Response { format!( "user={}\x01auth=Bearer {}\x01\x01", self.user, self.access_token diff --git a/src/authenticator.rs b/src/authenticator.rs index 1e5187f..ecfe93d 100644 --- a/src/authenticator.rs +++ b/src/authenticator.rs @@ -1,5 +1,5 @@ /// This will allow plugable authentication mechanisms. pub trait Authenticator { type Response: AsRef<[u8]>; - fn process(&self, Vec) -> Self::Response; + fn process(&self, &[u8]) -> Self::Response; } diff --git a/src/client.rs b/src/client.rs index 017bd1d..cfdebb8 100644 --- a/src/client.rs +++ b/src/client.rs @@ -402,7 +402,7 @@ impl Client { ), 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; - fn process(&self, challenge: Vec) -> 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()