Module: Sym::Crypt::CipherHandler

Included in:
Extensions::InstanceMethods
Defined in:
lib/sym/crypt/cipher_handler.rb

Overview

CipherHandler contains cipher-related utilities necessary to create ciphers, and seed them with the salt or iV vector. It also defines the internal structure CipherStruct which is a key struct used in constructing cipher and saving it with the data packet.

Defined Under Namespace

Classes: CipherStruct

Instance Method Summary collapse

Instance Method Details

#create_cipher(direction:, cipher_name:, iv: nil, salt: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sym/crypt/cipher_handler.rb', line 17

def create_cipher(direction:,
                  cipher_name:,
                  iv: nil,
                  salt: nil)

  cipher = NEW_CIPHER_PROC.call(cipher_name)
  cipher.send(direction)
  iv        ||= cipher.random_iv
  cipher.iv = iv
  CipherStruct.new(cipher, iv, salt)
end

#update_cipher(cipher, value) ⇒ Object



29
30
31
32
33
# File 'lib/sym/crypt/cipher_handler.rb', line 29

def update_cipher(cipher, value)
  data = cipher.update(value)
  data << cipher.final
  data
end