Skip to content
Browse files

* Partial Body Lengths packet support.

  • Loading branch information...
1 parent 125e9bb commit 9443be15d2ec755368dd20a66139b65c2242a837 @nahi committed Nov 6, 2004
View
39 lib/pgp/packet/packet.rb
@@ -89,8 +89,17 @@ def dump
def self.load(port)
loadport = wrap_port(port)
packets = []
+ continue = false
while !loadport.eof?
- newheader, tag, lengthdefined = load_header(loadport)
+ if continue
+ lengthdefined, partial = load_length_new(loadport)
+ else
+ newheader, tag, lengthdefined, partial = load_header(loadport)
+ end
+ if partial and continue
+ raise "Partial Body Lengths packet not supported"
+ end
+ continue = partial
initpos = loadport.readlength
unless TAG_LOADER.key?(tag)
raise "Not supported: #{tag}"
@@ -111,13 +120,32 @@ def self.scan(port, io = STDOUT)
else
dumpport = IndentDumpPort.for(io)
end
+ continue = false
loadport = wrap_port(port)
while !loadport.eof?
initpos = nil
begin
- newheader, tag, lengthdefined = load_header(loadport)
+ if continue
+ lengthdefined, partial = load_length_new(loadport)
+ else
+ newheader, tag, lengthdefined, partial = load_header(loadport)
+ end
newtag = newheader ? "New" : "Old"
- dumpport.puts "#{newtag}: #{taglabel(tag)}(tag #{tag})(#{lengthdefined} bytes)\n"
+ if partial
+ if continue
+ dumpport.puts "#{newtag}(partial continue): - (tag #{tag})(#{lengthdefined} bytes)"
+ loadport.read(lengthdefined)
+ next
+ else
+ newtag += '(partial start)'
+ end
+ else
+ if continue
+ newtag += '(partial end)'
+ end
+ end
+ continue = partial
+ dumpport.puts "#{newtag}: #{taglabel(tag)}(tag #{tag})(#{lengthdefined} bytes)"
initpos = loadport.readlength
dumpport.indent(4) do
unless TAG_SCANNER.key?(tag)
@@ -174,20 +202,21 @@ def self.wrap_port(port)
def self.load_header(port)
v = load_1octet(port)
+ partial = false
if (H_BASE & v).zero?
raise "Illegal PGP packet (#{H_BASE} must be always one): #{v}"
end
if (H_FORMAT_MASK & v).nonzero?
tag = H_NEW_TAG_MASK & v
- length = load_length_new(port)
+ length, partial = load_length_new(port)
newheader = true
else
tag = (H_OLD_TAG_MASK & v) >> 2
lengthtype = H_OLD_LENGTH_MASK & v
length = load_length_old(port, lengthtype)
newheader = false
end
- return [newheader, tag, length]
+ return [newheader, tag, length, partial]
end
def self.add_loader(tag, method)
View
5 lib/pgp/packet/sigsubpacket/packet.rb
@@ -98,7 +98,10 @@ def dump
end
def self.load(port)
- length = load_length_new(port)
+ length, partial = load_length_new(port)
+ if partial
+ raise "Partial Body Lengths not allowed"
+ end
type = load_type(port)
critical = type & T_CRITICAL
type &= ~T_CRITICAL
View
10 lib/pgp/packet/support.rb
@@ -113,14 +113,14 @@ def load_length_old(port, type)
def load_length_new(port)
octet1 = load_1octet(port)
if octet1 <= 191
- octet1
+ return octet1, false
elsif octet1 <= 223
octet2 = load_1octet(port)
- ((octet1 - 192) << 8) + octet2 + 192
+ return ((octet1 - 192) << 8) + octet2 + 192, false
elsif octet1 == 255
- load_4octet(port)
- else
- raise "Unknown format"
+ return load_4octet(port), false
+ else # Partial Body Length
+ return (1 << (octet1 & 0x1f)), true
end
end
end
View
5 lib/pgp/packet/userattrsubpacket/packet.rb
@@ -71,7 +71,10 @@ def dump
end
def self.load(port)
- length = load_length_new(port)
+ length, partial = load_length_new(port)
+ if partial
+ raise "Partial Body Lengths not allowed"
+ end
type = load_type(port)
unless TAG_LOADER.key?(type)
raise "Not supported: #{type}"

0 comments on commit 9443be1

Please sign in to comment.
Something went wrong with that request. Please try again.