Class: Izokatu::Openssl::PublicKey::EC::KeysGenerator
- Inherits:
-
KeysGenerator
- Object
- KeysGenerator
- Izokatu::Openssl::PublicKey::EC::KeysGenerator
- 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
-
#cipher ⇒ String
readonly
Cipher for keys generation.
Instance Method Summary collapse
-
#generate_private_key ⇒ OpenSSL::PKey::EC
private
Performing generation of OpenSSL EC private key.
-
#generate_public_key(private_key) ⇒ OpenSSL::PKey::EC
private
Performing generation of OpenSSL EC private key.
-
#initialize(cipher:) ⇒ KeysGenerator
constructor
Initialize option for OpenSSL EC keys generation.
-
#perform ⇒ Hash
Performing generation of OpenSSL EC private and public keys.
-
#validate_ec_cipher! ⇒ Object
private
Verifying EC cipher.
Methods included from Callable
Constructor Details
#initialize(cipher:) ⇒ KeysGenerator
Initialize option for OpenSSL EC keys generation
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
#cipher ⇒ String (readonly)
Returns 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_key ⇒ OpenSSL::PKey::EC (private)
Performing generation of OpenSSL EC private key
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
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 |
#perform ⇒ Hash
Performing generation of OpenSSL EC private and public keys
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
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 |