Fixes #127. Applying patch from Alex that solves ASN.1 encoding issues.
git-svn-id: file:///home/svn/framework3/trunk@5049 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
ce1532a64e
commit
24aac8b5ae
|
@ -94,18 +94,29 @@ CONST = Rex::Proto::SMB::Constants
|
|||
return decoded
|
||||
end
|
||||
|
||||
#
|
||||
# Prepends an ASN1 formatted length field to a piece of data
|
||||
#
|
||||
def self.asn1encode(str = '')
|
||||
res = ''
|
||||
case str.length
|
||||
when 0 .. 0x80
|
||||
res = [str.length].pack('C') + str
|
||||
when 0x81 .. 0x100
|
||||
res = [0x81, str.length].pack('CC') + str
|
||||
when 0x101 .. 0x100000
|
||||
res = [0x82, str.length].pack('Cn') + str
|
||||
when 0x100001 .. 0xffffffff
|
||||
res = [0x83, str.length].pack('CN') + str
|
||||
end
|
||||
|
||||
# If the high bit of the first byte is 1, it contains the number of
|
||||
# length bytes that follow
|
||||
|
||||
case data.length
|
||||
when 0 .. 0x7F
|
||||
res = [data.length].pack('C') + data
|
||||
when 0x80 .. 0xFF
|
||||
res = [0x81, data.length].pack('CC') + data
|
||||
when 0x100 .. 0xFFFF
|
||||
res = [0x82, data.length].pack('Cn') + data
|
||||
when 0x10000 .. 0xffffff
|
||||
res = [0x83, data.length >> 16, data.length & 0xFFFF].pack('CCn') + data
|
||||
when 0x1000000 .. 0xffffffff
|
||||
res = [0x84, data.length].pack('CN') + data
|
||||
else
|
||||
raise "ASN1 data too long"
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue