Class: Lyrebird::Certificate

Inherits:
Object
  • Object
show all
Defined in:
lib/lyrebird/certificate.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bits: 2048, cn: nil, o: nil, valid_for: 365, valid_until: nil, key: nil, x509: nil) ⇒ Certificate

Returns a new instance of Certificate.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lyrebird/certificate.rb', line 19

def initialize(
  bits: 2048,
  cn: nil,
  o: nil,
  valid_for: 365,
  valid_until: nil,
  key: nil,
  x509: nil
)
  @common_name = cn
  @organization = o
  @valid_for = valid_for
  @valid_until = valid_until
  @key = key || OpenSSL::PKey::RSA.new(bits)
  @x509 = x509 || build_x509
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/lyrebird/certificate.rb', line 5

def key
  @key
end

#x509Object (readonly)

Returns the value of attribute x509.



5
6
7
# File 'lib/lyrebird/certificate.rb', line 5

def x509
  @x509
end

Class Method Details

.build(**kwargs) {|config| ... } ⇒ Object

Yields:

  • (config)


7
8
9
10
11
# File 'lib/lyrebird/certificate.rb', line 7

def self.build(**kwargs)
  config = OpenStruct.new(kwargs)
  yield config if block_given?
  new(**config.to_h)
end

.load(key_pem:, x509_pem:) ⇒ Object



13
14
15
16
17
# File 'lib/lyrebird/certificate.rb', line 13

def self.load(key_pem:, x509_pem:)
  key = OpenSSL::PKey::RSA.new(key_pem)
  x509 = OpenSSL::X509::Certificate.new(x509_pem)
  new(key: key, x509: x509)
end

Instance Method Details

#base64Object



48
49
50
# File 'lib/lyrebird/certificate.rb', line 48

def base64
  Base64.strict_encode64(@x509.to_der)
end

#fingerprintObject



44
45
46
# File 'lib/lyrebird/certificate.rb', line 44

def fingerprint
  OpenSSL::Digest::SHA256.hexdigest(@x509.to_der)
end

#key_pemObject



36
37
38
# File 'lib/lyrebird/certificate.rb', line 36

def key_pem
  @key.to_pem
end

#x509_pemObject



40
41
42
# File 'lib/lyrebird/certificate.rb', line 40

def x509_pem
  @x509.to_pem
end