Skip to content

Commit 3549dee

Browse files
committed
🔒 SASL: Add "#done?" [🚧 WIP]
The protocol client is responsible for raising an error if the command completes successfully but "done?" returns false.
1 parent 52f8e81 commit 3549dee

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/net/imap/sasl/cram_md5_authenticator.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ class Net::IMAP::SASL::CramMD5Authenticator
1717
def process(challenge)
1818
digest = hmac_md5(challenge, @password)
1919
return @user + " " + digest
20+
ensure
21+
@done = true
2022
end
2123

24+
def done?; @done end
25+
2226
private
2327

2428
def initialize(user, password, warn_deprecation: true, **_ignored)
@@ -28,6 +32,7 @@ def initialize(user, password, warn_deprecation: true, **_ignored)
2832
require "digest/md5"
2933
@user = user
3034
@password = password
35+
@done = false
3136
end
3237

3338
def hmac_md5(text, key)

lib/net/imap/sasl/login_authenticator.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@ def process(data)
2424
@state = STATE_PASSWORD
2525
return @user
2626
when STATE_PASSWORD
27+
@state = STATE_DONE
2728
return @password
29+
when STATE_DONE
30+
raise ResponseParseError, data
2831
end
2932
end
3033

31-
private
32-
33-
STATE_USER = :USER
34+
STATE_USER = :USER
3435
STATE_PASSWORD = :PASSWORD
36+
STATE_DONE = :DONE
37+
private_constant :STATE_USER, :STATE_PASSWORD, :STATE_DONE
3538

3639
def initialize(user, password, warn_deprecation: true, **_ignored)
3740
if warn_deprecation
@@ -42,4 +45,5 @@ def initialize(user, password, warn_deprecation: true, **_ignored)
4245
@state = STATE_USER
4346
end
4447

48+
def done?; @state == STATE_DONE end
4549
end

0 commit comments

Comments
 (0)