Class: Rails::Auth::X509::Certificate
- Inherits:
-
Object
- Object
- Rails::Auth::X509::Certificate
- Defined in:
- lib/rails/auth/x509/certificate.rb
Overview
X.509 client certificates obtained from HTTP requests
Instance Attribute Summary collapse
-
#certificate ⇒ Object
readonly
Returns the value of attribute certificate.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Compare ourself to another object by ensuring that it has the same type and that its certificate pem is the same as ours.
- #[](component) ⇒ Object
-
#attributes ⇒ Hash
Generates inspectable attributes for debugging.
- #cn ⇒ Object (also: #common_name)
-
#initialize(certificate) ⇒ Certificate
constructor
A new instance of Certificate.
- #ou ⇒ Object (also: #organizational_unit)
Constructor Details
#initialize(certificate) ⇒ Certificate
Returns a new instance of Certificate.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rails/auth/x509/certificate.rb', line 10 def initialize(certificate) unless certificate.is_a?(OpenSSL::X509::Certificate) raise 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 |
Instance Attribute Details
#certificate ⇒ Object (readonly)
Returns the value of attribute certificate.
8 9 10 |
# File 'lib/rails/auth/x509/certificate.rb', line 8 def certificate @certificate end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Compare ourself to another object by ensuring that it has the same type and that its certificate pem is the same as ours
51 52 53 |
# File 'lib/rails/auth/x509/certificate.rb', line 51 def ==(other) other.is_a?(self.class) && other.certificate.to_der == certificate.to_der end |
#[](component) ⇒ Object
25 26 27 |
# File 'lib/rails/auth/x509/certificate.rb', line 25 def [](component) @subject[component.to_s.upcase] end |
#attributes ⇒ Hash
Generates inspectable attributes for debugging
42 43 44 45 46 47 |
# File 'lib/rails/auth/x509/certificate.rb', line 42 def attributes { cn: cn, ou: ou } end |
#cn ⇒ Object Also known as: common_name
29 30 31 |
# File 'lib/rails/auth/x509/certificate.rb', line 29 def cn @subject["CN".freeze] end |
#ou ⇒ Object Also known as: organizational_unit
34 35 36 |
# File 'lib/rails/auth/x509/certificate.rb', line 34 def ou @subject["OU".freeze] end |