Skip to content

Commit a66bb1d

Browse files
committed
consume mutable authenticators
1 parent 36bca8a commit a66bb1d

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

examples/gmail_oauth2.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ struct GmailOAuth2 {
77
access_token: String,
88
}
99

10-
impl async_imap::Authenticator for GmailOAuth2 {
10+
impl async_imap::Authenticator for &GmailOAuth2 {
1111
type Response = String;
12-
#[allow(unused_variables)]
13-
fn process(&self, data: &[u8]) -> Self::Response {
12+
13+
fn process(&mut self, _data: &[u8]) -> Self::Response {
1414
format!(
1515
"user={}\x01auth=Bearer {}\x01\x01",
1616
self.user, self.access_token

src/authenticator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ pub trait Authenticator {
66

77
/// Each base64-decoded server challenge is passed to `process`.
88
/// The returned byte-string is base64-encoded and then sent back to the server.
9-
fn process(&self, challenge: &[u8]) -> Self::Response;
9+
fn process(&mut self, challenge: &[u8]) -> Self::Response;
1010
}

src/client.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ impl<T: Read + Write + Unpin + fmt::Debug + Send> Client<T> {
255255
/// access_token: String,
256256
/// }
257257
///
258-
/// impl async_imap::Authenticator for OAuth2 {
258+
/// impl async_imap::Authenticator for &OAuth2 {
259259
/// type Response = String;
260-
/// fn process(&self, _: &[u8]) -> Self::Response {
260+
/// fn process(&mut self, _: &[u8]) -> Self::Response {
261261
/// format!(
262262
/// "user={}\x01auth=Bearer {}\x01\x01",
263263
/// self.user, self.access_token
@@ -292,7 +292,7 @@ impl<T: Read + Write + Unpin + fmt::Debug + Send> Client<T> {
292292
pub async fn authenticate<A: Authenticator, S: AsRef<str>>(
293293
mut self,
294294
auth_type: S,
295-
authenticator: &A,
295+
authenticator: A,
296296
) -> ::std::result::Result<Session<T>, (Error, Client<T>)> {
297297
let id = ok_or_unauth_client_err!(
298298
self.run_command(&format!("AUTHENTICATE {}", auth_type.as_ref()))
@@ -307,7 +307,7 @@ impl<T: Read + Write + Unpin + fmt::Debug + Send> Client<T> {
307307
async fn do_auth_handshake<A: Authenticator>(
308308
mut self,
309309
id: RequestId,
310-
authenticator: &A,
310+
mut authenticator: A,
311311
) -> ::std::result::Result<Session<T>, (Error, Client<T>)> {
312312
// explicit match blocks neccessary to convert error to tuple and not bind self too
313313
// early (see also comment on `login`)
@@ -326,7 +326,7 @@ impl<T: Read + Write + Unpin + fmt::Debug + Send> Client<T> {
326326
} else {
327327
Vec::new()
328328
};
329-
let raw_response = &authenticator.process(&challenge);
329+
let raw_response = &mut authenticator.process(&challenge);
330330
let auth_response = base64::encode(raw_response);
331331

332332
ok_or_unauth_client_err!(
@@ -1496,9 +1496,9 @@ mod tests {
14961496
enum Authenticate {
14971497
Auth,
14981498
};
1499-
impl Authenticator for Authenticate {
1499+
impl Authenticator for &Authenticate {
15001500
type Response = Vec<u8>;
1501-
fn process(&self, challenge: &[u8]) -> Self::Response {
1501+
fn process(&mut self, challenge: &[u8]) -> Self::Response {
15021502
assert!(challenge == b"bar", "Invalid authenticate challenge");
15031503
b"foo".to_vec()
15041504
}

0 commit comments

Comments
 (0)