diff --git a/lib/net/imap/sasl/cram_md5_authenticator.rb b/lib/net/imap/sasl/cram_md5_authenticator.rb index 42935d3a..6a6242eb 100644 --- a/lib/net/imap/sasl/cram_md5_authenticator.rb +++ b/lib/net/imap/sasl/cram_md5_authenticator.rb @@ -21,13 +21,18 @@ def initialize(user, password, warn_deprecation: true, **_ignored) require "digest/md5" @user = user @password = password + @done = false end def process(challenge) digest = hmac_md5(challenge, @password) return @user + " " + digest + ensure + @done = true end + def done?; @done end + private def hmac_md5(text, key) diff --git a/lib/net/imap/sasl/login_authenticator.rb b/lib/net/imap/sasl/login_authenticator.rb index 11d508df..f13cac6a 100644 --- a/lib/net/imap/sasl/login_authenticator.rb +++ b/lib/net/imap/sasl/login_authenticator.rb @@ -20,7 +20,8 @@ class Net::IMAP::SASL::LoginAuthenticator STATE_USER = :USER STATE_PASSWORD = :PASSWORD - private_constant :STATE_USER, :STATE_PASSWORD + STATE_DONE = :DONE + private_constant :STATE_USER, :STATE_PASSWORD, :STATE_DONE def initialize(user, password, warn_deprecation: true, **_ignored) if warn_deprecation @@ -37,7 +38,12 @@ def process(data) @state = STATE_PASSWORD return @user when STATE_PASSWORD + @state = STATE_DONE return @password + when STATE_DONE + raise ResponseParseError, data end end + + def done?; @state == STATE_DONE end end