Class: HMAC::Base

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

Instance Method Summary collapse

Instance Method Details

#set_key(key) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/tinatra.rb', line 33

def set_key(key)
  key = @algorithm.digest(key) if key.size > @block_size
  key_xor_ipad = Array.new(@block_size, 0x36)
  key_xor_opad = Array.new(@block_size, 0x5c)
  key.bytes.each_with_index do |value, index|
    key_xor_ipad[index] ^= value
    key_xor_opad[index] ^= value
  end
  @key_xor_ipad = key_xor_ipad.pack('c*')
  @key_xor_opad = key_xor_opad.pack('c*')
  @md = @algorithm.new
  @initialized = true
end