Class: Msf::OptEnum

Inherits:
OptBase show all
Defined in:
lib/msf/core/opt_enum.rb

Overview

Enum option.

Instance Attribute Summary collapse

Attributes inherited from OptBase

#advanced, #aliases, #conditions, #default, #enums, #evasion, #fallbacks, #max_length, #name, #owner, #regex, #required

Instance Method Summary collapse

Methods inherited from OptBase

#advanced?, #display_value, #empty_required_value?, #evasion?, #invalid_value_length?, #required?, #type?, #validate_on_assignment?

Constructor Details

#initialize(in_name, attrs = [], required: true, **kwargs) ⇒ OptEnum

This overrides required default from ‘false’ to ‘true’



15
16
17
18
# File 'lib/msf/core/opt_enum.rb', line 15

def initialize(in_name, attrs = [],
               required: true, **kwargs)
  super
end

Instance Attribute Details

#desc_stringObject (protected)

:nodoc:



60
61
62
# File 'lib/msf/core/opt_enum.rb', line 60

def desc_string
  @desc_string
end

Instance Method Details

#case_sensitive?Boolean (protected)

Returns:

  • (Boolean)


56
57
58
# File 'lib/msf/core/opt_enum.rb', line 56

def case_sensitive?
  enums.map(&:downcase).uniq.length != enums.uniq.length
end

#descObject



49
50
51
52
# File 'lib/msf/core/opt_enum.rb', line 49

def desc
  str = enums.join(', ') if enums
  "#{desc_string || ''} (Accepted: #{str})"
end

#desc=(value) ⇒ Object



44
45
46
47
# File 'lib/msf/core/opt_enum.rb', line 44

def desc=(value)
  self.desc_string = value
  desc
end

#normalize(value = self.value) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/msf/core/opt_enum.rb', line 32

def normalize(value = self.value)
  if valid?(value) && !value.nil?
    if case_sensitive?
      value.to_s
    else
      enums.find { |e| e.casecmp? value }
    end
  else
    nil
  end
end

#typeObject



10
11
12
# File 'lib/msf/core/opt_enum.rb', line 10

def type
  return 'enum'
end

#valid?(value = self.value, check_empty: true) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/msf/core/opt_enum.rb', line 20

def valid?(value = self.value, check_empty: true)
  return false if check_empty && empty_required_value?(value)
  return true if value.nil? && !required?
  return false if value.nil?

  if case_sensitive?
    enums.include?(value.to_s)
  else
    enums.map(&:downcase).include?(value.to_s.downcase)
  end
end