Skip to content

Commit a5a5ba9

Browse files
committed
♻️ Use SASL::AuthenticationExchange internally
1 parent 8c25109 commit a5a5ba9

File tree

2 files changed

+5
-24
lines changed

2 files changed

+5
-24
lines changed

lib/net/imap.rb

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,29 +1333,9 @@ def starttls(**options)
13331333
# Previously cached #capabilities will be cleared when this method
13341334
# completes. If the TaggedResponse to #authenticate includes updated
13351335
# capabilities, they will be cached.
1336-
def authenticate(mechanism, *creds,
1337-
sasl_ir: config.sasl_ir,
1338-
**props, &callback)
1339-
mechanism = SASL::Authenticators.normalize_name(mechanism)
1340-
authenticator = SASL.authenticator(mechanism, *creds, **props, &callback)
1341-
cmdargs = ["AUTHENTICATE", mechanism]
1342-
if sasl_ir && capable?("SASL-IR") && auth_capable?(mechanism) &&
1343-
authenticator.respond_to?(:initial_response?) &&
1344-
authenticator.initial_response?
1345-
response = authenticator.process(nil)
1346-
cmdargs << (response.empty? ? "=" : [response].pack("m0"))
1347-
end
1348-
result = send_command_with_continuations(*cmdargs) {|data|
1349-
challenge = data.unpack1("m")
1350-
response = authenticator.process challenge
1351-
[response].pack("m0")
1352-
}
1353-
if authenticator.respond_to?(:done?) && !authenticator.done?
1354-
logout!
1355-
raise SASL::AuthenticationIncomplete, result
1356-
end
1357-
@capabilities = capabilities_from_resp_code result
1358-
result
1336+
def authenticate(*args, sasl_ir: config.sasl_ir, **props, &callback)
1337+
sasl_adapter.authenticate(*args, sasl_ir: sasl_ir, **props, &callback)
1338+
.tap { @capabilities = capabilities_from_resp_code _1 }
13591339
end
13601340

13611341
# Sends a {LOGIN command [IMAP4rev1 §6.2.3]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.2.3]

lib/net/imap/sasl/authentication_exchange.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module Net
44
class IMAP
55
module SASL
66

7-
# This API is *experimental*, and may change.
7+
# AuthenticationExchange is used internally by Net::IMAP#authenticate.
8+
# But the API is still *experimental*, and may change.
89
#
910
# TODO: catch exceptions in #process and send #cancel_response.
1011
# TODO: raise an error if the command succeeds after being canceled.

0 commit comments

Comments
 (0)