Module: HrrRbSsh::Transport::MacAlgorithm::Functionable

Includes:
Loggable
Included in:
HmacMd5, HmacMd5_96, HmacSha1, HmacSha1_96, HmacSha2_256, HmacSha2_512
Defined in:
lib/hrr_rb_ssh/transport/mac_algorithm/functionable.rb

Instance Attribute Summary

Attributes included from Loggable

#log_key, #logger

Instance Method Summary collapse

Methods included from Loggable

#log_debug, #log_error, #log_fatal, #log_info, #log_warn

Instance Method Details

#compute(sequence_number, unencrypted_packet) ⇒ Object



25
26
27
28
29
# File 'lib/hrr_rb_ssh/transport/mac_algorithm/functionable.rb', line 25

def compute sequence_number, unencrypted_packet
  data = DataType::Uint32.encode(sequence_number) + unencrypted_packet
  digest = OpenSSL::HMAC.digest self.class::DIGEST, @key, data
  digest[0, digest_length]
end

#digest_lengthObject



17
18
19
# File 'lib/hrr_rb_ssh/transport/mac_algorithm/functionable.rb', line 17

def digest_length
  self.class::DIGEST_LENGTH
end

#initialize(key, logger: nil) ⇒ Object



12
13
14
15
# File 'lib/hrr_rb_ssh/transport/mac_algorithm/functionable.rb', line 12

def initialize key, logger: nil
  self.logger = logger
  @key = key
end

#key_lengthObject



21
22
23
# File 'lib/hrr_rb_ssh/transport/mac_algorithm/functionable.rb', line 21

def key_length
  self.class::KEY_LENGTH
end