Skip to content

Commit 623402a

Browse files
committed
📚 Update SASL documentation
1 parent 725a10e commit 623402a

File tree

4 files changed

+56
-20
lines changed

4 files changed

+56
-20
lines changed

lib/net/imap.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,9 @@ def starttls(**options)
12421242
# +SASL-IR+ capability, below). Defaults to the #config value for
12431243
# {sasl_ir}[rdoc-ref:Config#sasl_ir], which defaults to +true+.
12441244
#
1245+
# The +registry+ kwarg can be used to select the mechanism implementation
1246+
# from a custom registry. See SASL.authenticator and SASL::Authenticators.
1247+
#
12451248
# All other arguments are forwarded to the registered SASL authenticator for
12461249
# the requested mechanism. <em>The documentation for each individual
12471250
# mechanism must be consulted for its specific parameters.</em>

lib/net/imap/sasl.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ def initialize(response, message = "authentication ended prematurely")
159159
# Returns the default global SASL::Authenticators instance.
160160
def self.authenticators; @authenticators ||= Authenticators.new end
161161

162-
# Delegates to <tt>registry.new</tt> See Authenticators#new.
162+
# Creates a new SASL authenticator, using SASL::Authenticators#new.
163+
#
164+
# +registry+ defaults to SASL.authenticators. All other arguments are
165+
# forwarded to to <tt>registry.new</tt>.
163166
def self.authenticator(*args, registry: authenticators, **kwargs, &block)
164167
registry.new(*args, **kwargs, &block)
165168
end

lib/net/imap/sasl/authentication_exchange.rb

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,68 @@ module SASL
1010
# TODO: raise an error if the command succeeds after being canceled.
1111
# TODO: use with more clients, to verify the API can accommodate them.
1212
#
13-
# Create an AuthenticationExchange from a client adapter and a mechanism
14-
# authenticator:
15-
# def authenticate(mechanism, ...)
16-
# authenticator = SASL.authenticator(mechanism, ...)
17-
# SASL::AuthenticationExchange.new(
18-
# sasl_adapter, mechanism, authenticator
19-
# ).authenticate
20-
# end
21-
#
22-
# private
13+
# An AuthenticationExchange represents a single attempt to authenticate
14+
# a SASL client to a SASL server. It is created from a client adapter, a
15+
# mechanism name, and a mechanism authenticator. When #authenticate is
16+
# called, it will send the appropriate authenticate command to the server,
17+
# returning the client response on success and raising an exception on
18+
# failure.
2319
#
24-
# def sasl_adapter = MyClientAdapter.new(self, &method(:send_command))
20+
# In most cases, the client will not need to use
21+
# SASL::AuthenticationExchange directly at all. Instead, use
22+
# SASL::ClientAdapter#authenticate. If customizations are needed, the
23+
# custom client adapter is probably the best place for that code.
2524
#
26-
# Or delegate creation of the authenticator to ::build:
2725
# def authenticate(...)
28-
# SASL::AuthenticationExchange.build(sasl_adapter, ...)
29-
# .authenticate
26+
# MyClient::SASLAdapter.new(self).authenticate(...)
3027
# end
3128
#
32-
# As a convenience, ::authenticate combines ::build and #authenticate:
29+
# SASL::ClientAdapter#authenticate delegates to ::authenticate, like so:
30+
#
3331
# def authenticate(...)
32+
# sasl_adapter = MyClient::SASLAdapter.new(self)
3433
# SASL::AuthenticationExchange.authenticate(sasl_adapter, ...)
3534
# end
3635
#
37-
# Likewise, ClientAdapter#authenticate delegates to #authenticate:
38-
# def authenticate(...) = sasl_adapter.authenticate(...)
36+
# ::authenticate simply delegates to ::build and #authenticate, like so:
37+
#
38+
# def authenticate(...)
39+
# sasl_adapter = MyClient::SASLAdapter.new(self)
40+
# SASL::AuthenticationExchange
41+
# .build(sasl_adapter, ...)
42+
# .authenticate
43+
# end
44+
#
45+
# And ::build delegates to SASL.authenticator and ::new, like so:
46+
#
47+
# def authenticate(mechanism, ...)
48+
# sasl_adapter = MyClient::SASLAdapter.new(self)
49+
# authenticator = SASL.authenticator(mechanism, ...)
50+
# SASL::AuthenticationExchange
51+
# .new(sasl_adapter, mechanism, authenticator)
52+
# .authenticate
53+
# end
3954
#
4055
class AuthenticationExchange
4156
# Convenience method for <tt>build(...).authenticate</tt>
57+
#
58+
# See also: SASL::ClientAdapter#authenticate
4259
def self.authenticate(...) build(...).authenticate end
4360

44-
# Use +registry+ to override the global Authenticators registry.
61+
# Convenience method to combine the creation of a new authenticator and
62+
# a new Authentication exchange.
63+
#
64+
# +client+ must be an instance of SASL::ClientAdapter.
65+
#
66+
# +mechanism+ must be a SASL mechanism name, as a string or symbol.
67+
#
68+
# +sasl_ir+ allows or disallows sending an "initial response", depending
69+
# also on whether the server capabilities, mechanism authenticator, and
70+
# client adapter all support it. Defaults to +true+.
71+
#
72+
# +mechanism+, +args+, +kwargs+, and +block+ are all forwarded to
73+
# SASL.authenticator. Use the +registry+ kwarg to override the global
74+
# SASL::Authenticators registry.
4575
def self.build(client, mechanism, *args, sasl_ir: true, **kwargs, &block)
4676
authenticator = SASL.authenticator(mechanism, *args, **kwargs, &block)
4777
new(client, mechanism, authenticator, sasl_ir: sasl_ir)

lib/net/imap/sasl/client_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def initialize(client, &command_proc)
3636
# Delegates to AuthenticationExchange.authenticate.
3737
def authenticate(...) AuthenticationExchange.authenticate(self, ...) end
3838

39-
# Do the protocol and server both support an initial response?
39+
# Do the protocol, server, and client all support an initial response?
4040
def sasl_ir_capable?; client.sasl_ir_capable? end
4141

4242
# Does the server advertise support for the mechanism?

0 commit comments

Comments
 (0)