Class: Izokatu::ActionCallOptionsSelector

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

Overview

Izokatu selector of options for selected action class

Constant Summary collapse

RBNACL_KEY_CLASSES =

RbNaCl public key classes, used for contracts

[
  RbNaCl::Boxes::Curve25519XSalsa20Poly1305::PrivateKey,
  RbNaCl::Boxes::Curve25519XSalsa20Poly1305::PublicKey
].freeze
OPENSSL_KEY_CLASSES =

OpenSSL public key classes, used for contracts

[
  OpenSSL::PKey::RSA,
  OpenSSL::PKey::EC
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Callable

call

Constructor Details

#initialize(action_class:, options:) ⇒ ActionCallOptionsSelector

Initializing options for action class

Parameters:

Since:

  • 0.1.0



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/izokatu/action_call_options_selector.rb', line 59

def initialize(action_class:, options:)
  @action_class = action_class.to_s
  @action = options[:action]
  @via = options[:via]
  @cipher = options[:cipher]
  @clear_data_string = options[:clear_data_string]
  @encrypted_data_string = options[:encrypted_data_string]
  @public_key = options[:public_key]
  @private_key = options[:private_key]
  @key = options[:key]
  @nonce = options[:nonce]
  @auth_data = options[:auth_data]
  @auth_tag = options[:auth_tag]
  @ecies_options = options[:ecies_options]
  @bit_number = options[:bit_number]
end

Instance Attribute Details

#actionSymbol (readonly)

Returns action to execute.

Returns:

  • (Symbol)

    action to execute



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

def action
  @action
end

#action_classClass (readonly)

Returns selected action class.

Returns:

  • (Class)

    selected action class



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

def action_class
  @action_class
end

#auth_dataString (readonly)

Returns authenticated data.

Returns:

  • (String)

    authenticated data



32
33
34
# File 'lib/izokatu/action_call_options_selector.rb', line 32

def auth_data
  @auth_data
end

#auth_tagString (readonly)

Returns authentication tag.

Returns:

  • (String)

    authentication tag



34
35
36
# File 'lib/izokatu/action_call_options_selector.rb', line 34

def auth_tag
  @auth_tag
end

#bit_numberInteger (readonly)

Returns bit number for OpenSSL public key RSA encryption/decryption.

Returns:

  • (Integer)

    bit number for OpenSSL public key RSA encryption/decryption



38
39
40
# File 'lib/izokatu/action_call_options_selector.rb', line 38

def bit_number
  @bit_number
end

#cipherString (readonly)

Note:

also used for OpenSSL public key ec key generation

Returns OpenSSL private key cipher.

Returns:

  • (String)

    OpenSSL private key cipher



18
19
20
# File 'lib/izokatu/action_call_options_selector.rb', line 18

def cipher
  @cipher
end

#clear_data_stringString (readonly)

Returns string of clear data for encryption.

Returns:

  • (String)

    string of clear data for encryption



20
21
22
# File 'lib/izokatu/action_call_options_selector.rb', line 20

def clear_data_string
  @clear_data_string
end

#ecies_optionsHash (readonly)

Returns options for OpenSSL public key EC encryption/decryption.

Returns:

  • (Hash)

    options for OpenSSL public key EC encryption/decryption



36
37
38
# File 'lib/izokatu/action_call_options_selector.rb', line 36

def ecies_options
  @ecies_options
end

#encrypted_data_stringString (readonly)

Returns string of encrypted data for decryption.

Returns:

  • (String)

    string of encrypted data for decryption



22
23
24
# File 'lib/izokatu/action_call_options_selector.rb', line 22

def encrypted_data_string
  @encrypted_data_string
end

#keyString (readonly)

Returns encryption key for private key encryption/decryption.

Returns:

  • (String)

    encryption key for private key encryption/decryption



28
29
30
# File 'lib/izokatu/action_call_options_selector.rb', line 28

def key
  @key
end

#nonceString (readonly)

Returns initialization vector for one-time use.

Returns:

  • (String)

    initialization vector for one-time use



30
31
32
# File 'lib/izokatu/action_call_options_selector.rb', line 30

def nonce
  @nonce
end

#private_keyRBNACL_KEY_CLASSES || OPENSSL_KEY_CLASSES (readonly)

Returns private key for public key encryption/decryption.

Returns:



26
27
28
# File 'lib/izokatu/action_call_options_selector.rb', line 26

def private_key
  @private_key
end

#public_keyRBNACL_KEY_CLASSES || OPENSSL_KEY_CLASSES (readonly)

Returns public key for public key encryption/decryption.

Returns:



24
25
26
# File 'lib/izokatu/action_call_options_selector.rb', line 24

def public_key
  @public_key
end

#viaSymbol (readonly)

Returns library used for encryption/decryption.

Returns:

  • (Symbol)

    library used for encryption/decryption



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

def via
  @via
end

Instance Method Details

#performHash

Selecting options for keys generation class or for encryption/decryption class

Returns:

  • (Hash)

    options for action class call

Since:

  • 0.1.0



82
83
84
# File 'lib/izokatu/action_call_options_selector.rb', line 82

def perform
  action == :keys_generation ? select_keys_generation_action_options : select_default_action_options
end

#select_default_action_optionsHash (private)

Selecting options for encryption/decryption class

Returns:

  • (Hash)

    options for encryption/decryption class

Since:

  • 0.1.0



111
112
113
# File 'lib/izokatu/action_call_options_selector.rb', line 111

def select_default_action_options
  via == :rbnacl ? select_rbnacl_action_options : select_openssl_action_options
end

#select_keys_generation_action_optionsHash (private)

Selecting options for keys generation class

Returns:

  • (Hash)

    options for keys generation class

Since:

  • 0.1.0



94
95
96
97
98
99
100
101
102
103
# File 'lib/izokatu/action_call_options_selector.rb', line 94

def select_keys_generation_action_options
  case action_class
  when 'Izokatu::Rbnacl::PublicKey::KeysGenerator'
    {}
  when 'Izokatu::Openssl::PublicKey::RSA::KeysGenerator'
    { bit_number: bit_number }
  when 'Izokatu::Openssl::PublicKey::EC::KeysGenerator'
    { cipher: cipher }
  end
end

#select_openssl_action_optionsHash (private)

Selecting options for Openssl encryption/decryption class

Returns:

  • (Hash)

    options for Openssl encryption/decryption class

Since:

  • 0.1.0



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/izokatu/action_call_options_selector.rb', line 154

def select_openssl_action_options
  case action_class
  when 'Izokatu::Openssl::PrivateKey::Default::Encrypter'
    { cipher: cipher, clear_data: clear_data_string }
  when 'Izokatu::Openssl::PrivateKey::Default::Decrypter'
    {
      cipher: cipher,
      encrypted_data: encrypted_data_string,
      key: key,
      nonce: nonce
    }
  when 'Izokatu::Openssl::PrivateKey::Auth::Encrypter'
    {
      cipher: cipher,
      clear_data: clear_data_string,
      auth_data: auth_data
    }
  when 'Izokatu::Openssl::PrivateKey::Auth::Decrypter'
    {
      cipher: cipher,
      encrypted_data: encrypted_data_string,
      key: key,
      nonce: nonce,
      auth_data: auth_data,
      auth_tag: auth_tag
    }
  when 'Izokatu::Openssl::PrivateKey::Auth::CCM::Encrypter'
    {
      cipher: cipher,
      clear_data: clear_data_string,
      auth_data: auth_data
    }
  when 'Izokatu::Openssl::PrivateKey::Auth::CCM::Decrypter'
    {
      cipher: cipher,
      encrypted_data: encrypted_data_string,
      key: key,
      nonce: nonce,
      auth_data: auth_data,
      auth_tag: auth_tag
    }
  when 'Izokatu::Openssl::PublicKey::RSA::Encrypter'
    { clear_data: clear_data_string, public_key: public_key }
  when 'Izokatu::Openssl::PublicKey::RSA::Decrypter'
    { private_key: private_key, encrypted_data: encrypted_data_string }
  when 'Izokatu::Openssl::PublicKey::EC::Encrypter'
    {
      clear_data: clear_data_string,
      public_key: public_key,
      ecies_options: ecies_options
    }
  when 'Izokatu::Openssl::PublicKey::EC::Decrypter'
    {
      private_key: private_key,
      encrypted_data: encrypted_data_string,
      ecies_options: ecies_options
    }
  end
end

#select_rbnacl_action_optionsHash (private)

Selecting options for Rbnacl encryption/decryption class

Returns:

  • (Hash)

    options for Rbnacl encryption/decryption class

Since:

  • 0.1.0



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/izokatu/action_call_options_selector.rb', line 121

def select_rbnacl_action_options
  case action_class
  when 'Izokatu::Rbnacl::PrivateKey::Encrypter'
    { auth_data: auth_data, clear_data: clear_data_string }
  when 'Izokatu::Rbnacl::PrivateKey::Decrypter'
    {
      encrypted_data: encrypted_data_string,
      nonce: nonce,
      key: key,
      auth_data: auth_data
    }
  when 'Izokatu::Rbnacl::PublicKey::Encrypter'
    {
      public_key: public_key,
      private_key: private_key,
      clear_data: clear_data_string
    }
  when 'Izokatu::Rbnacl::PublicKey::Decrypter'
    {
      encrypted_data: encrypted_data_string,
      nonce: nonce,
      public_key: public_key,
      private_key: private_key
    }
  end
end