[geary] Code and comment cleanup in SMTP authentication



commit 54426fc063d2cec5535fa3421e441669318b825c
Author: Jim Nelson <jim yorba org>
Date:   Tue Jan 27 15:38:49 2015 -0800

    Code and comment cleanup in SMTP authentication
    
    While working on bug #732429 I noticed some code and factoring nits
    in the SMTP authentication and credential code.

 src/CMakeLists.txt                               |    1 -
 src/engine/api/geary-credentials.vala            |    8 +-----
 src/engine/smtp/smtp-abstract-authenticator.vala |   20 -----------------
 src/engine/smtp/smtp-authenticator.vala          |   25 +++++++++++++++++++--
 src/engine/smtp/smtp-login-authenticator.vala    |   16 ++++++++-----
 src/engine/smtp/smtp-plain-authenticator.vala    |   14 +++++++-----
 6 files changed, 42 insertions(+), 42 deletions(-)
---
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5f0abb5..bfb58fb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -259,7 +259,6 @@ engine/rfc822/rfc822-message.vala
 engine/rfc822/rfc822-message-data.vala
 engine/rfc822/rfc822-utils.vala
 
-engine/smtp/smtp-abstract-authenticator.vala
 engine/smtp/smtp-authenticator.vala
 engine/smtp/smtp-capabilities.vala
 engine/smtp/smtp-client-connection.vala
diff --git a/src/engine/api/geary-credentials.vala b/src/engine/api/geary-credentials.vala
index 5650364..1db4a60 100644
--- a/src/engine/api/geary-credentials.vala
+++ b/src/engine/api/geary-credentials.vala
@@ -17,15 +17,11 @@
  * application.  This is because network resources often have to be connected (or reconnected) to
  * in the background and asking the user to reauthenticate each time is deemed inconvenient.
  */
- 
+
 public class Geary.Credentials : BaseObject, Gee.Hashable<Geary.Credentials> {
     public string? user { get; set; }
     public string? pass { get; set; }
     
-    /**
-     * user and pass may be null here, but the properties will always be a non-null zero-length
-     * string.  See is_empty().
-     */
     public Credentials(string? user, string? pass) {
         this.user = user;
         this.pass = pass;
@@ -51,7 +47,7 @@ public class Geary.Credentials : BaseObject, Gee.Hashable<Geary.Credentials> {
     }
     
     public uint hash() {
-        return to_string().hash();
+        return "%s%s".printf(user ?? "", pass ?? "").hash();
     }
 }
 
diff --git a/src/engine/smtp/smtp-authenticator.vala b/src/engine/smtp/smtp-authenticator.vala
index 4496425..9557b9c 100644
--- a/src/engine/smtp/smtp-authenticator.vala
+++ b/src/engine/smtp/smtp-authenticator.vala
@@ -4,8 +4,27 @@
  * (version 2.1 or later).  See the COPYING file in this distribution.
  */
 
-public interface Geary.Smtp.Authenticator : Object {
-    public abstract string get_name();
+/**
+ * An abstract class describing a process for goind through an SASL authentication transaction.
+ *
+ * Authenticators expect to use complete { link Credentials}, i.e. user and pass must not be null.
+ */
+
+public abstract class Geary.Smtp.Authenticator : BaseObject {
+    /**
+     * The user-visible name for this { link Authenticator}.
+     */
+    public string name { get; private set; }
+    
+    public Credentials credentials { get; private set; }
+    
+    public Authenticator(string name, Credentials credentials) {
+        this.name = name;
+        this.credentials = credentials;
+        
+        if (!credentials.is_complete())
+            message("Incomplete credentials supplied to SMTP authenticator %s", name);
+    }
     
     /**
      * Returns a Request that is used to initiate the challenge-response.
@@ -28,7 +47,7 @@ public interface Geary.Smtp.Authenticator : Object {
     public abstract Memory.Buffer? challenge(int step, Response response) throws SmtpError;
     
     public virtual string to_string() {
-        return get_name();
+        return name;
     }
 }
 
diff --git a/src/engine/smtp/smtp-login-authenticator.vala b/src/engine/smtp/smtp-login-authenticator.vala
index 9401fc2..e47b4fe 100644
--- a/src/engine/smtp/smtp-login-authenticator.vala
+++ b/src/engine/smtp/smtp-login-authenticator.vala
@@ -4,13 +4,17 @@
  * (version 2.1 or later).  See the COPYING file in this distribution.
  */
 
-public class Geary.Smtp.LoginAuthenticator : Geary.Smtp.AbstractAuthenticator {
+/**
+ * SASL's LOGIN authentication schema impemented as an { link Authenticator}.
+ *
+ * LOGIN is obsolete but still widely in use and provided for backward compatibility.
+ *
+ * See [[https://tools.ietf.org/html/draft-murchison-sasl-login-00]]
+ */
+
+public class Geary.Smtp.LoginAuthenticator : Geary.Smtp.Authenticator {
     public LoginAuthenticator(Credentials credentials) {
-        base (credentials);
-    }
-    
-    public override string get_name() {
-        return "LOGIN";
+        base ("LOGIN", credentials);
     }
     
     public override Request initiate() {
diff --git a/src/engine/smtp/smtp-plain-authenticator.vala b/src/engine/smtp/smtp-plain-authenticator.vala
index 105d770..1e2e529 100644
--- a/src/engine/smtp/smtp-plain-authenticator.vala
+++ b/src/engine/smtp/smtp-plain-authenticator.vala
@@ -4,15 +4,17 @@
  * (version 2.1 or later).  See the COPYING file in this distribution.
  */
 
-public class Geary.Smtp.PlainAuthenticator : Geary.Smtp.AbstractAuthenticator {
+/**
+ * SASL's PLAIN authentication schema impemented as an { link Authenticator}.
+ *
+ * See [[http://tools.ietf.org/html/rfc4616]]
+ */
+
+public class Geary.Smtp.PlainAuthenticator : Geary.Smtp.Authenticator {
     private static uint8[] nul = { '\0' };
     
     public PlainAuthenticator(Credentials credentials) {
-        base (credentials);
-    }
-    
-    public override string get_name() {
-        return "PLAIN";
+        base ("PLAIN", credentials);
     }
     
     public override Request initiate() {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]