Class: Owasp::Esapi::Codec::OsCodec
- Defined in:
- lib/codec/os_codec.rb
Constant Summary collapse
- WINDOWS_HOST =
Window Host flag
:Windows
- UNIX_HOST =
Unix Host flag
:Unix
Constants inherited from BaseCodec
BaseCodec::END_CODE_POINT, BaseCodec::START_CODE_POINT
Instance Method Summary collapse
-
#decode_char(input) ⇒ Object
Returns the decoded version of the character starting at index, or nil if no decoding is possible.
-
#encode_char(immune, input) ⇒ Object
Returns shell encoded character ^ - for windows \ - for unix.
-
#initialize(os = nil) ⇒ OsCodec
constructor
Setup the code, if no os is passed in the codec will guess the OS based on the ruby host_os variable.
-
#os ⇒ Object
get the configured OS.
Methods inherited from BaseCodec
Constructor Details
#initialize(os = nil) ⇒ OsCodec
Setup the code, if no os is passed in the codec will guess the OS based on the ruby host_os variable
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/codec/os_codec.rb', line 16 def initialize(os = nil) @host = nil @escape_char = '' host_os = os if os.nil? host_os = case Config::CONFIG['host_os'] when /mswin|windows/i then WINDOWS_HOST when /linux/i then UNIX_HOST when /darwin/i then UNIX_HOST when /sunos|solaris/i then UNIX_HOST else UNIX_HOST end end if host_os == WINDOWS_HOST @host = WINDOWS_HOST @escape_char = '^' elsif host_os == UNIX_HOST @host = UNIX_HOST @escape_char = '\\' end end |
Instance Method Details
#decode_char(input) ⇒ Object
Returns the decoded version of the character starting at index, or nil if no decoding is possible. <p> Formats all are legal both upper/lower case:
^x - all special characters when configured for WINDOWS
\\ - all special characters when configured for UNIX
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/codec/os_codec.rb', line 58 def decode_char(input) input.mark first = input.next # check first char if first.nil? input.reset return nil end # if it isnt escape return nil if first != @escape_char input.reset return nil end # get teh escape value return input.next end |
#encode_char(immune, input) ⇒ Object
Returns shell encoded character ^ - for windows \ - for unix
46 47 48 49 50 |
# File 'lib/codec/os_codec.rb', line 46 def encode_char(immune,input) return input if immune.include?(input) return input if hex(input).nil? return "#{@escape_char}#{input}" end |
#os ⇒ Object
get the configured OS
39 40 41 |
# File 'lib/codec/os_codec.rb', line 39 def os @host end |