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 7, 2023
1 parent 6a8ca1e commit efbc1d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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 @@ -17,8 +17,12 @@ class Net::IMAP::SASL::CramMD5Authenticator
def process(challenge)
digest = hmac_md5(challenge, @password)
return @user + " " + digest
ensure
@done = true
end

def done?; @done end

private

def initialize(user, password, warn_deprecation: true, **_ignored)
Expand All @@ -28,6 +32,7 @@ def initialize(user, password, warn_deprecation: true, **_ignored)
require "digest/md5"
@user = user
@password = password
@done = false
end

def hmac_md5(text, key)
Expand Down
10 changes: 7 additions & 3 deletions lib/net/imap/sasl/login_authenticator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ def process(data)
@state = STATE_PASSWORD
return @user
when STATE_PASSWORD
@state = STATE_DONE
return @password
when STATE_DONE
raise ResponseParseError, data
end
end

private

STATE_USER = :USER
STATE_USER = :USER
STATE_PASSWORD = :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 @@ -42,4 +45,5 @@ def initialize(user, password, warn_deprecation: true, **_ignored)
@state = STATE_USER
end

def done?; @state == STATE_DONE end
end

0 comments on commit efbc1d3

Please sign in to comment.