class Net::SSH::Transport::HMAC::Abstract

The base class of all OpenSSL-based HMAC algorithm wrappers.

Attributes

key[R]

The key in use for this instance.

Public Class Methods

digest_class(*v) click to toggle source
# File lib/net/ssh/transport/hmac/abstract.rb, line 48
def digest_class(*v)
  @digest_class = nil if !defined?(@digest_class)
  if v.empty?
    @digest_class = superclass.digest_class if @digest_class.nil? && superclass.respond_to?(:digest_class)
    return @digest_class
  elsif v.length == 1
    @digest_class = v.first
  else
    raise ArgumentError, "wrong number of arguments (#{v.length} for 1)"
  end
end
etm(*v) click to toggle source
# File lib/net/ssh/transport/hmac/abstract.rb, line 12
def etm(*v)
  @etm = false if !defined?(@etm)
  if v.empty?
    @etm = superclass.etm if @etm.nil? && superclass.respond_to?(:etm)
    return @etm
  elsif v.length == 1
    @etm = v.first
  else
    raise ArgumentError, "wrong number of arguments (#{v.length} for 1)"
  end
end
key_length(*v) click to toggle source
# File lib/net/ssh/transport/hmac/abstract.rb, line 24
def key_length(*v)
  @key_length = nil if !defined?(@key_length)
  if v.empty?
    @key_length = superclass.key_length if @key_length.nil? && superclass.respond_to?(:key_length)
    return @key_length
  elsif v.length == 1
    @key_length = v.first
  else
    raise ArgumentError, "wrong number of arguments (#{v.length} for 1)"
  end
end
mac_length(*v) click to toggle source
# File lib/net/ssh/transport/hmac/abstract.rb, line 36
def mac_length(*v)
  @mac_length = nil if !defined?(@mac_length)
  if v.empty?
    @mac_length = superclass.mac_length if @mac_length.nil? && superclass.respond_to?(:mac_length)
    return @mac_length
  elsif v.length == 1
    @mac_length = v.first
  else
    raise ArgumentError, "wrong number of arguments (#{v.length} for 1)"
  end
end
new(key=nil) click to toggle source
# File lib/net/ssh/transport/hmac/abstract.rb, line 80
def initialize(key=nil)
  self.key = key
end

Public Instance Methods

digest(data) click to toggle source

Compute the HMAC digest for the given data string.

# File lib/net/ssh/transport/hmac/abstract.rb, line 91
def digest(data)
  OpenSSL::HMAC.digest(digest_class.new, key, data)[0,mac_length]
end
digest_class() click to toggle source
# File lib/net/ssh/transport/hmac/abstract.rb, line 73
def digest_class
  self.class.digest_class
end
etm() click to toggle source
# File lib/net/ssh/transport/hmac/abstract.rb, line 61
def etm
  self.class.etm
end
key=(value) click to toggle source

Sets the key to the given value, truncating it so that it is the correct length.

# File lib/net/ssh/transport/hmac/abstract.rb, line 86
def key=(value)
  @key = value ? value.to_s[0,key_length] : nil
end
key_length() click to toggle source
# File lib/net/ssh/transport/hmac/abstract.rb, line 65
def key_length
  self.class.key_length
end
mac_length() click to toggle source
# File lib/net/ssh/transport/hmac/abstract.rb, line 69
def mac_length
  self.class.mac_length
end