class HMAC::Base

Public Instance Methods

<<(text) click to toggle source
Alias for: update
digest() click to toggle source
# File lib/hmac.rb, line 82
def digest
  check_status
  @md.digest
end
hexdigest() click to toggle source
# File lib/hmac.rb, line 87
def hexdigest
  check_status
  @md.hexdigest
end
Also aliased as: to_s
reset_key() click to toggle source
# File lib/hmac.rb, line 59
def reset_key
  @key_xor_ipad.gsub!(%r./, '?')
  @key_xor_opad.gsub!(%r./, '?')
  @key_xor_ipad[0..-1] = ''
  @key_xor_opad[0..-1] = ''
  @initialized = false
end
set_key(key) click to toggle source
# File lib/hmac.rb, line 42
def set_key(key)
  # If key is longer than the block size, apply hash function
  # to key and use the result as a real key.
  key = @algorithm.digest(key) if key.size > @block_size
  akey = key.unpack("C*")
  key_xor_ipad = ("\x36" * @block_size).unpack("C*")
  key_xor_opad = ("\x5C" * @block_size).unpack("C*")
  for i in 0 .. akey.size - 1
    key_xor_ipad[i] ^= akey[i]
    key_xor_opad[i] ^= akey[i]
  end
  @key_xor_ipad = key_xor_ipad.pack("C*")
  @key_xor_opad = key_xor_opad.pack("C*")
  @md = @algorithm.new
  @initialized = true
end
to_s() click to toggle source
Alias for: hexdigest
update(text) click to toggle source
# File lib/hmac.rb, line 67
def update(text)
  check_status
  # perform inner H
  md = @algorithm.new
  md.update(@key_xor_ipad)
  md.update(text)
  str = md.digest
  # perform outer H
  md = @algorithm.new
  md.update(@key_xor_opad)
  md.update(str)
  @md = md
end
Also aliased as: <<