@@ -21,6 +21,10 @@ module Net::IMAP::SASL
21
21
# ScramSHA1Authenticator for examples.
22
22
class Authenticators
23
23
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
+
24
28
# Create a new Authenticators registry.
25
29
#
26
30
# This class is usually not instantiated directly. Use SASL.authenticators
@@ -65,7 +69,7 @@ def names; @authenticators.keys end
65
69
# lazily loaded from <tt>Net::IMAP::SASL::#{name}Authenticator</tt> (case is
66
70
# preserved and non-alphanumeric characters are removed..
67
71
def add_authenticator ( name , authenticator = nil )
68
- key = - name . to_s . upcase . tr ( ?_ , ?- )
72
+ key = Authenticators . normalize_name ( name )
69
73
authenticator ||= begin
70
74
class_name = "#{ name . gsub ( /[^a-zA-Z0-9]/ , "" ) } Authenticator" . to_sym
71
75
auth_class = nil
@@ -79,12 +83,12 @@ def add_authenticator(name, authenticator = nil)
79
83
80
84
# Removes the authenticator registered for +name+
81
85
def remove_authenticator ( name )
82
- key = - name . to_s . upcase . tr ( ?_ , ?- )
86
+ key = Authenticators . normalize_name ( name )
83
87
@authenticators . delete ( key )
84
88
end
85
89
86
90
def mechanism? ( name )
87
- key = - name . to_s . upcase . tr ( ?_ , ?- )
91
+ key = Authenticators . normalize_name ( name )
88
92
@authenticators . key? ( key )
89
93
end
90
94
@@ -105,7 +109,7 @@ def mechanism?(name)
105
109
# only. Protocol client users should see refer to their client's
106
110
# documentation, e.g. Net::IMAP#authenticate.
107
111
def authenticator ( mechanism , ...)
108
- key = - mechanism . to_s . upcase . tr ( ?_ , ?- )
112
+ key = Authenticators . normalize_name ( mechanism )
109
113
auth = @authenticators . fetch ( key ) do
110
114
raise ArgumentError , 'unknown auth type - "%s"' % key
111
115
end
0 commit comments