Sha256: 760c10385b1a3b7cda614d1e76a7d000d6b0d3cfc9fb0dd0c789555fe718a0e9

Contents?: true

Size: 1.33 KB

Versions: 10

Compression:

Stored size: 1.33 KB

Contents

module Xml
  module Kit
    class KeyPair # :nodoc:
      attr_reader :certificate
      attr_reader :private_key
      attr_reader :public_key

      def initialize(certificate, private_key, passphrase, use)
        @certificate = ::Xml::Kit::Certificate.new(certificate, use: use)
        @private_key = OpenSSL::PKey::RSA.new(private_key, passphrase)
        @public_key = @private_key.public_key
      end

      # Returns true if the key pair is the designated use.
      #
      # @param use [Symbol] Can be either `:signing` or `:encryption`.
      def for?(use)
        certificate.for?(use)
      end

      # Returns a generated self signed certificate with private key.
      #
      # @param use [Symbol] Can be either `:signing` or `:encryption`.
      # @param passphrase [String] the passphrase to use to encrypt the private key.
      # @param algorithm [String] the symmetric algorithm to use for encrypting the private key.
      def self.generate(use:, passphrase: SecureRandom.uuid, algorithm: ::Xml::Kit::Crypto::SymmetricCipher::DEFAULT_ALGORITHM)
        algorithm = ::Xml::Kit::Crypto::SymmetricCipher::ALGORITHMS[algorithm]
        certificate, private_key = ::Xml::Kit::SelfSignedCertificate.new.create(algorithm: algorithm, passphrase: passphrase)
        new(certificate, private_key, passphrase, use)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
xml-kit-0.1.11 lib/xml/kit/key_pair.rb
xml-kit-0.1.10 lib/xml/kit/key_pair.rb
xml-kit-0.1.9 lib/xml/kit/key_pair.rb
xml-kit-0.1.8 lib/xml/kit/key_pair.rb
xml-kit-0.1.7 lib/xml/kit/key_pair.rb
xml-kit-0.1.6 lib/xml/kit/key_pair.rb
xml-kit-0.1.5 lib/xml/kit/key_pair.rb
xml-kit-0.1.4 lib/xml/kit/key_pair.rb
xml-kit-0.1.3 lib/xml/kit/key_pair.rb
xml-kit-0.1.2 lib/xml/kit/key_pair.rb