Class: SSLyze::X509::Domain

Inherits:
Object
  • Object
show all
Defined in:
lib/sslyze/x509/domain.rb

Overview

Represents a domain name pattern.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Domain

Initializes the subject name.

Parameters:

  • name (String)

    The subject name.

Since:

  • 1.0.0



31
32
33
34
35
36
37
38
39
40
# File 'lib/sslyze/x509/domain.rb', line 31

def initialize(name)
  @name = name

  if @name.start_with?('*.')
    @suffix = @name[1..-1]
    @domain = @name[2..-1]
  else
    @domain = @name
  end
end

Instance Attribute Details

#domainString (readonly)

The domain part of the subject name.

Returns:

  • (String)

Since:

  • 1.0.0



18
19
20
# File 'lib/sslyze/x509/domain.rb', line 18

def domain
  @domain
end

#nameString (readonly) Also known as: to_s, to_str

The subject name.

Returns:

  • (String)

Since:

  • 1.0.0



13
14
15
# File 'lib/sslyze/x509/domain.rb', line 13

def name
  @name
end

#suffixString (readonly)

The literal suffix of the subject name.

Returns:

  • (String)

Since:

  • 1.0.0



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

def suffix
  @suffix
end

Instance Method Details

#==(other) ⇒ Boolean

Compares two subject names.

Returns:

  • (Boolean)

Since:

  • 1.0.0



47
48
49
# File 'lib/sslyze/x509/domain.rb', line 47

def ==(other)
  other.kind_of?(self.class) && @name == other.name
end

#include?(domain) ⇒ Boolean Also known as: ===

Tests whether the domain is matched by the subject name.

Returns:

  • (Boolean)

Since:

  • 1.0.0



54
55
56
57
58
59
60
61
# File 'lib/sslyze/x509/domain.rb', line 54

def include?(domain)
  if @name.start_with?('*.') # wildcard
    domain.end_with?(@suffix) || # does the domain share the suffix
      domain == @domain            # does the domain match the suffix
  else # exact match
    domain == @name
  end
end

#inspectString

Inspects the subject name.

Returns:

  • (String)

Since:

  • 1.0.0



73
74
75
# File 'lib/sslyze/x509/domain.rb', line 73

def inspect
  "#<#{self.class}: #{self}>"
end