module CryptoHash
@INTERNAL: Please use ObjectHash.hash()
instead. Contains functions which cryptographically hash an input string, using a given algorithm. Several common algorithms are implemented, or you can provide your own Digest object.
Constants
- ALGORITHMS
Algorithms which can cryptographically hash an input.
Public Instance Methods
perform_cryptohash(input, algorithm)
click to toggle source
@INTERNAL: Please use ObjectHash.hash()
instead. Call the appropriate algorithm on the input. @param input A string to hash. @param algorithm Either a string for an algorithm to use, or a Digest to perform the hash.
# File lib/object_hash_rb/cryptohash.rb, line 57 def perform_cryptohash(input, algorithm) # Allow users to specify their own Digest object. return algorithm.hexdigest(input) if algorithm.respond_to?(:hexdigest) alg = algorithm.strip.downcase.to_sym # Throw an error if the algorithm is unknown. raise UnknownAlgorithmError, algorithm unless ALGORITHMS.key?(alg) # Return the result of the algorithm. ALGORITHMS[alg].call(input) end