Skip to content

Commit 8f27b05

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 634854b commit 8f27b05

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/net/imap/sasl/cram_md5_authenticator.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ def initialize(user, password, warn_deprecation: true, **_ignored)
2121
require "digest/md5"
2222
@user = user
2323
@password = password
24+
@done = false
2425
end
2526

2627
def process(challenge)
2728
digest = hmac_md5(challenge, @password)
2829
return @user + " " + digest
30+
ensure
31+
@done = true
2932
end
3033

34+
def done?; @done end
35+
3136
private
3237

3338
def hmac_md5(text, key)

lib/net/imap/sasl/login_authenticator.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
class Net::IMAP::SASL::LoginAuthenticator
2121
STATE_USER = :USER
2222
STATE_PASSWORD = :PASSWORD
23-
private_constant :STATE_USER, :STATE_PASSWORD
23+
STATE_DONE = :DONE
24+
private_constant :STATE_USER, :STATE_PASSWORD, :STATE_DONE
2425

2526
def initialize(user, password, warn_deprecation: true, **_ignored)
2627
if warn_deprecation
@@ -37,7 +38,12 @@ def process(data)
3738
@state = STATE_PASSWORD
3839
return @user
3940
when STATE_PASSWORD
41+
@state = STATE_DONE
4042
return @password
43+
when STATE_DONE
44+
raise ResponseParseError, data
4145
end
4246
end
47+
48+
def done?; @state == STATE_DONE end
4349
end

0 commit comments

Comments
 (0)