lib/uri/ni.rb in uri-ni-0.1.2 vs lib/uri/ni.rb in uri-ni-0.1.4
- old
+ new
@@ -184,11 +184,11 @@
# @param [#to_s, #to_sym] The algorithm
# @return [Digest:Instance] The digest context
# @raise [ArgumentError] if the algorithm is unrecognized
def self.context algorithm
raise ArgumentError, "Cannot coerce #{algorithm} to a symbol" unless
- algorithm.respond_to(:to_s) # cheat: symbols respond to to_s
+ algorithm.respond_to? :to_s # cheat: symbols respond to to_s
algorithm = algorithm.to_s.to_sym unless algorithm.is_a? Symbol
raise ArgumentError, "Unsupported digest algorithm #{algorithm}" unless
ctx = DIGESTS[algorithm]
ctx.new
end
@@ -473,6 +473,18 @@
#
def to_http authority: nil
to_www https: false, authority: authority
end
+ # Returns the set of supported algorithms.
+ # @return [Array] the algorithms
+ def self.algorithms
+ DIGESTS.keys
+ end
+
+ # Returns true if the algorithm is supported.
+ # @param algorithm [Symbol,String] the algorithm identifier to test
+ # @return [true, false] whether it is supported
+ def self.valid_algo? algorithm
+ DIGESTS.has_key? algorithm.to_s.downcase.to_sym
+ end
end