Class: Veil::Cipher

Inherits:
Object
  • Object
show all
Defined in:
lib/veil/cipher.rb,
lib/veil/cipher/v1.rb,
lib/veil/cipher/v2.rb

Defined Under Namespace

Classes: V1, V2

Constant Summary collapse

DEFAULT_DECRYPTOR =
Veil::Cipher::V1
DEFAULT_ENCRYPTOR =
Veil::Cipher::V2

Class Method Summary collapse

Class Method Details

.create(opts = {}) ⇒ Object

Create a new Cipher instance

Defaults to using v1 for decryption (noop), v2 for encryption. If invoked as default, v2 will generate key and iv.

Examples:

Veil::Cipher.create(type: “V1”)

Veil::Cipher.create(type: “V2”, key: “blah”, iv: “vi”)

Parameters:

  • opts (defaults to: {})

    Hash<Symbol> a hash of options to pass to the constructor



21
22
23
24
25
26
27
28
29
# File 'lib/veil/cipher.rb', line 21

def create(opts = {})
  case opts
  when {}, nil
    [ DEFAULT_DECRYPTOR.new({}), DEFAULT_ENCRYPTOR.new({}) ]
  else
    cipher = const_get(opts[:type])
    [ cipher.new(opts), cipher.new(opts) ]
  end
end