Skip to content

Commit

Permalink
🔒 SASL: Add "#done?" [🚧 WIP]
Browse files Browse the repository at this point in the history
The protocol client is responsible for raising an error if the command
completes successfully but "done?" returns false.
  • Loading branch information
nevans committed Sep 20, 2023
1 parent cfb8caf commit 5d27f9c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/net/imap/sasl/cram_md5_authenticator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion lib/net/imap/sasl/login_authenticator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 5d27f9c

Please sign in to comment.