Class: Xml::Kit::KeyPair
- Inherits:
-
Object
- Object
- Xml::Kit::KeyPair
- Defined in:
- lib/xml/kit/key_pair.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#certificate ⇒ Object
readonly
Returns the value of attribute certificate.
-
#private_key ⇒ Object
readonly
Returns the value of attribute private_key.
-
#public_key ⇒ Object
readonly
Returns the value of attribute public_key.
Class Method Summary collapse
-
.generate(use:, passphrase: SecureRandom.uuid, algorithm: ::Xml::Kit::Crypto::SymmetricCipher::DEFAULT_ALGORITHM) ⇒ Object
Returns a generated self signed certificate with private key.
Instance Method Summary collapse
-
#for?(use) ⇒ Boolean
Returns true if the key pair is the designated use.
-
#initialize(certificate, private_key, passphrase, use) ⇒ KeyPair
constructor
A new instance of KeyPair.
Constructor Details
#initialize(certificate, private_key, passphrase, use) ⇒ KeyPair
Returns a new instance of KeyPair.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/xml/kit/key_pair.rb', line 10 def initialize(certificate, private_key, passphrase, use) @certificate = ::Xml::Kit::Certificate.new(certificate, use: use) @private_key = if passphrase.present? OpenSSL::PKey::RSA.new(private_key, passphrase) else OpenSSL::PKey::RSA.new(private_key) end @public_key = @private_key.public_key end |
Instance Attribute Details
#certificate ⇒ Object (readonly)
Returns the value of attribute certificate.
6 7 8 |
# File 'lib/xml/kit/key_pair.rb', line 6 def certificate @certificate end |
#private_key ⇒ Object (readonly)
Returns the value of attribute private_key.
7 8 9 |
# File 'lib/xml/kit/key_pair.rb', line 7 def private_key @private_key end |
#public_key ⇒ Object (readonly)
Returns the value of attribute public_key.
8 9 10 |
# File 'lib/xml/kit/key_pair.rb', line 8 def public_key @public_key end |
Class Method Details
.generate(use:, passphrase: SecureRandom.uuid, algorithm: ::Xml::Kit::Crypto::SymmetricCipher::DEFAULT_ALGORITHM) ⇒ Object
Returns a generated self signed certificate with private key.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/xml/kit/key_pair.rb', line 33 def self.generate( use:, passphrase: SecureRandom.uuid, algorithm: ::Xml::Kit::Crypto::SymmetricCipher::DEFAULT_ALGORITHM ) algorithm = ::Xml::Kit::Crypto::SymmetricCipher::ALGORITHMS[algorithm] certificate, private_key = SelfSignedCertificate.new.create( algorithm: algorithm, passphrase: passphrase ) new(certificate, private_key, passphrase, use) end |
Instance Method Details
#for?(use) ⇒ Boolean
Returns true if the key pair is the designated use.
24 25 26 |
# File 'lib/xml/kit/key_pair.rb', line 24 def for?(use) certificate.for?(use) end |