certificate.rb 572 Bytes
Newer Older
1
2
3
class Acme::Client::Certificate
  extend Forwardable

4
  attr_reader :x509, :x509_chain, :request, :private_key, :url
5
6
7

  def_delegators :x509, :to_pem, :to_der

8
  def initialize(certificate, url, chain, request)
9
    @x509 = certificate
10
    @url = url
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    @x509_chain = chain
    @request = request
  end

  def chain_to_pem
    x509_chain.map(&:to_pem).join
  end

  def x509_fullchain
    [x509, *x509_chain]
  end

  def fullchain_to_pem
    x509_fullchain.map(&:to_pem).join
  end

  def common_name
    x509.subject.to_a.find { |name, _, _| name == 'CN' }[1]
  end
end