Skip to content

Commit dd0b91e

Browse files
committed
♻️ Use SASL::AuthenticationExchange internally
1 parent 3b3f8ae commit dd0b91e

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
@@ -1331,29 +1331,9 @@ def starttls(**options)
13311331
# Previously cached #capabilities will be cleared when this method
13321332
# completes. If the TaggedResponse to #authenticate includes updated
13331333
# capabilities, they will be cached.
1334-
def authenticate(mechanism, *creds,
1335-
sasl_ir: config.sasl_ir,
1336-
**props, &callback)
1337-
mechanism = SASL::Authenticators.normalize_name(mechanism)
1338-
authenticator = SASL.authenticator(mechanism, *creds, **props, &callback)
1339-
cmdargs = ["AUTHENTICATE", mechanism]
1340-
if sasl_ir && capable?("SASL-IR") && auth_capable?(mechanism) &&
1341-
authenticator.respond_to?(:initial_response?) &&
1342-
authenticator.initial_response?
1343-
response = authenticator.process(nil)
1344-
cmdargs << (response.empty? ? "=" : [response].pack("m0"))
1345-
end
1346-
result = send_command_with_continuations(*cmdargs) {|data|
1347-
challenge = data.unpack1("m")
1348-
response = authenticator.process challenge
1349-
[response].pack("m0")
1350-
}
1351-
if authenticator.respond_to?(:done?) && !authenticator.done?
1352-
logout!
1353-
raise SASL::AuthenticationIncomplete, result
1354-
end
1355-
@capabilities = capabilities_from_resp_code result
1356-
result
1334+
def authenticate(*args, sasl_ir: config.sasl_ir, **props, &callback)
1335+
sasl_adapter.authenticate(*args, sasl_ir: sasl_ir, **props, &callback)
1336+
.tap { @capabilities = capabilities_from_resp_code _1 }
13571337
end
13581338

13591339
# 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)