Class: Izokatu::Openssl::PrivateKey::Auth::Encrypter

Inherits:
Default::Encrypter show all
Defined in:
lib/izokatu/openssl/private_key/auth/encrypter.rb

Overview

OpenSSL private key encrypter for authenticated ciphers

Direct Known Subclasses

CCM::Encrypter

Constant Summary collapse

DEFAULT_AUTH_OPTIONS =

Default Openssl::PrivateKey::Auth::Encrypter option

{
  auth_data: ''
}.freeze

Constants inherited from Default::Encrypter

Default::Encrypter::DEFAULT_OPTIONS

Constants inherited from Encrypter

Encrypter::DEFAULT_OPTIONS

Instance Attribute Summary collapse

Attributes inherited from Default::Encrypter

#cipher, #key, #nonce

Attributes inherited from Encrypter

#clear_data, #encrypted_data, #encrypter

Instance Method Summary collapse

Methods inherited from Default::Encrypter

#create_encrypter!, #initialize_encrypter_params!

Methods inherited from Encrypter

#import_clear_data!, #perform

Methods included from Callable

#call

Constructor Details

#initialize(cipher:, clear_data:, auth_data:) ⇒ Encrypter

Initializing options for OpenSSL EC encryption

Parameters:

Since:

  • 0.1.0



25
26
27
28
# File 'lib/izokatu/openssl/private_key/auth/encrypter.rb', line 25

def initialize(cipher:, clear_data:, auth_data:)
  super(cipher: cipher, clear_data: clear_data)
  initialize_auth_encrypter_params!(auth_data)
end

Instance Attribute Details

#auth_dataString (readonly)

Returns authenticated data.

Returns:

  • (String)

    authenticated data



10
11
12
# File 'lib/izokatu/openssl/private_key/auth/encrypter.rb', line 10

def auth_data
  @auth_data
end

Instance Method Details

#compute_auth_tag!Hash (private)

Computing authentication tag

Returns:

  • (Hash)

    authentication tag

Since:

  • 0.1.0



70
71
72
# File 'lib/izokatu/openssl/private_key/auth/encrypter.rb', line 70

def compute_auth_tag!
  { auth_tag: encrypter.auth_tag }
end

#decrypter_paramsHash (private)

Returning decrypter params

Returns:

  • (Hash)

    decrypter params

Since:

  • 0.1.1



60
61
62
# File 'lib/izokatu/openssl/private_key/auth/encrypter.rb', line 60

def decrypter_params
  super.merge(auth_data: auth_data, **compute_auth_tag!)
end

#encrypt_data!Array (private)

Encrypting data

Returns:

  • (Array)

    encrypted data with decrypter params

Since:

  • 0.1.0



49
50
51
52
# File 'lib/izokatu/openssl/private_key/auth/encrypter.rb', line 49

def encrypt_data!
  encrypted_data, decrypter_params = super
  [encrypted_data, decrypter_params]
end

#initialize_auth_encrypter_params!(auth_data) ⇒ String (private)

Initializing encrypter auth param

Returns:

  • (String)

    authenticated data

Since:

  • 0.1.0



38
39
40
41
# File 'lib/izokatu/openssl/private_key/auth/encrypter.rb', line 38

def initialize_auth_encrypter_params!(auth_data)
  @auth_data = auth_data || DEFAULT_AUTH_OPTIONS[:auth_data]
  encrypter.auth_data = @auth_data
end