Class: Lyrebird::Certificate
- Inherits:
-
Object
- Object
- Lyrebird::Certificate
- Defined in:
- lib/lyrebird/certificate.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#x509 ⇒ Object
readonly
Returns the value of attribute x509.
Class Method Summary collapse
Instance Method Summary collapse
- #base64 ⇒ Object
- #fingerprint ⇒ Object
-
#initialize(bits: 2048, cn: nil, o: nil, valid_for: 365, valid_until: nil, key: nil, x509: nil) ⇒ Certificate
constructor
A new instance of Certificate.
- #key_pem ⇒ Object
- #x509_pem ⇒ Object
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
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/lyrebird/certificate.rb', line 5 def key @key end |
#x509 ⇒ Object (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
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
#base64 ⇒ Object
48 49 50 |
# File 'lib/lyrebird/certificate.rb', line 48 def base64 Base64.strict_encode64(@x509.to_der) end |
#fingerprint ⇒ Object
44 45 46 |
# File 'lib/lyrebird/certificate.rb', line 44 def fingerprint OpenSSL::Digest::SHA256.hexdigest(@x509.to_der) end |
#key_pem ⇒ Object
36 37 38 |
# File 'lib/lyrebird/certificate.rb', line 36 def key_pem @key.to_pem end |
#x509_pem ⇒ Object
40 41 42 |
# File 'lib/lyrebird/certificate.rb', line 40 def x509_pem @x509.to_pem end |