Class: Rex::Proto::Kerberos::Model::KerberosFlags

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

Overview

Represents KerberosFlags. www.rfc-editor.org/rfc/rfc4120.txt

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ KerberosFlags

Returns a new instance of KerberosFlags.

Parameters:

  • value (Integer)

    the numerical value of the flags

Raises:

  • (ArgumentError)

    if any of the parameters are of an invalid type



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

def initialize(value)
  raise ArgumentError, 'Invalid value' unless value.is_a?(Integer)
  @value = value
end

Instance Attribute Details

#valueInteger (readonly)

Returns the integer value of the kerberos flags.

Returns:

  • (Integer)

    the integer value of the kerberos flags



11
12
13
# File 'lib/rex/proto/kerberos/model/kerberos_flags.rb', line 11

def value
  @value
end

Class Method Details

.from_flags(flags) ⇒ Rex::Proto::Kerberos::Model::KdcOptionFlags

Parameters:

Returns:



22
23
24
25
26
27
28
29
# File 'lib/rex/proto/kerberos/model/kerberos_flags.rb', line 22

def self.from_flags(flags)
  value = 0
  flags.each do |flag|
    value |= 1 << (31 - flag)
  end

  new(value)
end

.name(value) ⇒ Object



49
50
51
# File 'lib/rex/proto/kerberos/model/kerberos_flags.rb', line 49

def self.name(value)
  constants.select { |c| c.upcase == c }.find { |c| const_get(c) == value }
end

Instance Method Details

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

Override the equality test for KdcOptionFlags. Equality is always tested against the #value of the KdcOptionFlags.

Parameters:

  • other (Object)

    The object to test equality against

Returns:

  • (Boolean)

    whether the equality test passed

Raises:

  • (ArgumentError)

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



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rex/proto/kerberos/model/kerberos_flags.rb', line 59

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

#enabled_flag_namesArray<String>

Returns The enabled flag names.

Returns:

  • (Array<String>)

    The enabled flag names



42
43
44
45
46
47
# File 'lib/rex/proto/kerberos/model/kerberos_flags.rb', line 42

def enabled_flag_names
  sorted_flag_names = self.class.constants.sort_by { |name| self.class.const_get(name) }
  enabled_flag_names = sorted_flag_names.select { |flag| include?(self.class.const_get(flag)) }

  enabled_flag_names
end

#include?(flag) ⇒ Boolean

Returns whether the flag is present within the current KdcOptionFlags.

Parameters:

Returns:

  • (Boolean)

    whether the flag is present within the current KdcOptionFlags



37
38
39
# File 'lib/rex/proto/kerberos/model/kerberos_flags.rb', line 37

def include?(flag)
  ((value >> (31 - flag)) & 1) == 1
end

#to_iObject



31
32
33
# File 'lib/rex/proto/kerberos/model/kerberos_flags.rb', line 31

def to_i
  @value
end