CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/proto/kerberos/model/kerberos_flags.rb
Views: 11766
1
# -*- coding: binary -*-
2
3
module Rex
4
module Proto
5
module Kerberos
6
module Model
7
# Represents KerberosFlags.
8
# https://www.rfc-editor.org/rfc/rfc4120.txt
9
class KerberosFlags
10
# @return [Integer] the integer value of the kerberos flags
11
attr_reader :value
12
13
# @param [Integer] value the numerical value of the flags
14
# @raise [ArgumentError] if any of the parameters are of an invalid type
15
def initialize(value)
16
raise ArgumentError, 'Invalid value' unless value.is_a?(Integer)
17
@value = value
18
end
19
20
# @param [Array<Integer,Rex::Proto::Kerberos::Model::KdcOptionFlags>] flags an array of numerical values representing flags
21
# @return [Rex::Proto::Kerberos::Model::KdcOptionFlags]
22
def self.from_flags(flags)
23
value = 0
24
flags.each do |flag|
25
value |= 1 << (31 - flag)
26
end
27
28
new(value)
29
end
30
31
def to_i
32
@value
33
end
34
35
# @param [Integer,Rex::Proto::Kerberos::Model::KdcOptionFlags] flag the numerical value of the flag to test for.
36
# @return [Boolean] whether the flag is present within the current KdcOptionFlags
37
def include?(flag)
38
((value >> (31 - flag)) & 1) == 1
39
end
40
41
# @return [Array<String>] The enabled flag names
42
def enabled_flag_names
43
sorted_flag_names = self.class.constants.sort_by { |name| self.class.const_get(name) }
44
enabled_flag_names = sorted_flag_names.select { |flag| include?(self.class.const_get(flag)) }
45
46
enabled_flag_names
47
end
48
49
def self.name(value)
50
constants.select { |c| c.upcase == c }.find { |c| const_get(c) == value }
51
end
52
53
# Override the equality test for KdcOptionFlags. Equality is
54
# always tested against the #value of the KdcOptionFlags.
55
#
56
# @param other [Object] The object to test equality against
57
# @raise [ArgumentError] if the other object is not either another KdcOptionFlags or a Integer
58
# @return [Boolean] whether the equality test passed
59
def ==(other)
60
if other.is_a? self.class
61
value == other.value
62
elsif other.is_a? Integer
63
value == other
64
elsif other.nil?
65
false
66
else
67
raise ArgumentError, "Cannot compare a #{self.class} to a #{other.class}"
68
end
69
end
70
71
alias === ==
72
end
73
end
74
end
75
end
76
end
77
78