Module: HrrRbSsh::Transport::EncryptionAlgorithm::Functionable
- Included in:
- Aes128Cbc, Aes128Ctr, Aes192Cbc, Aes192Ctr, Aes256Cbc, Aes256Ctr, Arcfour, BlowfishCbc, Cast128Cbc, ThreeDesCbc
- Defined in:
- lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb
Class Method Summary collapse
Instance Method Summary collapse
- #block_size ⇒ Object
- #decrypt(data) ⇒ Object
- #encrypt(data) ⇒ Object
- #initialize(direction, iv, key) ⇒ Object
- #iv_length ⇒ Object
- #key_length ⇒ Object
Class Method Details
.included(klass) ⇒ Object
10 11 12 13 14 |
# File 'lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb', line 10 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
30 31 32 |
# File 'lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb', line 30 def block_size self.class::BLOCK_SIZE end |
#decrypt(data) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb', line 50 def decrypt data if data.empty? data else @cipher.update(data) + @cipher.final end end |
#encrypt(data) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb', line 42 def encrypt data if data.empty? data else @cipher.update(data) + @cipher.final end end |
#initialize(direction, iv, key) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb', line 16 def initialize direction, iv, key @logger = Logger.new(self.class.name) @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
34 35 36 |
# File 'lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb', line 34 def iv_length self.class::IV_LENGTH end |
#key_length ⇒ Object
38 39 40 |
# File 'lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb', line 38 def key_length self.class::KEY_LENGTH end |