Exception: RubySMB::Error::InvalidPacket

Inherits:
RubySMBError
  • Object
show all
Defined in:
lib/ruby_smb/error.rb

Overview

Raised when trying to parse raw binary into a Packet and the data is invalid.

Instance Method Summary collapse

Constructor Details

#initialize(args = nil) ⇒ InvalidPacket

Returns a new instance of InvalidPacket.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby_smb/error.rb', line 19

def initialize(args = nil)
  if args.nil?
    super
  elsif args.is_a? String
    super(args)
  elsif args.is_a? Hash
    expected_proto = args[:expected_proto] ? translate_protocol(args[:expected_proto]) : "???"
    expected_cmd = args[:expected_cmd] || "???"
    received_proto = args[:received_proto] ? translate_protocol(args[:received_proto]) : "???"
    received_cmd = args[:received_cmd] || "???"
    super(
      "Expecting #{expected_proto} protocol "\
      "with command=#{expected_cmd}"\
      "#{(" (" + args[:expected_custom] + ")") if args[:expected_custom]}, "\
      "got #{received_proto} protocol "\
      "with command=#{received_cmd}"\
      "#{(" (" + args[:received_custom] + ")") if args[:received_custom]}"
    )
  else
    raise ArgumentError, "InvalidPacket expects a String or a Hash, got a #{args.class}"
  end
end