class OpenSSL::X509::Name
An X.509 name represents a hostname, email address or other entity associated with a public key.
You can create a Name by parsing a distinguished name String or by supplying the distinguished name as an Array.
name = OpenSSL::X509::Name.parse_rfc2253 'DC=example,CN=nobody' name = OpenSSL::X509::Name.new [['CN', 'nobody'], ['DC', 'example']]
Constants
- COMPAT
-
A flag for
to_s.Breaks the name returned into multiple lines if longer than 80 characters.
- DEFAULT_OBJECT_TYPE
-
The default object type for name entries.
- MULTILINE
-
A flag for
to_s.Returns a multiline format.
- OBJECT_TYPE_TEMPLATE
-
The default object type template for name entries.
- ONELINE
-
A flag for
to_s.Returns a more readable format than
RFC2253. - RFC2253
-
A flag for
to_s.Returns an
RFC2253format name.
Public Class Methods
(distinguished_name name, template template) → void
(Array[distinguished_name] names) → void
(?String der) → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 11493
def initialize: (distinguished_name name, template template) -> void
| (Array[distinguished_name] names) -> void
| (?String der) -> void
Creates a new Name.
A name may be created from a DER encoded string der, an Array representing a distinguished_name or a distinguished_name along with a template.
name = OpenSSL::X509::Name.new [['CN', 'nobody'], ['DC', 'example']] name = OpenSSL::X509::Name.new name.to_der
See add_entry for a description of the distinguished_name Array’s contents
(String str, ?template template) → instance
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 11325
def self.parse_openssl: (String str, ?template template) -> instance
Parses the string representation of a distinguished name. Two different forms are supported:
-
OpenSSLformat (X509_NAME_oneline()) used byto_s. For example:/DC=com/DC=example/CN=nobody -
OpenSSLformat (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.
(String str, ?template template) → instance
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 11336
def self.parse_rfc2253: (String str, ?template template) -> instance
Parses the UTF-8 string representation of a distinguished name, according to RFC 2253.
See also to_utf8 for the opposite operation.
Public Instance Methods
Compares this Name with other and returns 0 if they are the same and -1 or ++1+ if they are greater or less than each other respectively. Returns nil if they are not comparable (i.e. different types).
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 11376
def add_entry: (String oid, String value, ?loc: Integer, ?set: Integer) -> self
Adds a new entry with the given oid and value to this name. The oid is an object identifier defined in ASN.1. Some common OIDs are:
- C
-
Country
Name - CN
-
Common
Name - DC
-
Domain Component
- O
-
Organization
Name - OU
-
Organizational Unit
Name - ST
-
State or Province
Name
The optional keyword parameters loc and set specify where to insert the new attribute. Refer to the manpage of X509_NAME_add_entry(3) for details. loc defaults to -1 and set defaults to 0. This appends a single-valued RDN to the end.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 11387
def cmp: (untyped other) -> Integer?
Compares this Name with other and returns 0 if they are the same and -1 or ++1+ if they are greater or less than each other respectively. Returns nil if they are not comparable (i.e. different types).
(self other) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 11395
def eql?: (self other) -> bool
Returns true if name and other refer to the same hash key.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 11404
def hash: () -> Integer
The hash value returned is suitable for use as a certificate’s filename in a CA path.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 11412
def hash_old: () -> Integer
Returns an MD5 based hash used in OpenSSL 0.9.X.
(self) → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 11502
def initialize_copy: (self) -> void
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 11414
def inspect: () -> String
(untyped q) → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 11421
def pretty_print: (untyped q) -> untyped
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 11430
def to_a: () -> Array[[ String, String, Integer ]]
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 11438
def to_der: () -> String
Converts the name to DER encoding
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 11462
def to_s: (?format format) -> String
Returns a String representation of the Distinguished Name. format is one of:
If format is omitted, the largely broken and traditional OpenSSL format (X509_NAME_oneline() format) is chosen.
<strong>Use of this method is discouraged.</strong> None of the formats other than OpenSSL::X509::Name::RFC2253 is standardized and may show an inconsistent behavior through OpenSSL versions.
It is recommended to use to_utf8 instead, which is equivalent to calling name.to_s(OpenSSL::X509::Name::RFC2253).force_encoding("UTF-8").