Class: SecureURI::Hasher

Inherits:
Object
  • Object
show all
Defined in:
lib/secure_uri/hasher.rb

Overview

Placeholder class to make sure a hashing class is set before the class is used.

Required methods:

  • self.hash

The salt mechanism is there as most hashing implementations will need a shared secret.

Subclass this class to automagically set the hasher to your class.

Direct Known Subclasses

SHA256Hasher

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.saltObject

Lets us read the salt; defaulting to an empty string



17
18
19
# File 'lib/secure_uri/hasher.rb', line 17

def salt
  @salt || ""
end

Class Method Details

.compare(hash, str) ⇒ Object

Takes a hash and a string. Hashes the string using self#hash and compares to the hash passed in.

Returns True or False



32
33
34
# File 'lib/secure_uri/hasher.rb', line 32

def compare hash, str
  hash == self.hash(str)
end

.hash(str) ⇒ Object

Takes a string and hashes it

Returns String



24
25
26
# File 'lib/secure_uri/hasher.rb', line 24

def hash str
  raise "hash method needs to be overridden"
end

.inherited(klass) ⇒ Object

Convenience method so subclassing Hasher automatically sets the new (sub)class as the Hasher class in SecureURI



38
39
40
# File 'lib/secure_uri/hasher.rb', line 38

def inherited klass
  SecureURI.hasher = klass
end