Class: SSLyze::XML::Certinfo::Certificate::PublicKey

Inherits:
Object
  • Object
show all
Defined in:
lib/sslyze/xml/certinfo/certificate/public_key.rb

Overview

Since:

  • 1.2.0

Constant Summary collapse

ALGORITHMS =

Since:

  • 1.2.0

{
  'RSA'             => :RSA,
  'DSA'             => :DSA,
  'EllipticCurve' => :EC
}

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ PublicKey

Initializes the public-key information.

Parameters:

  • node (Nokogiri::XML::Node)

Since:

  • 1.2.0



23
24
25
# File 'lib/sslyze/xml/certinfo/certificate/public_key.rb', line 23

def initialize(node)
  @node = node
end

Instance Method Details

#algorithm:RSA, ...

The algorithm used to generate the public-key.

Returns:

  • (:RSA, :DSA, :EC)

Raises:

  • (NotImplementedError)

    Unrecognized algorithm name.

Since:

  • 1.2.0



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sslyze/xml/certinfo/certificate/public_key.rb', line 35

def algorithm
  unless @algorithm
    name = @node['algorithm']

    @algorithm = ALGORITHMS.fetch(name) do
      raise(notimplementederror,"unknown public-key algorithm: #{name.inspect}")
    end
  end

  return @algorithm
end

#curveSymbol?

The Elliptical Curve that was used.

Returns:

  • (Symbol, nil)

    The Elliptical Curve, or nil if #algorithm was not :EC.

Since:

  • 1.2.0



63
64
65
66
67
# File 'lib/sslyze/xml/certinfo/certificate/public_key.rb', line 63

def curve
  @curve ||= if (curve = @node['curve'])
               curve.to_sym
             end
end

#exponentInteger?

The exponent used to generate the public-key

Returns:

  • (Integer, nil)

Since:

  • 1.2.0



74
75
76
77
78
# File 'lib/sslyze/xml/certinfo/certificate/public_key.rb', line 74

def exponent
  @exponent ||= if (exponent = @node['exponent'])
                  exponent.to_i
                end
end

#sizeInteger

The size of the public-key.

Returns:

  • (Integer)

    The size in bits.

Since:

  • 1.2.0



53
54
55
# File 'lib/sslyze/xml/certinfo/certificate/public_key.rb', line 53

def size
  @size ||= @node['size'].to_i
end