Class: Confium::PKI::CertificateBuilder
- Inherits:
-
Object
- Object
- Confium::PKI::CertificateBuilder
- Defined in:
- lib/confium/pki/certificate_builder.rb
Instance Attribute Summary collapse
-
#issuer ⇒ Object
Returns the value of attribute issuer.
-
#not_after ⇒ Object
Returns the value of attribute not_after.
-
#not_before ⇒ Object
Returns the value of attribute not_before.
-
#serial ⇒ Object
Returns the value of attribute serial.
-
#subject ⇒ Object
Returns the value of attribute subject.
Instance Method Summary collapse
-
#build_self_signed(algorithm:, private_key:) ⇒ Hash
Build a self-signed certificate.
-
#initialize ⇒ CertificateBuilder
constructor
A new instance of CertificateBuilder.
Constructor Details
#initialize ⇒ CertificateBuilder
Returns a new instance of CertificateBuilder.
24 25 26 27 28 29 30 |
# File 'lib/confium/pki/certificate_builder.rb', line 24 def initialize @subject = "" @issuer = nil # nil = self-signed @serial = rand(1..(1 << 128)) @not_before = Time.now @not_after = Time.now + (365 * 24 * 3600) end |
Instance Attribute Details
#issuer ⇒ Object
Returns the value of attribute issuer.
22 23 24 |
# File 'lib/confium/pki/certificate_builder.rb', line 22 def issuer @issuer end |
#not_after ⇒ Object
Returns the value of attribute not_after.
22 23 24 |
# File 'lib/confium/pki/certificate_builder.rb', line 22 def not_after @not_after end |
#not_before ⇒ Object
Returns the value of attribute not_before.
22 23 24 |
# File 'lib/confium/pki/certificate_builder.rb', line 22 def not_before @not_before end |
#serial ⇒ Object
Returns the value of attribute serial.
22 23 24 |
# File 'lib/confium/pki/certificate_builder.rb', line 22 def serial @serial end |
#subject ⇒ Object
Returns the value of attribute subject.
22 23 24 |
# File 'lib/confium/pki/certificate_builder.rb', line 22 def subject @subject end |
Instance Method Details
#build_self_signed(algorithm:, private_key:) ⇒ Hash
Build a self-signed certificate.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/confium/pki/certificate_builder.rb', line 39 def build_self_signed(algorithm:, private_key:) kp = case algorithm when :ed25519 Confium::Composite.generate_ed25519_keypair when :ecdsa_p256 Confium::TC::FrostP256.generate_keypair else raise ArgumentError, "unsupported algorithm: #{algorithm}" end { subject: @subject, serial: @serial.to_s(16), not_before: @not_before.iso8601, not_after: @not_after.iso8601, algorithm: algorithm.to_s, public_key_hex: kp["public_key"].unpack1("H*"), } end |