Class: Izokatu::Rbnacl::Encrypter Abstract

Inherits:
Encrypter
  • Object
show all
Defined in:
lib/izokatu/rbnacl/encrypter.rb

Overview

This class is abstract.

Subclasses are containing implementation of #create_encrypter!

Abstract class for Rbnacl encrypters

Direct Known Subclasses

PrivateKey::Encrypter, PublicKey::Encrypter

Constant Summary

Constants inherited from Encrypter

Encrypter::DEFAULT_OPTIONS

Instance Attribute Summary collapse

Attributes inherited from Encrypter

#clear_data, #encrypted_data, #encrypter

Instance Method Summary collapse

Methods inherited from Encrypter

#encrypt_data!, #import_clear_data!, #perform

Methods included from Callable

#call

Constructor Details

#initialize(clear_data:) ⇒ Encrypter

Initializing option for encryption

Parameters:

Since:

  • 0.1.0



19
20
21
22
23
# File 'lib/izokatu/rbnacl/encrypter.rb', line 19

def initialize(clear_data:)
  super
  create_encrypter!
  generate_nonce!
end

Instance Attribute Details

#nonceString (readonly)

Returns initialization vector for one-time use.

Returns:

  • (String)

    initialization vector for one-time use



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

def nonce
  @nonce
end

Instance Method Details

#create_encrypter!Object

Creating encrypter instance

Raises:

  • RuntimeError

Since:

  • 0.1.0



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

def create_encrypter!
  raise 'Not implemented!'
end

#generate_nonce!String

Generating nonce from encrypter instance

Returns:

  • (String)

    initialization vector for one-time use

Since:

  • 0.1.0



40
41
42
# File 'lib/izokatu/rbnacl/encrypter.rb', line 40

def generate_nonce!
  @nonce = RbNaCl::Random.random_bytes(encrypter.nonce_bytes)
end