diff options
author | o <o@immerda.ch> | 2011-06-25 23:51:47 +0200 |
---|---|---|
committer | o <o@immerda.ch> | 2011-06-25 23:51:47 +0200 |
commit | ed41e4a1c547bf8d72345d84c09d1eb8efaeecfe (patch) | |
tree | 848b8e73e66ac943759348728b8f28895051f693 | |
parent | 1fd5965d6c2687a26c4d32cd3199448755598b8d (diff) |
added a test for the parsing
-rw-r--r-- | lib/fpg/parse/packet.rb | 3 | ||||
-rw-r--r-- | lib/fpg/parse/parser.rb | 4 | ||||
-rw-r--r-- | spec/packet_parsing_spec.rb | 20 |
3 files changed, 24 insertions, 3 deletions
diff --git a/lib/fpg/parse/packet.rb b/lib/fpg/parse/packet.rb index b216491..d4b27d0 100644 --- a/lib/fpg/parse/packet.rb +++ b/lib/fpg/parse/packet.rb @@ -3,9 +3,8 @@ module FPG module PacketParser def parse( stream ) size= packet_size( stream ) - puts self - puts "i'm size "+size.to_s stream.seek(size,IO::SEEK_CUR) + return self end def packet_size( str ) tag = size_tag(str.getbyte) diff --git a/lib/fpg/parse/parser.rb b/lib/fpg/parse/parser.rb index 37a0d44..8eb47e8 100644 --- a/lib/fpg/parse/parser.rb +++ b/lib/fpg/parse/parser.rb @@ -2,13 +2,15 @@ module FPG module Parse class Parser def self.parse( stream ) + packets = [] until stream.eof? do begin - PacketHeader.new.parse( stream ) + packets << PacketHeader.new.parse(stream) rescue Exception => e raise 'parsing the message failed at position '+stream.pos.to_s+'. reason: '+ e.message end end + packets end end end diff --git a/spec/packet_parsing_spec.rb b/spec/packet_parsing_spec.rb new file mode 100644 index 0000000..2d7de61 --- /dev/null +++ b/spec/packet_parsing_spec.rb @@ -0,0 +1,20 @@ +require File.join(File.dirname(__FILE__), %w[spec_helper]) + +require 'stringio' + +include FPG::Parse + +describe Parser do + before(:each) do + @binary_pub = File.open "spec/fixtures/test.bin.pub", 'rb' + @binary_sec = File.open "spec/fixtures/test.bin.sec", 'rb' + end + + it "should find all the packets in a publickey" do + parsed = Parser.parse(@binary_pub) + parsed.any?{|packet| packet.is_a? PublicKey}.should be_true + parsed.any?{|packet| packet.is_a? Signature}.should be_true + parsed.any?{|packet| packet.is_a? PublicSubkey}.should be_true + end +end + |