@@ -21,6 +21,10 @@ module Net::IMAP::SASL
2121 # ScramSHA1Authenticator for examples.
2222 class Authenticators
2323
24+ # Normalize the mechanism name as an uppercase string, with underscores
25+ # converted to dashes.
26+ def self . normalize_name ( mechanism ) -mechanism . to_s . upcase . tr ( ?_, ?-) end
27+
2428 # Create a new Authenticators registry.
2529 #
2630 # This class is usually not instantiated directly. Use SASL.authenticators
@@ -65,7 +69,7 @@ def names; @authenticators.keys end
6569 # lazily loaded from <tt>Net::IMAP::SASL::#{name}Authenticator</tt> (case is
6670 # preserved and non-alphanumeric characters are removed..
6771 def add_authenticator ( name , authenticator = nil )
68- key = - name . to_s . upcase . tr ( ?_ , ?- )
72+ key = Authenticators . normalize_name ( name )
6973 authenticator ||= begin
7074 class_name = "#{ name . gsub ( /[^a-zA-Z0-9]/ , "" ) } Authenticator" . to_sym
7175 auth_class = nil
@@ -79,12 +83,12 @@ def add_authenticator(name, authenticator = nil)
7983
8084 # Removes the authenticator registered for +name+
8185 def remove_authenticator ( name )
82- key = - name . to_s . upcase . tr ( ?_ , ?- )
86+ key = Authenticators . normalize_name ( name )
8387 @authenticators . delete ( key )
8488 end
8589
8690 def mechanism? ( name )
87- key = - name . to_s . upcase . tr ( ?_ , ?- )
91+ key = Authenticators . normalize_name ( name )
8892 @authenticators . key? ( key )
8993 end
9094
@@ -105,7 +109,7 @@ def mechanism?(name)
105109 # only. Protocol client users should see refer to their client's
106110 # documentation, e.g. Net::IMAP#authenticate.
107111 def authenticator ( mechanism , ...)
108- key = - mechanism . to_s . upcase . tr ( ?_ , ?- )
112+ key = Authenticators . normalize_name ( mechanism )
109113 auth = @authenticators . fetch ( key ) do
110114 raise ArgumentError , 'unknown auth type - "%s"' % key
111115 end
0 commit comments