module HrrRbSsh::Transport::EncryptionAlgorithm::Functionable
Public Class Methods
included(klass)
click to toggle source
# 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
new(direction, iv, key, logger: nil)
click to toggle source
# 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
Public Instance Methods
block_size()
click to toggle source
# File lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb, line 32 def block_size self.class::BLOCK_SIZE end
decrypt(data)
click to toggle source
# 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)
click to toggle source
# 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
iv_length()
click to toggle source
# File lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb, line 36 def iv_length self.class::IV_LENGTH end
key_length()
click to toggle source
# File lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb, line 40 def key_length self.class::KEY_LENGTH end