Class: Izokatu::Openssl::PublicKey::EC::KeysGenerator

Inherits:
KeysGenerator
  • Object
show all
Defined in:
lib/izokatu/openssl/public_key/ec/keys_generator.rb

Overview

OpenSSL EC keys generator

Constant Summary collapse

DEFAULT_OPTIONS =

Default options for OpenSSL EC keys generation

{
  cipher: 'secp521r1'
}.freeze

Constants inherited from KeysGenerator

KeysGenerator::KEYS_SYMBOLS, KeysGenerator::KEY_CLASSES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Callable

#call

Constructor Details

#initialize(cipher:) ⇒ KeysGenerator

Initialize option for OpenSSL EC keys generation

Parameters:

Since:

  • 0.1.0



25
26
27
28
# File 'lib/izokatu/openssl/public_key/ec/keys_generator.rb', line 25

def initialize(cipher:)
  super()
  @cipher = cipher || DEFAULT_OPTIONS[:cipher]
end

Instance Attribute Details

#cipherString (readonly)

Returns cipher for keys generation.

Returns:

  • (String)

    cipher for keys generation



12
13
14
# File 'lib/izokatu/openssl/public_key/ec/keys_generator.rb', line 12

def cipher
  @cipher
end

Instance Method Details

#generate_private_keyOpenSSL::PKey::EC (private)

Performing generation of OpenSSL EC private key

Returns:

  • (OpenSSL::PKey::EC)

    OpenSSL private key

Since:

  • 0.1.0



58
59
60
# File 'lib/izokatu/openssl/public_key/ec/keys_generator.rb', line 58

def generate_private_key
  OpenSSL::PKey::EC.new(cipher).generate_key
end

#generate_public_key(private_key) ⇒ OpenSSL::PKey::EC (private)

Performing generation of OpenSSL EC private key

Returns:

  • (OpenSSL::PKey::EC)

    OpenSSL private key

Since:

  • 0.1.0



68
69
70
71
72
# File 'lib/izokatu/openssl/public_key/ec/keys_generator.rb', line 68

def generate_public_key(private_key)
  private_key_copy = OpenSSL::PKey::EC.new(private_key.public_key.group)
  private_key_copy.public_key = private_key.public_key
  private_key_copy
end

#performHash

Performing generation of OpenSSL EC private and public keys

Returns:

  • (Hash)

    OpenSSL EC public and private keys

Since:

  • 0.1.0



36
37
38
39
# File 'lib/izokatu/openssl/public_key/ec/keys_generator.rb', line 36

def perform
  validate_ec_cipher!
  super.transform_values(&:to_pem)
end

#validate_ec_cipher!Object (private)

Verifying EC cipher

Raises:

  • RuntimeError

Since:

  • 0.1.0



48
49
50
# File 'lib/izokatu/openssl/public_key/ec/keys_generator.rb', line 48

def validate_ec_cipher!
  raise 'ERROR: Unknown EC cipher!' unless PBKEY_EC_CIPHERS.include?(cipher)
end