git-svn-id: file:///home/svn/framework3/trunk@5067 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2007-07-30 05:21:02 +00:00
parent c0701b1ea2
commit bff51b5578
1 changed files with 8 additions and 8 deletions

View File

@ -97,25 +97,25 @@ CONST = Rex::Proto::SMB::Constants
#
# Prepends an ASN1 formatted length field to a piece of data
#
def self.asn1encode(data = '')
def self.asn1encode(str = '')
res = ''
# If the high bit of the first byte is 1, it contains the number of
# length bytes that follow
case data.length
case str.length
when 0 .. 0x7F
res = [data.length].pack('C') + data
res = [str.length].pack('C') + str
when 0x80 .. 0xFF
res = [0x81, data.length].pack('CC') + data
res = [0x81, str.length].pack('CC') + str
when 0x100 .. 0xFFFF
res = [0x82, data.length].pack('Cn') + data
res = [0x82, str.length].pack('Cn') + str
when 0x10000 .. 0xffffff
res = [0x83, data.length >> 16, data.length & 0xFFFF].pack('CCn') + data
res = [0x83, str.length >> 16, str.length & 0xFFFF].pack('CCn') + str
when 0x1000000 .. 0xffffffff
res = [0x84, data.length].pack('CN') + data
res = [0x84, str.length].pack('CN') + str
else
raise "ASN1 data too long"
raise "ASN1 str too long"
end
return res
end