Move Authenticator to returning an AsRef<u8>.
This commit is contained in:
parent
93d032181d
commit
1dd55ff066
3 changed files with 12 additions and 12 deletions
|
|
@ -2,7 +2,6 @@ extern crate base64;
|
|||
extern crate imap;
|
||||
extern crate native_tls;
|
||||
|
||||
use base64::encode;
|
||||
use imap::authenticator::Authenticator;
|
||||
use native_tls::TlsConnector;
|
||||
|
||||
|
|
@ -12,13 +11,12 @@ struct GmailOAuth2 {
|
|||
}
|
||||
|
||||
impl Authenticator for GmailOAuth2 {
|
||||
type Response = String;
|
||||
#[allow(unused_variables)]
|
||||
fn process(&self, data: String) -> String {
|
||||
encode(
|
||||
format!(
|
||||
"user={}\x01auth=Bearer {}\x01\x01",
|
||||
self.user, self.access_token
|
||||
).as_bytes(),
|
||||
fn process(&self, data: String) -> Self::Response {
|
||||
format!(
|
||||
"user={}\x01auth=Bearer {}\x01\x01",
|
||||
self.user, self.access_token
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
/// This will allow plugable authentication mechanisms.
|
||||
pub trait Authenticator {
|
||||
fn process(&self, String) -> String;
|
||||
type Response: AsRef<[u8]>;
|
||||
fn process(&self, String) -> Self::Response;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -395,8 +395,8 @@ impl<T: Read + Write> Client<T> {
|
|||
parse_authenticate_response(String::from_utf8(line).unwrap()),
|
||||
self
|
||||
);
|
||||
let auth_response = base64::encode(authenticator.process(data).as_str());
|
||||
|
||||
let raw_response = &authenticator.process(data);
|
||||
let auth_response = base64::encode(raw_response);
|
||||
ok_or_unauth_client_err!(
|
||||
self.write_line(auth_response.into_bytes().as_slice()),
|
||||
self
|
||||
|
|
@ -948,8 +948,9 @@ mod tests {
|
|||
let client = Client::new(mock_stream);
|
||||
enum Authenticate { Auth };
|
||||
impl Authenticator for Authenticate {
|
||||
fn process(&self, _: String) -> String {
|
||||
"foo".to_string()
|
||||
type Response = Vec<u8>;
|
||||
fn process(&self, _: String) -> Self::Response {
|
||||
b"foo".to_vec()
|
||||
}
|
||||
}
|
||||
let auth = Authenticate::Auth;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue