class Izokatu::ActionCallOptionsSelector

Izokatu selector of options for selected action class

Constants

OPENSSL_KEY_CLASSES

OpenSSL public key classes, used for contracts

RBNACL_KEY_CLASSES

RbNaCl public key classes, used for contracts

Attributes

action[R]

@return [Symbol] action to execute

action_class[R]

@return [Class] selected action class

auth_data[R]

@return [String] authenticated data

auth_tag[R]

@return [String] authentication tag

bit_number[R]

@return [Integer] bit number for OpenSSL public key RSA encryption/decryption

cipher[R]

@return [String] OpenSSL private key cipher @note also used for OpenSSL public key ec key generation

clear_data_string[R]

@return [String] string of clear data for encryption

ecies_options[R]

@return [Hash] options for OpenSSL public key EC encryption/decryption

encrypted_data_string[R]

@return [String] string of encrypted data for decryption

key[R]

@return [String] encryption key for private key encryption/decryption

nonce[R]

@return [String] initialization vector for one-time use

private_key[R]

@return [RBNACL_KEY_CLASSES || OPENSSL_KEY_CLASSES] private key for public key encryption/decryption

public_key[R]

@return [RBNACL_KEY_CLASSES || OPENSSL_KEY_CLASSES] public key for public key encryption/decryption

via[R]

@return [Symbol] library used for encryption/decryption

Public Class Methods

new(action_class:, options:) click to toggle source

Initializing options for action class

@param action_class (action_class) @param options (options)

@since 0.1.0

# 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

Public Instance Methods

perform() click to toggle source

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

@return [Hash] options for action class call

@since 0.1.0

# 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

Private Instance Methods

select_default_action_options() click to toggle source

Selecting options for encryption/decryption class

@return [Hash] options for encryption/decryption class

@since 0.1.0

# 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_options() click to toggle source

Selecting options for keys generation class

@return [Hash] options for keys generation class

@since 0.1.0

# 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_options() click to toggle source

Selecting options for Openssl encryption/decryption class

@return [Hash] options for Openssl encryption/decryption class

@since 0.1.0

# 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_options() click to toggle source

Selecting options for Rbnacl encryption/decryption class

@return [Hash] options for Rbnacl encryption/decryption class

@since 0.1.0

# 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