Sha256: 6cd335f59b40410cea9ab4526d64515e0d12d2b184543752e58ca01fda1a5625

Contents?: true

Size: 999 Bytes

Versions: 2

Compression:

Stored size: 999 Bytes

Contents

module Saml
  module Kit
    class Certificate
      attr_reader :value, :use

      def initialize(value, use:)
        @value = value
        @use = use.downcase.to_sym
      end

      def fingerprint
        Fingerprint.new(value)
      end

      def for?(use)
        self.use == use.to_sym
      end

      def encryption?
        :encryption == use
      end

      def signing?
        :signing == use
      end

      def x509
        self.class.to_x509(value)
      end

      def public_key
        x509.public_key
      end

      def ==(other)
        self.to_s == other.to_s
      end

      def eql?(other)
        self == other
      end

      def hash
        value.hash
      end

      def to_s
        value
      end

      def self.to_x509(value)
        OpenSSL::X509::Certificate.new(Base64.decode64(value))
      rescue OpenSSL::X509::CertificateError => error
        Saml::Kit.logger.warn(error)
        OpenSSL::X509::Certificate.new(value)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
saml-kit-0.2.2 lib/saml/kit/certificate.rb
saml-kit-0.2.1 lib/saml/kit/certificate.rb