Class: Rails::Auth::X509::Filter::Pem

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/auth/x509/filter/pem.rb

Overview

Extract OpenSSL::X509::Certificates from Privacy Enhanced Mail (PEM) certificates

Direct Known Subclasses

PemUrlencoded

Instance Method Summary collapse

Instance Method Details

#call(pem) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/rails/auth/x509/filter/pem.rb', line 9

def call(pem)
  # Normalize the whitespace in the certificate to the exact format
  # certificates are normally formatted in otherwise parsing with fail
  # with a 'nested asn1 error'. split(" ") handles sequential whitespace
  # characters like \t, \n, and space.
  OpenSSL::X509::Certificate.new(pem.split(" ").instance_eval do
    [[self[0], self[1]].join(" "), self[2...-2], [self[-2], self[-1]].join(" ")]
      .flatten.join("\n")
  end).freeze
end