Class Net::SSH::Transport::HMAC::Abstract

  1. lib/net/ssh/transport/hmac/abstract.rb
Parent: Object

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)
[show source]
    # File lib/net/ssh/transport/hmac/abstract.rb, line 34
34:       def digest_class(*v)
35:         @digest_class = nil if !defined?(@digest_class)
36:         if v.empty?
37:           @digest_class = superclass.digest_class if @digest_class.nil? && superclass.respond_to?(:digest_class)
38:           return @digest_class
39:         elsif v.length == 1
40:           @digest_class = v.first
41:         else
42:           raise ArgumentError, "wrong number of arguments (#{v.length} for 1)"
43:         end
44:       end
key_length (*v)
[show source]
    # File lib/net/ssh/transport/hmac/abstract.rb, line 10
10:       def key_length(*v)
11:         @key_length = nil if !defined?(@key_length)
12:         if v.empty?
13:           @key_length = superclass.key_length if @key_length.nil? && superclass.respond_to?(:key_length)
14:           return @key_length
15:         elsif v.length == 1
16:           @key_length = v.first
17:         else
18:           raise ArgumentError, "wrong number of arguments (#{v.length} for 1)"
19:         end
20:       end
mac_length (*v)
[show source]
    # File lib/net/ssh/transport/hmac/abstract.rb, line 22
22:       def mac_length(*v)
23:         @mac_length = nil if !defined?(@mac_length)
24:         if v.empty?
25:           @mac_length = superclass.mac_length if @mac_length.nil? && superclass.respond_to?(:mac_length)
26:           return @mac_length
27:         elsif v.length == 1
28:           @mac_length = v.first
29:         else
30:           raise ArgumentError, "wrong number of arguments (#{v.length} for 1)"
31:         end
32:       end
new (key=nil)
[show source]
    # File lib/net/ssh/transport/hmac/abstract.rb, line 62
62:     def initialize(key=nil)
63:       self.key = key
64:     end

Public instance methods

digest (data)

Compute the HMAC digest for the given data string.

[show source]
    # File lib/net/ssh/transport/hmac/abstract.rb, line 73
73:     def digest(data)
74:       OpenSSL::HMAC.digest(digest_class.new, key, data)[0,mac_length]
75:     end
digest_class ()
[show source]
    # File lib/net/ssh/transport/hmac/abstract.rb, line 55
55:     def digest_class
56:       self.class.digest_class
57:     end
key= (value)

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

[show source]
    # File lib/net/ssh/transport/hmac/abstract.rb, line 68
68:     def key=(value)
69:       @key = value ? value.to_s[0,key_length] : nil
70:     end
key_length ()
[show source]
    # File lib/net/ssh/transport/hmac/abstract.rb, line 47
47:     def key_length
48:       self.class.key_length
49:     end
mac_length ()
[show source]
    # File lib/net/ssh/transport/hmac/abstract.rb, line 51
51:     def mac_length
52:       self.class.mac_length
53:     end