Module: SSLyze::XML::Certinfo::HasCertificates

Includes:
Enumerable
Included in:
CertificateValidation::VerifiedCertificateChain, ReceivedCertificateChain
Defined in:
lib/sslyze/xml/certinfo/has_certificates.rb

Overview

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#certificatesArray<Certificate> Also known as: certs

Returns all certificates in the chain.

Returns:

Since:

  • 1.0.0



42
43
44
# File 'lib/sslyze/xml/certinfo/has_certificates.rb', line 42

def certificates
  each_certificate.to_a
end

#each_certificate {|cert| ... } ⇒ Enumerator Also known as: each_cert, each

Enumerates over each certificate in the chain.

Yields:

  • (cert)

    The given block will be passed each certificate.

Yield Parameters:

Returns:

  • (Enumerator)

    If no block was given, an Enumerator will be returned.

Since:

  • 1.0.0



26
27
28
29
30
31
32
# File 'lib/sslyze/xml/certinfo/has_certificates.rb', line 26

def each_certificate
  return enum_for(__method__) unless block_given?

  @node.xpath('certificate').each do |element|
    yield Certificate.new(element)
  end
end

#each_intermediate {|cert| ... } ⇒ Enumerator

Enumerates over any intermediate certificates in the chain.

Yields:

  • (cert)

    The given block will be passed each intermediate certificate.

Yield Parameters:

  • cert (Certificate)

    An intermediate certificate in the chain.

Returns:

  • (Enumerator)

    If no block was given, an Enumerator will be returned.

Since:

  • 1.0.0



71
72
73
74
75
76
77
# File 'lib/sslyze/xml/certinfo/has_certificates.rb', line 71

def each_intermediate
  return enum_for(__method__) unless block_given?

  @node.xpath('certificate[position() > 1 and position() < last()]').each do |element|
    yield Certificate.new(element)
  end
end

#intermediatesArray<Certificate>

Returns all intermediate certificates in the chain.

Returns:

Since:

  • 1.0.0



84
85
86
# File 'lib/sslyze/xml/certinfo/has_certificates.rb', line 84

def intermediates
  each_intermediate.to_a
end

#leafCertificate?

The leaf certificate.

Returns:

Since:

  • 1.0.0



53
54
55
56
57
# File 'lib/sslyze/xml/certinfo/has_certificates.rb', line 53

def leaf
  if (element = @node.at_xpath('certificate[1]'))
    Certificate.new(element)
  end
end

#rootCertificate?

The root certificate.

Returns:

Since:

  • 1.0.0



93
94
95
96
97
# File 'lib/sslyze/xml/certinfo/has_certificates.rb', line 93

def root
  if (element = @node.at_xpath('certificate[last()]'))
    Certificate.new(element)
  end
end