@@ -77,6 +77,31 @@ class IMAP
7777 # <em>Using a deprecated mechanism will print a warning.</em>
7878 #
7979 module SASL
80+ # Exception class for any client error detected during the authentication
81+ # exchange.
82+ #
83+ # When the _server_ reports an authentication failure, it will respond
84+ # with a protocol specific error instead, e.g: +BAD+ or +NO+ in IMAP.
85+ #
86+ # When the client encounters any error, it *must* consider the
87+ # authentication exchange to be unsuccessful and it might need to drop the
88+ # connection. For example, if the server reports that the authentication
89+ # exchange was successful or the protocol does not allow additional
90+ # authentication attempts.
91+ Error = Class . new ( StandardError )
92+
93+ # Indicates an authentication exchange that will be or has been canceled
94+ # by the client, not due to any error or failure during processing.
95+ AuthenticationCanceled = Class . new ( Error )
96+
97+ # Indicates an error when processing a server challenge, e.g: an invalid
98+ # or unparsable challenge. An underlying exception may be available as
99+ # the exception's #cause.
100+ AuthenticationError = Class . new ( Error )
101+
102+ # Indicates that authentication cannot proceed because one of the server's
103+ # messages has not passed integrity checks.
104+ AuthenticationFailed = Class . new ( Error )
80105
81106 # autoloading to avoid loading all of the regexps when they aren't used.
82107 sasl_stringprep_rb = File . expand_path ( "sasl/stringprep" , __dir__ )
@@ -118,13 +143,24 @@ def saslprep(string, **opts)
118143 Net ::IMAP ::StringPrep ::SASLprep . saslprep ( string , **opts )
119144 end
120145
121- # Returns whether the authenticator is client-first and supports sending
122- # an "initial response".
146+ # Returns whether + authenticator+ is client-first and supports sending an
147+ # "initial response".
123148 def initial_response? ( authenticator )
124149 authenticator . respond_to? ( :initial_response? ) &&
125150 authenticator . initial_response?
126151 end
127152
153+ # Returns whether +authenticator+ considers the authentication exchange to
154+ # be complete.
155+ #
156+ # The authentication should not succeed if this returns false, but
157+ # returning true does *not* indicate success. Authentication succeeds
158+ # when this method returns true and the server responds with a
159+ # protocol-specific success.
160+ def done? ( authenticator )
161+ !authenticator . respond_to? ( :done? ) || authenticator . done?
162+ end
163+
128164 end
129165 end
130166end
0 commit comments