Module: PuTTY::Key::OpenSSL::EC

Defined in:
lib/putty/key/openssl.rb

Overview

The EC module is included into OpenSSL::PKey::EC when using the PuTTY::Key refinement or calling PuTTY::Key.global_install. This adds a to_ppk instance method to OpenSSL::PKey::EC.

Instance Method Summary collapse

Instance Method Details

#to_ppkPPK

Returns a new PPK instance that is equivalent to this key.

to_ppk can be called on instances of OpenSSL::PKey::EC.

Returns:

  • (PPK)

    A new instance of PPK that is equivalent to this key.

Raises:



357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/putty/key/openssl.rb', line 357

def to_ppk
  curve = group && group.curve_name
  raise InvalidStateError, 'The key has not been fully initialized (a curve name must be assigned)' unless curve
  ssh_curve = SSH_CURVES[curve]
  raise UnsupportedCurveError, "The curve '#{curve}' is not supported" unless ssh_curve

  PPK.new.tap do |ppk|
    ppk.algorithm = "ecdsa-sha2-#{ssh_curve}"
    begin
      ppk.public_blob = Util.ssh_pack(ppk.algorithm, ssh_curve, public_key && public_key.to_bn)
      ppk.private_blob = Util.ssh_pack(private_key)
    rescue NilValueError
      raise InvalidStateError, 'The key has not been fully initialized (public_key and private_key must both be assigned)'
    end
  end
end