Class: OpenSSL::X509::Name

Inherits:
Object
  • Object
show all
Includes:
Marshal
Defined in:
lib/openssl/x509.rb

Defined Under Namespace

Modules: RFC2253DN

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Marshal

#_dump, included

Class Method Details

.parse_openssl(str, template = OBJECT_TYPE_TEMPLATE) ⇒ Object Also known as: parse

Parses the string representation of a distinguished name. Two different forms are supported:

  • OpenSSL format (X509_NAME_oneline()) used by #to_s. For example: /DC=com/DC=example/CN=nobody

  • OpenSSL format (X509_NAME_print()) used by #to_s(OpenSSL::X509::Name::COMPAT). For example: DC=com, DC=example, CN=nobody

Neither of them is standardized and has quirks and inconsistencies in handling of escaped characters or multi-valued RDNs.

Use of this method is discouraged in new applications. See Name.parse_rfc2253 and #to_utf8 for the alternative.



305
306
307
308
309
310
311
312
313
314
# File 'lib/openssl/x509.rb', line 305

def parse_openssl(str, template=OBJECT_TYPE_TEMPLATE)
  if str.start_with?("/")
    # /A=B/C=D format
    ary = str[1..-1].split("/").map { |i| i.split("=", 2) }
  else
    # Comma-separated
    ary = str.split(",").map { |i| i.strip.split("=", 2) }
  end
  self.new(ary, template)
end

.parse_rfc2253(str, template = OBJECT_TYPE_TEMPLATE) ⇒ Object

Parses the UTF-8 string representation of a distinguished name, according to RFC 2253.

See also #to_utf8 for the opposite operation.



286
287
288
289
# File 'lib/openssl/x509.rb', line 286

def parse_rfc2253(str, template=OBJECT_TYPE_TEMPLATE)
  ary = OpenSSL::X509::Name::RFC2253DN.scan(str)
  self.new(ary, template)
end

Instance Method Details

#pretty_print(q) ⇒ Object



319
320
321
322
323
324
# File 'lib/openssl/x509.rb', line 319

def pretty_print(q)
  q.object_group(self) {
    q.text ' '
    q.text to_s(OpenSSL::X509::Name::RFC2253)
  }
end