In Authenticator::process change the challenge from a Vec<u8> to a &[u8]
This commit is contained in:
parent
9e0a5d7c8a
commit
c2c7e2a3f7
3 changed files with 5 additions and 5 deletions
|
|
@ -13,7 +13,7 @@ struct GmailOAuth2 {
|
||||||
impl Authenticator for GmailOAuth2 {
|
impl Authenticator for GmailOAuth2 {
|
||||||
type Response = String;
|
type Response = String;
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
fn process(&self, data: Vec<u8>) -> Self::Response {
|
fn process(&self, data: &[u8]) -> Self::Response {
|
||||||
format!(
|
format!(
|
||||||
"user={}\x01auth=Bearer {}\x01\x01",
|
"user={}\x01auth=Bearer {}\x01\x01",
|
||||||
self.user, self.access_token
|
self.user, self.access_token
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/// This will allow plugable authentication mechanisms.
|
/// This will allow plugable authentication mechanisms.
|
||||||
pub trait Authenticator {
|
pub trait Authenticator {
|
||||||
type Response: AsRef<[u8]>;
|
type Response: AsRef<[u8]>;
|
||||||
fn process(&self, Vec<u8>) -> Self::Response;
|
fn process(&self, &[u8]) -> Self::Response;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -402,7 +402,7 @@ impl<T: Read + Write> Client<T> {
|
||||||
),
|
),
|
||||||
self
|
self
|
||||||
);
|
);
|
||||||
let raw_response = &authenticator.process(challenge);
|
let raw_response = &authenticator.process(&challenge);
|
||||||
let auth_response = base64::encode(raw_response);
|
let auth_response = base64::encode(raw_response);
|
||||||
ok_or_unauth_client_err!(
|
ok_or_unauth_client_err!(
|
||||||
self.write_line(auth_response.into_bytes().as_slice()),
|
self.write_line(auth_response.into_bytes().as_slice()),
|
||||||
|
|
@ -956,9 +956,9 @@ mod tests {
|
||||||
enum Authenticate { Auth };
|
enum Authenticate { Auth };
|
||||||
impl Authenticator for Authenticate {
|
impl Authenticator for Authenticate {
|
||||||
type Response = Vec<u8>;
|
type Response = Vec<u8>;
|
||||||
fn process(&self, challenge: Vec<u8>) -> Self::Response {
|
fn process(&self, challenge: &[u8]) -> Self::Response {
|
||||||
assert!(
|
assert!(
|
||||||
challenge == b"bar".to_vec(),
|
challenge == b"bar",
|
||||||
"Invalid authenticate challenge"
|
"Invalid authenticate challenge"
|
||||||
);
|
);
|
||||||
b"foo".to_vec()
|
b"foo".to_vec()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue