Skip to content

Commit

Permalink
💥 Add SASL::Authenticators defaults, by default
Browse files Browse the repository at this point in the history
Reversed the `use_defaults` default, and added another option for
`use_deprecated`.
  • Loading branch information
nevans committed Sep 29, 2023
1 parent 9c8fbdb commit 74e4687
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
4 changes: 1 addition & 3 deletions lib/net/imap/sasl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ module SASL
autoload :LoginAuthenticator, "#{sasl_dir}/login_authenticator"

# Returns the default global SASL::Authenticators instance.
def self.authenticators
@authenticators ||= Authenticators.new(use_defaults: true)
end
def self.authenticators; @authenticators ||= Authenticators.new end

# Delegates to ::authenticators. See Authenticators#authenticator.
def self.authenticator(...) authenticators.authenticator(...) end
Expand Down
33 changes: 16 additions & 17 deletions lib/net/imap/sasl/authenticators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,23 @@ class Authenticators
# This class is usually not instantiated directly. Use SASL.authenticators
# to reuse the default global registry.
#
# By default, the registry will be empty--without any registrations. When
# +add_defaults+ is +true+, authenticators for all standard mechanisms will
# be registered.
#
def initialize(use_defaults: false)
# When +use_defaults+ is +false+, the registry will start empty. When
# +use_deprecated+ is +false+, deprecated authenticators will not be
# included with the defaults.
def initialize(use_defaults: true, use_deprecated: true)
@authenticators = {}
if use_defaults
add_authenticator "Anonymous"
add_authenticator "External"
add_authenticator "OAuthBearer"
add_authenticator "Plain"
add_authenticator "Scram-SHA-1"
add_authenticator "Scram-SHA-256"
add_authenticator "XOAuth2"
add_authenticator "Login" # deprecated
add_authenticator "Cram-MD5" # deprecated
add_authenticator "Digest-MD5" # deprecated
end
return unless use_defaults
add_authenticator "Anonymous"
add_authenticator "External"
add_authenticator "OAuthBearer"
add_authenticator "Plain"
add_authenticator "Scram-SHA-1"
add_authenticator "Scram-SHA-256"
add_authenticator "XOAuth2"
return unless use_deprecated
add_authenticator "Login" # deprecated
add_authenticator "Cram-MD5" # deprecated
add_authenticator "Digest-MD5" # deprecated
end

# Returns the names of all registered SASL mechanisms.
Expand Down

0 comments on commit 74e4687

Please sign in to comment.