Extended maintenance of Ruby versions 1.8.7 and 1.9.2 ended on July 31, 2014. Read more

In Files

  • digest/lib/digest/hmac.rb

Class/Module Index [+]

Quicksearch

Digest::HMAC

Public Class Methods

new(key, digester) click to toggle source
 
               # File digest/lib/digest/hmac.rb, line 50
def initialize(key, digester)
  @md = digester.new

  block_len = @md.block_length

  if key.bytesize > block_len
    key = @md.digest(key)
  end

  ipad = Array.new(block_len, 0x36)
  opad = Array.new(block_len, 0x5c)

  key.bytes.each_with_index { |c, i|
    ipad[i] ^= c
    opad[i] ^= c
  }

  @key = key.freeze
  @ipad = ipad.pack('C*').freeze
  @opad = opad.pack('C*').freeze
  @md.update(@ipad)
end
            

Public Instance Methods

<<(text) click to toggle source
Alias for: update
block_length() click to toggle source
 
               # File digest/lib/digest/hmac.rb, line 101
def block_length
  @md.block_length
end
            
digest_length() click to toggle source
 
               # File digest/lib/digest/hmac.rb, line 97
def digest_length
  @md.digest_length
end
            
initialize_copy(other) click to toggle source
 
               # File digest/lib/digest/hmac.rb, line 73
def initialize_copy(other)
  @md = other.instance_eval { @md.clone }
end
            
inspect() click to toggle source
 
               # File digest/lib/digest/hmac.rb, line 105
def inspect
  sprintf('#<%s: key=%s, digest=%s>', self.class.name, @key.inspect, @md.inspect.sub(/^\#<(.*)>$/) { $1 });
end
            
reset() click to toggle source
 
               # File digest/lib/digest/hmac.rb, line 83
def reset
  @md.reset
  @md.update(@ipad)
  self
end
            
update(text) click to toggle source
 
               # File digest/lib/digest/hmac.rb, line 77
def update(text)
  @md.update(text)
  self
end
            
Also aliased as: <<

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus