Sha256: 64baab796ab0ea8a48a574e1a56d53fdc9ec231bdf0e878dd3f7eb4e4fa6cca8

Contents?: true

Size: 930 Bytes

Versions: 2

Compression:

Stored size: 930 Bytes

Contents

# frozen_string_literal: true

module Rails
  module Auth
    module X509
      # X.509 client certificates obtained from HTTP requests
      class Certificate
        attr_reader :certificate

        def initialize(certificate)
          unless certificate.is_a?(OpenSSL::X509::Certificate)
            fail TypeError, "expecting OpenSSL::X509::Certificate, got #{certificate.class}"
          end

          @certificate = certificate.freeze
          @subject = {}

          @certificate.subject.to_a.each do |name, data, _type|
            @subject[name.freeze] = data.freeze
          end

          @subject.freeze
        end

        def [](component)
          @subject[component.to_s.upcase]
        end

        def cn
          @subject["CN".freeze]
        end
        alias common_name cn

        def ou
          @subject["OU".freeze]
        end
        alias organizational_unit ou
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails-auth-0.2.0 lib/rails/auth/x509/certificate.rb
rails-auth-0.1.0 lib/rails/auth/x509/certificate.rb