Class: Digest::HMAC
Instance Method Summary (collapse)
- - (Object) block_length
- - (Object) digest_length
-
- (HMAC) initialize(key, digester)
constructor
A new instance of HMAC.
- - (Object) initialize_copy(other)
- - (Object) inspect
- - (Object) reset
- - (Object) update(text) (also: #<<)
Constructor Details
- (HMAC) initialize(key, digester)
A new instance of HMAC
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/digest/hmac.rb', line 44 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).fill(0x36) opad = Array.new(block_len).fill(0x5c) key.bytes.each_with_index { |c, i| ipad[i] ^= c opad[i] ^= c } @key = key.freeze @ipad = ipad.inject('') { |s, c| s << c.chr }.freeze @opad = opad.inject('') { |s, c| s << c.chr }.freeze @md.update(@ipad) end |
Instance Method Details
- (Object) block_length
95 96 97 |
# File 'lib/digest/hmac.rb', line 95 def block_length @md.block_length end |
- (Object) digest_length
91 92 93 |
# File 'lib/digest/hmac.rb', line 91 def digest_length @md.digest_length end |
- (Object) initialize_copy(other)
67 68 69 |
# File 'lib/digest/hmac.rb', line 67 def initialize_copy(other) @md = other.instance_eval { @md.clone } end |
- (Object) inspect
99 100 101 |
# File 'lib/digest/hmac.rb', line 99 def inspect sprintf('#<%s: key=%s, digest=%s>', self.class.name, @key.inspect, @md.inspect.sub(/^\#<(.*)>$/) { $1 }); end |
- (Object) reset
77 78 79 80 81 |
# File 'lib/digest/hmac.rb', line 77 def reset @md.reset @md.update(@ipad) self end |
- (Object) update(text) Also known as: <<
71 72 73 74 |
# File 'lib/digest/hmac.rb', line 71 def update(text) @md.update(text) self end |