Module: Sym::CipherHandler
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
Modules: ClassMethods
Classes: CipherStruct
Constant Summary
collapse
- CREATE_CIPHER =
->(name) { ::OpenSSL::Cipher.new(name) }
Instance Method Summary
collapse
Instance Method Details
#create_cipher(direction:, cipher_name:, iv: nil, salt: nil) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/sym/cipher_handler.rb', line 16
def create_cipher(direction:,
cipher_name:,
iv: nil,
salt: nil)
cipher = new_cipher(cipher_name)
cipher.send(direction)
iv ||= cipher.random_iv
cipher.iv = iv
CipherStruct.new(cipher, iv, salt)
end
|
#new_cipher(cipher_name) ⇒ Object
28
29
30
|
# File 'lib/sym/cipher_handler.rb', line 28
def new_cipher(cipher_name)
CREATE_CIPHER.call(cipher_name)
end
|
#update_cipher(cipher, value) ⇒ Object
32
33
34
35
36
|
# File 'lib/sym/cipher_handler.rb', line 32
def update_cipher(cipher, value)
data = cipher.update(value)
data << cipher.final
data
end
|