Class: ROM::Auth::Digest
- Inherits:
-
Object
- Object
- ROM::Auth::Digest
- Defined in:
- lib/rom/auth/digest.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(data) ⇒ Digest
constructor
A new instance of Digest.
- #length ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data) ⇒ Digest
Returns a new instance of Digest.
5 6 7 8 |
# File 'lib/rom/auth/digest.rb', line 5 def initialize(data) raise(ArgumentError, "String required got #{data.class}") if !data.is_a?(String) @data = data end |
Instance Method Details
#==(other) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rom/auth/digest.rb', line 14 def ==(other) raise ArgumentError if !other.is_a?(Digest) raise ArgumentError if length != other.length # SECURITY timing attack # TODO because of short-circuiting this is actually not 100% constant time. fix this. result = @data.chars.zip(other.to_s.chars).inject(true) do |res, (char, other_char)| eq = (char == other_char) res && eq end result end |
#length ⇒ Object
10 11 12 |
# File 'lib/rom/auth/digest.rb', line 10 def length @data.length end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/rom/auth/digest.rb', line 28 def to_s @data end |