Class: Net::NTLM::Message

Inherits:
FieldSet show all
Defined in:
lib/net/ntlm/message.rb,
lib/net/ntlm/message/type0.rb,
lib/net/ntlm/message/type1.rb,
lib/net/ntlm/message/type2.rb,
lib/net/ntlm/message/type3.rb

Direct Known Subclasses

Type0, Type1, Type2, Type3

Defined Under Namespace

Classes: Type0, Type1, Type2, Type3

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FieldSet

#[], #[]=, #disable, #enable, #has_disabled_fields?, #initialize, int16LE, int32LE, int64LE, names, opts, prototypes, security_buffer, string, types

Constructor Details

This class inherits a constructor from Net::NTLM::FieldSet

Class Method Details

.decode64(str) ⇒ Object


58
59
60
# File 'lib/net/ntlm/message.rb', line 58

def decode64(str)
  parse(Base64.decode64(str))
end

.parse(str) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/net/ntlm/message.rb', line 42

def parse(str)
  m = Type0.new
  m.parse(str)
  case m.type
  when 1
    t = Type1.new.parse(str)
  when 2
    t = Type2.new.parse(str)
  when 3
    t = Type3.new.parse(str)
  else
    raise ArgumentError, "unknown type: #{m.type}"
  end
  t
end

Instance Method Details

#data_edgeObject


123
124
125
# File 'lib/net/ntlm/message.rb', line 123

def data_edge
  security_buffers.map{ |n, f| f.active ? f.offset : size}.min
end

#data_sizeObject


103
104
105
# File 'lib/net/ntlm/message.rb', line 103

def data_size
  security_buffers.inject(0){|sum, a| sum += a[1].data_size}
end

#decode64(str) ⇒ Object


97
98
99
# File 'lib/net/ntlm/message.rb', line 97

def decode64(str)
  parse(Base64.decode64(str))
end

#deflagObject


116
117
118
119
120
121
# File 'lib/net/ntlm/message.rb', line 116

def deflag
  security_buffers.inject(head_size){|cur, a|
    a[1].offset = cur
    cur += a[1].data_size
  }
end

#dump_flagsObject


84
85
86
# File 'lib/net/ntlm/message.rb', line 84

def dump_flags
  FLAG_KEYS.each{ |k| print(k, "=", has_flag?(k), "\n") }
end

#encode64Object


93
94
95
# File 'lib/net/ntlm/message.rb', line 93

def encode64
  Base64.encode64(serialize).gsub(/\n/, '')
end

#has_flag?(flag) ⇒ Boolean

Returns:

  • (Boolean)

76
77
78
# File 'lib/net/ntlm/message.rb', line 76

def has_flag?(flag)
  (self[:flag].value & FLAGS[flag]) == FLAGS[flag]
end

#head_sizeObject


101
# File 'lib/net/ntlm/message.rb', line 101

alias head_size size

#parse(str) ⇒ self

Returns:

  • (self)

64
65
66
67
68
69
70
71
72
73
74
# File 'lib/net/ntlm/message.rb', line 64

def parse(str)
  super

  while has_disabled_fields? && serialize.size < str.size
    # enable the next disabled field
    self.class.names.find { |name| !self[name].active && enable(name) }
    super
  end

  self
end

#security_buffersObject


112
113
114
# File 'lib/net/ntlm/message.rb', line 112

def security_buffers
  @alist.find_all{|n, f| f.instance_of?(SecurityBuffer)}
end

#serializeObject


88
89
90
91
# File 'lib/net/ntlm/message.rb', line 88

def serialize
  deflag
  super + security_buffers.map{|n, f| f.value}.join
end

#set_flag(flag) ⇒ Object


80
81
82
# File 'lib/net/ntlm/message.rb', line 80

def set_flag(flag)
  self[:flag].value  |= FLAGS[flag]
end

#sizeObject


107
108
109
# File 'lib/net/ntlm/message.rb', line 107

def size
  head_size + data_size
end