Class: Izokatu::ActionCallSelector

Inherits:
Object
  • Object
show all
Extended by:
Callable
Includes:
Contracts
Defined in:
lib/izokatu/action_call_selector.rb

Overview

Izokatu selector of action class to be called

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Callable

call

Constructor Details

#initialize(via:, mode:, action:, asym_cipher_type:, ccm_cipher:, auth_cipher:) ⇒ ActionCallSelector

Initializing options for selection of action class

Parameters:

Since:

  • 0.1.0



34
35
36
37
38
39
40
41
# File 'lib/izokatu/action_call_selector.rb', line 34

def initialize(via:, mode:, action:, asym_cipher_type:, ccm_cipher:, auth_cipher:)
  @via = via
  @mode = mode
  @action = action
  @asym_cipher_type = asym_cipher_type
  @ccm_cipher = ccm_cipher
  @auth_cipher = auth_cipher
end

Instance Attribute Details

#actionSymbol (readonly)

Returns action to execute.

Returns:

  • (Symbol)

    action to execute



15
16
17
# File 'lib/izokatu/action_call_selector.rb', line 15

def action
  @action
end

#asym_cipher_typeSymbol (readonly)

Returns OpenSSL public key cipher type.

Returns:

  • (Symbol)

    OpenSSL public key cipher type



17
18
19
# File 'lib/izokatu/action_call_selector.rb', line 17

def asym_cipher_type
  @asym_cipher_type
end

#auth_cipherBool (readonly)

Returns status of cipher as authenticated.

Returns:

  • (Bool)

    status of cipher as authenticated



21
22
23
# File 'lib/izokatu/action_call_selector.rb', line 21

def auth_cipher
  @auth_cipher
end

#ccm_cipherBool (readonly)

Returns equality of cipher mode to CCM.

Returns:

  • (Bool)

    equality of cipher mode to CCM



19
20
21
# File 'lib/izokatu/action_call_selector.rb', line 19

def ccm_cipher
  @ccm_cipher
end

#modeSymbol (readonly)

Returns mode of encryption/decryption.

Returns:

  • (Symbol)

    mode of encryption/decryption



13
14
15
# File 'lib/izokatu/action_call_selector.rb', line 13

def mode
  @mode
end

#viaSymbol (readonly)

Returns library used for encryption/decryption.

Returns:

  • (Symbol)

    library used for encryption/decryption



11
12
13
# File 'lib/izokatu/action_call_selector.rb', line 11

def via
  @via
end

Instance Method Details

#performClass

Selecting action class for keys generation or encryption/decryption

Returns:

  • (Class)

    selected class for keys generation

Since:

  • 0.1.0



49
50
51
# File 'lib/izokatu/action_call_selector.rb', line 49

def perform
  action == :keys_generation ? select_keys_generation_action_call : select_default_action_call
end

#select_default_action_callClass (private)

Selecting action class for encryption/decryption

Returns:

  • (Class)

    selected class for encryption/decryption

Since:

  • 0.1.0



78
79
80
# File 'lib/izokatu/action_call_selector.rb', line 78

def select_default_action_call
  via == :rbnacl ? select_rbnacl_action_call : select_openssl_action_call
end

#select_keys_generation_action_callClass (private)

Selecting action class for keys generation

Returns:

  • (Class)

    selected class for keys generation

Since:

  • 0.1.0



61
62
63
64
65
66
67
68
69
70
# File 'lib/izokatu/action_call_selector.rb', line 61

def select_keys_generation_action_call
  case [via, mode, action, asym_cipher_type, ccm_cipher, auth_cipher]
    in [:rbnacl, :public_key, :keys_generation, _, _, _]
      Izokatu::Rbnacl::PublicKey::KeysGenerator
    in [:openssl, :public_key, :keys_generation, :rsa, _, _]
      Izokatu::Openssl::PublicKey::RSA::KeysGenerator
    in [:openssl, :public_key, :keys_generation, :ec, _, _]
      Izokatu::Openssl::PublicKey::EC::KeysGenerator
  end
end

#select_openssl_action_callClass (private)

Selecting action class for Openssl encryption/decryption

Returns:

  • (Class)

    selected class for encryption/decryption

Since:

  • 0.1.0



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/izokatu/action_call_selector.rb', line 107

def select_openssl_action_call
  case [via, mode, action, asym_cipher_type, ccm_cipher, auth_cipher]
    in [:openssl, :private_key, :encryption, _, false, false]
      Izokatu::Openssl::PrivateKey::Default::Encrypter
    in [:openssl, :private_key, :decryption, _, false, false]
      Izokatu::Openssl::PrivateKey::Default::Decrypter
    in [:openssl, :private_key, :encryption, _, false, true]
      Izokatu::Openssl::PrivateKey::Auth::Encrypter
    in [:openssl, :private_key, :decryption, _, false, true]
      Izokatu::Openssl::PrivateKey::Auth::Decrypter
    in [:openssl, :private_key, :encryption, _, true, _]
      Izokatu::Openssl::PrivateKey::Auth::CCM::Encrypter
    in [:openssl, :private_key, :decryption, _, true, _]
      Izokatu::Openssl::PrivateKey::Auth::CCM::Decrypter
    in [:openssl, :public_key, :encryption, :rsa, _, _]
      Izokatu::Openssl::PublicKey::RSA::Encrypter
    in [:openssl, :public_key, :decryption, :rsa, _, _]
      Izokatu::Openssl::PublicKey::RSA::Decrypter
    in [:openssl, :public_key, :encryption, :ec, _, _]
      Izokatu::Openssl::PublicKey::EC::Encrypter
    in [:openssl, :public_key, :decryption, :ec, _, _]
      Izokatu::Openssl::PublicKey::EC::Decrypter
  end
end

#select_rbnacl_action_callClass (private)

Selecting action class for Rbnacl encryption/decryption

Returns:

  • (Class)

    selected class for Rbnal encryption/decryption

Since:

  • 0.1.0



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/izokatu/action_call_selector.rb', line 88

def select_rbnacl_action_call
  case [via, mode, action, asym_cipher_type, ccm_cipher, auth_cipher]
    in [:rbnacl, :private_key, :encryption, _, _, _]
      Izokatu::Rbnacl::PrivateKey::Encrypter
    in [:rbnacl, :private_key, :decryption, _, _, _]
      Izokatu::Rbnacl::PrivateKey::Decrypter
    in [:rbnacl, :public_key, :encryption, _, _, _]
      Izokatu::Rbnacl::PublicKey::Encrypter
    in [:rbnacl, :public_key, :decryption, _, _, _]
      Izokatu::Rbnacl::PublicKey::Decrypter
  end
end