Class: SSLyze::X509::PublicKey

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/sslyze/x509/public_key.rb

Overview

Wrapper class around OpenSSL::PKey classes that provide #algorithm and #size methods.

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#algorithm:rsa, ...

The algorithm that generated the public key.

Returns:

  • (:rsa, :dsa, :dh, :ec)

Since:

  • 1.0.0



20
21
22
23
24
25
26
27
# File 'lib/sslyze/x509/public_key.rb', line 20

def algorithm
  case __getobj__
  when OpenSSL::PKey::RSA then :rsa
  when OpenSSL::PKey::DSA then :dsa
  when OpenSSL::PKey::DH  then :dh
  when OpenSSL::PKey::EC  then :ec
  end
end

#sizeInteger

The size of the public key.

Returns:

  • (Integer)

    The number of bits in the public key.

Raises:

  • (NotImplementedError)

    Determining key size for OpenSSL::PKey::EC public keys is currently not implemented.

Since:

  • 1.0.0



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sslyze/x509/public_key.rb', line 39

def size
  pkey = __getobj__

  case pkey
  when OpenSSL::PKey::RSA then pkey.n.num_bits
  when OpenSSL::PKey::DSA then pkey.p.num_bits
  when OpenSSL::PKey::DH  then pkey.p.num_bits
  when OpenSSL::PKey::EC
    raise(NotImplementedError,"key size for #{pkey.inspect} not implemented")
  end
end