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

Inherits:
Object
  • Object
show all
Defined in:
lib/net/ssh/transport/hmac/abstract.rb

Overview

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

Direct Known Subclasses

MD5, None, RIPEMD160, SHA1, SHA2_256, SHA2_256_Etm, SHA2_512, SHA2_512_Etm

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key = nil) ⇒ Abstract

Returns a new instance of Abstract.


79
80
81
# File 'lib/net/ssh/transport/hmac/abstract.rb', line 79

def initialize(key = nil)
  self.key = key
end

Instance Attribute Details

#keyObject

The key in use for this instance.


77
78
79
# File 'lib/net/ssh/transport/hmac/abstract.rb', line 77

def key
  @key
end

Class Method Details

.digest_class(*v) ⇒ Object


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/net/ssh/transport/hmac/abstract.rb', line 47

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) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/net/ssh/transport/hmac/abstract.rb', line 11

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) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/net/ssh/transport/hmac/abstract.rb', line 23

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) ⇒ Object


35
36
37
38
39
40
41
42
43
44
45
# File 'lib/net/ssh/transport/hmac/abstract.rb', line 35

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

Instance Method Details

#digest(data) ⇒ Object

Compute the HMAC digest for the given data string.


90
91
92
# File 'lib/net/ssh/transport/hmac/abstract.rb', line 90

def digest(data)
  OpenSSL::HMAC.digest(digest_class.new, key, data)[0, mac_length]
end

#digest_classObject


72
73
74
# File 'lib/net/ssh/transport/hmac/abstract.rb', line 72

def digest_class
  self.class.digest_class
end

#etmObject


60
61
62
# File 'lib/net/ssh/transport/hmac/abstract.rb', line 60

def etm
  self.class.etm
end

#key_lengthObject


64
65
66
# File 'lib/net/ssh/transport/hmac/abstract.rb', line 64

def key_length
  self.class.key_length
end

#mac_lengthObject


68
69
70
# File 'lib/net/ssh/transport/hmac/abstract.rb', line 68

def mac_length
  self.class.mac_length
end