Class: Rex::Proto::Kerberos::Model::Error::ErrorCode

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/proto/kerberos/model/error.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value, description) ⇒ ErrorCode

Returns a new instance of ErrorCode.

Parameters:

  • name (String)

    the 'name' of the error code (i.e KDC_ERR_NONE)

  • value (Integer)

    the return value that represents that error (i.e. 0)

  • description (String)

    the verbose description of the error

Raises:

  • (ArgumentError)

    if any of the parameters are of an invalid type



26
27
28
29
30
31
32
33
34
# File 'lib/rex/proto/kerberos/model/error.rb', line 26

def initialize(name, value, description)
  raise ArgumentError, 'Invalid Error Name' unless name.is_a?(String) && !name.empty?
  raise ArgumentError, 'Invalid Error Code Value' unless value.is_a?(Integer)
  raise ArgumentError, 'Invalid Error Description' unless description.is_a?(String) && !description.empty?

  @name = name
  @value = value
  @description = description
end

Instance Attribute Details

#descriptionString (readonly)

Returns the description of the error the code represents.

Returns:

  • (String)

    the description of the error the code represents



16
17
18
# File 'lib/rex/proto/kerberos/model/error.rb', line 16

def description
  @description
end

#nameString (readonly)

Returns the name of the error code.

Returns:

  • (String)

    the name of the error code



18
19
20
# File 'lib/rex/proto/kerberos/model/error.rb', line 18

def name
  @name
end

#valueInteger (readonly)

Returns the error code that was given as a return value.

Returns:

  • (Integer)

    the error code that was given as a return value



20
21
22
# File 'lib/rex/proto/kerberos/model/error.rb', line 20

def value
  @value
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: ===

Override the equality test for ErrorCodes. Equality is always tested against the #value of the error code.

Parameters:

  • other_object (Object)

    the object to test equality against

Returns:

  • (Boolean)

    whether the equality test passed

Raises:

  • (ArgumentError)

    if the other object is not either another ErrorCode or a Integer



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rex/proto/kerberos/model/error.rb', line 42

def ==(other)
  if other.is_a? self.class
    value == other.value
  elsif other.is_a? Integer
    value == other
  elsif other.nil?
    false
  else
    raise ArgumentError, "Cannot compare a #{self.class} to a #{other.class}"
  end
end

#to_sObject



56
57
58
# File 'lib/rex/proto/kerberos/model/error.rb', line 56

def to_s
  "#{name} (#{value}) - #{description}"
end