Class: SSLyze::X509::Name

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sslyze/x509/name.rb

Overview

Wrapper object for OpenSSL::X509::Name.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Name

Returns a new instance of Name.

Parameters:

  • name (OpenSSL::X509::Name)

    The OpenSSL X509 name object.

Since:

  • 1.0.0



29
30
31
32
# File 'lib/sslyze/x509/name.rb', line 29

def initialize(name)
  @name    = name
  @entries = name.to_a
end

Instance Attribute Details

#entriesArray<(String, String, Integer)> (readonly)

The parsed entries of the name.

Returns:

  • (Array<(String, String, Integer)>)

Since:

  • 1.0.0



23
24
25
# File 'lib/sslyze/x509/name.rb', line 23

def entries
  @entries
end

#nameObject (readonly, protected)

Since:

  • 1.0.0



190
191
192
# File 'lib/sslyze/x509/name.rb', line 190

def name
  @name
end

Instance Method Details

#[](key) ⇒ String?

Finds the entry with the matcing OID (Object IDentifier).

Parameters:

  • key (String)

Returns:

  • (String, nil)

Since:

  • 1.0.0



61
62
63
64
65
66
67
# File 'lib/sslyze/x509/name.rb', line 61

def [](key)
  each do |oid,value,type|
    return value if oid == key
  end

  return nil
end

#cmp(other) ⇒ Object



156
157
158
# File 'lib/sslyze/x509/name.rb', line 156

def cmp(other)
  @name.cmp(other.name)
end

#common_nameDomain Also known as: cn

The Common Name (CN) entry.

Returns:

Since:

  • 1.0.0



86
87
88
# File 'lib/sslyze/x509/name.rb', line 86

def common_name
  @common_name ||= Domain.new(self['CN'])
end

#country_nameString Also known as: country, c

The Country (C) entry.

Returns:

  • (String)

Since:

  • 1.0.0



74
75
76
# File 'lib/sslyze/x509/name.rb', line 74

def country_name
  @country_name ||= self['C']
end

#domain_componentString? Also known as: dc

The Domain Component (DC) entry.

Returns:

  • (String, nil)

Since:

  • 1.0.0



97
98
99
# File 'lib/sslyze/x509/name.rb', line 97

def domain_component
  @domain_component ||= self['DC']
end

#each {|oid, value, type| ... } ⇒ Object

Enumerates over the entries.

Yields:

  • (oid, value, type)

Yield Parameters:

  • oid (String)

    The Object IDentifier.

  • value (String)

    The entry's value.

  • type (Integer)

    The entry type.

Since:

  • 1.0.0



48
49
50
51
52
# File 'lib/sslyze/x509/name.rb', line 48

def each(&block)
  @entries.each do |(oid,value,type)|
    yield oid, value, type
  end
end

#eql?(other) ⇒ Boolean



163
164
165
# File 'lib/sslyze/x509/name.rb', line 163

def eql?(other)
  @name.eql?(other.name)
end

#location_nameString? Also known as: location, l

The Location (L) entry.

Returns:

  • (String, nil)

Since:

  • 1.0.0



146
147
148
# File 'lib/sslyze/x509/name.rb', line 146

def location_name
  @location ||= self['L']
end

#organization_nameString Also known as: organization, o

The Organization Name (O) entry.

Returns:

  • (String)

Since:

  • 1.0.0



108
109
110
# File 'lib/sslyze/x509/name.rb', line 108

def organization_name
  @organization_name ||= self['O']
end

#organizational_unit_nameString Also known as: organizational_unit, ou

The Organization Unit Name (OU) entry.

Returns:

  • (String)

Since:

  • 1.0.0



120
121
122
# File 'lib/sslyze/x509/name.rb', line 120

def organizational_unit_name
  @organizational_unit_name ||= self['OU']
end

#state_nameString? Also known as: state, province_name, st

The State/Province Name (ST) entry.

Returns:

  • (String, nil)

Since:

  • 1.0.0



132
133
134
# File 'lib/sslyze/x509/name.rb', line 132

def state_name
  @state_name ||= self['ST']
end

#to_aObject



170
171
172
# File 'lib/sslyze/x509/name.rb', line 170

def to_a
  @name.to_a
end

#to_derObject



177
178
179
# File 'lib/sslyze/x509/name.rb', line 177

def to_der
  @name.to_der
end

#to_s(*args) ⇒ Object



184
185
186
# File 'lib/sslyze/x509/name.rb', line 184

def to_s(*args)
  @name.to_s(*args)
end