Module: HrrRbSsh::Transport::EncryptionAlgorithm::Functionable
Instance Attribute Summary
Attributes included from Loggable
#log_key, #logger
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Loggable
#log_debug, #log_error, #log_fatal, #log_info, #log_warn
Class Method Details
.included(klass) ⇒ Object
12
13
14
15
16
|
# File 'lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb', line 12
def self.included klass
cipher = OpenSSL::Cipher.new(klass::CIPHER_NAME)
klass.const_set(:IV_LENGTH, cipher.iv_len)
klass.const_set(:KEY_LENGTH, cipher.key_len)
end
|
Instance Method Details
#block_size ⇒ Object
32
33
34
|
# File 'lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb', line 32
def block_size
self.class::BLOCK_SIZE
end
|
#decrypt(data) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb', line 52
def decrypt data
if data.empty?
data
else
@cipher.update(data) + @cipher.final
end
end
|
#encrypt(data) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb', line 44
def encrypt data
if data.empty?
data
else
@cipher.update(data) + @cipher.final
end
end
|
#initialize(direction, iv, key, logger: nil) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb', line 18
def initialize direction, iv, key, logger: nil
self.logger = logger
@cipher = OpenSSL::Cipher.new(self.class::CIPHER_NAME)
case direction
when Direction::OUTGOING
@cipher.encrypt
when Direction::INCOMING
@cipher.decrypt
end
@cipher.padding = 0
@cipher.iv = iv
@cipher.key = key
end
|
#iv_length ⇒ Object
36
37
38
|
# File 'lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb', line 36
def iv_length
self.class::IV_LENGTH
end
|
#key_length ⇒ Object
40
41
42
|
# File 'lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb', line 40
def key_length
self.class::KEY_LENGTH
end
|