Class: ROM::Auth::Digest

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/auth/digest.rb

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Digest

Returns a new instance of Digest.

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

#lengthObject



10
11
12
# File 'lib/rom/auth/digest.rb', line 10

def length
  @data.length
end

#to_sObject



28
29
30
# File 'lib/rom/auth/digest.rb', line 28

def to_s
  @data
end