Class: Izokatu::Openssl::PrivateKey::Auth::Decrypter

Inherits:
Default::Decrypter show all
Defined in:
lib/izokatu/openssl/private_key/auth/decrypter.rb

Overview

OpenSSL private key decrypter for authenticated ciphers

Direct Known Subclasses

CCM::Decrypter

Constant Summary collapse

DEFAULT_AUTH_TAG_LENGTH =

Default Openssl::PrivateKey::Auth::Decrypter option

16

Constants inherited from Default::Decrypter

Default::Decrypter::DEFAULT_OPTIONS

Instance Attribute Summary collapse

Attributes inherited from Default::Decrypter

#cipher, #key, #nonce

Attributes inherited from Decrypter

#decrypted_data, #decrypter, #encrypted_data

Instance Method Summary collapse

Methods inherited from Default::Decrypter

#create_decrypter!, #decrypt_data!

Methods inherited from Decrypter

#decrypt_data!, #import_encrypted_data!

Methods included from Callable

#call

Constructor Details

#initialize(auth_data:, auth_tag:, cipher:, encrypted_data:, key:, nonce:) ⇒ Decrypter

Initializing options for OpenSSL EC decryption

Parameters:

Since:

  • 0.1.0



29
30
31
32
33
# File 'lib/izokatu/openssl/private_key/auth/decrypter.rb', line 29

def initialize(auth_data:, auth_tag:, cipher:, encrypted_data:, key:, nonce:)
  @auth_data = auth_data
  @auth_tag = auth_tag
  super(cipher: cipher, encrypted_data: encrypted_data, key: key, nonce: nonce)
end

Instance Attribute Details

#auth_dataString (readonly)

Returns authenticated data.

Returns:

  • (String)

    authenticated data



11
12
13
# File 'lib/izokatu/openssl/private_key/auth/decrypter.rb', line 11

def auth_data
  @auth_data
end

#auth_tagString (readonly)

Returns authentication tag.

Returns:

  • (String)

    authentication tag



13
14
15
# File 'lib/izokatu/openssl/private_key/auth/decrypter.rb', line 13

def auth_tag
  @auth_tag
end

Instance Method Details

#initialize_auth_decrypter_params!Object (private)

Initializing decrypter auth params

Since:

  • 0.1.0



61
62
63
64
65
# File 'lib/izokatu/openssl/private_key/auth/decrypter.rb', line 61

def initialize_auth_decrypter_params!
  # unless added just for ARIA-***-CCM ciphers
  decrypter.auth_data = auth_data unless cipher.include?('ARIA')
  decrypter.auth_tag = auth_tag
end

#initialize_decrypter_params!Object (private)

Initializing decrypter params

Since:

  • 0.1.0



52
53
54
55
# File 'lib/izokatu/openssl/private_key/auth/decrypter.rb', line 52

def initialize_decrypter_params!
  super
  initialize_auth_decrypter_params!
end

#performOpenSSL::Cipher

Initializing decrypter

Returns:

  • (OpenSSL::Cipher)

    decrypter instance

Since:

  • 0.1.0



41
42
43
44
# File 'lib/izokatu/openssl/private_key/auth/decrypter.rb', line 41

def perform
  verify_tag_size!
  super
end

#verify_tag_size!Object (private)

Raising exception if auth tag is truncated

Raises:

  • RuntimeError

Since:

  • 0.1.0



72
73
74
# File 'lib/izokatu/openssl/private_key/auth/decrypter.rb', line 72

def verify_tag_size!
  raise 'tag is truncated!' unless auth_tag.bytesize == DEFAULT_AUTH_TAG_LENGTH
end