summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoro <o@immerda.ch>2011-06-27 17:12:12 +0200
committero <o@immerda.ch>2011-06-27 17:12:12 +0200
commit86ff54aaffc7975e1f221a4c9aced9ef34ba246f (patch)
tree97858fe4dddfc316612655ef3eca6b9768def824
parente879a280c3c3af2f87eee37a189fd3a8ae8c6106 (diff)
some more cleanup
-rw-r--r--lib/fpg/_helpers/parsing.rb23
-rw-r--r--lib/fpg/packets/packet.rb6
-rw-r--r--lib/fpg/packets/public_key.rb1
-rw-r--r--lib/fpg/packets/secret_key.rb1
-rw-r--r--lib/fpg/parse/packets/key_material.rb (renamed from lib/fpg/parse/key_material.rb)7
-rw-r--r--lib/fpg/parse/packets/packet.rb (renamed from lib/fpg/parse/packet.rb)3
-rw-r--r--lib/fpg/parse/packets/public_key.rb (renamed from lib/fpg/parse/public_key.rb)1
-rw-r--r--lib/fpg/parse/packets/public_key_encrypted_session_key.rb (renamed from lib/fpg/parse/public_key_encrypted_session_key.rb)0
-rw-r--r--lib/fpg/parse/packets/public_subkey.rb (renamed from lib/fpg/parse/public_subkey.rb)1
-rw-r--r--lib/fpg/parse/packets/secret_key.rb (renamed from lib/fpg/parse/secret_key.rb)1
-rw-r--r--lib/fpg/parse/packets/secret_subkey.rb (renamed from lib/fpg/parse/secret_subkey.rb)1
-rw-r--r--lib/fpg/parse/packets/signature.rb (renamed from lib/fpg/parse/signature.rb)3
-rw-r--r--lib/fpg/parse/packets/symmetric_encrypted_and_integrity_protected_data.rb (renamed from lib/fpg/parse/symmetric_encrypted_and_integrity_protected_data.rb)3
-rw-r--r--lib/fpg/parse/packets/user_id.rb (renamed from lib/fpg/parse/user_id.rb)3
-rw-r--r--lib/fpg/public_key_algos/algo.rb5
15 files changed, 39 insertions, 20 deletions
diff --git a/lib/fpg/_helpers/parsing.rb b/lib/fpg/_helpers/parsing.rb
new file mode 100644
index 0000000..b7f6aa2
--- /dev/null
+++ b/lib/fpg/_helpers/parsing.rb
@@ -0,0 +1,23 @@
+module FPG
+ module Parseable
+ def << stream
+ return if @parser_injected
+ @parser_injected = true
+
+ klass = self.class
+ modules = []
+
+ while Parse.const_defined?("#{klass.name.split('::').last}Parser") do
+ modules << Parse.const_get("#{klass.name.split('::').last}Parser")
+ klass = klass.superclass
+ end
+
+ "load all parsing modules in reverse order such that the most specific implementation is used"
+ modules.reverse.each do |m|
+ self.class.send(:include, m)
+ end
+
+ parse(stream)
+ end
+ end
+end
diff --git a/lib/fpg/packets/packet.rb b/lib/fpg/packets/packet.rb
index 75ee063..1f3d542 100644
--- a/lib/fpg/packets/packet.rb
+++ b/lib/fpg/packets/packet.rb
@@ -2,12 +2,8 @@ module FPG
module Packets
class Packet
include TaggedSubclasses
+ include Parseable
attr_accessor :byte_size
- def << stream
- self.class.send(:include, Parse::PacketParser)
- self.class.send(:include, Parse.const_get("#{self.class.name.split('::').last}Parser"))
- parse(stream)
- end
end
end
end
diff --git a/lib/fpg/packets/public_key.rb b/lib/fpg/packets/public_key.rb
index 14e9612..be77437 100644
--- a/lib/fpg/packets/public_key.rb
+++ b/lib/fpg/packets/public_key.rb
@@ -1,6 +1,7 @@
module FPG
module Packets
class PublicKey < Packet
+ attr_accessor :created,:algo,:key_material
def self.tag
6
end
diff --git a/lib/fpg/packets/secret_key.rb b/lib/fpg/packets/secret_key.rb
index b5a0558..00b6da7 100644
--- a/lib/fpg/packets/secret_key.rb
+++ b/lib/fpg/packets/secret_key.rb
@@ -1,5 +1,6 @@
module FPG
module Packets
+ attr_accessor :created,:algo,:key_material
class SecretKey < Packet
def self.tag
5
diff --git a/lib/fpg/parse/key_material.rb b/lib/fpg/parse/packets/key_material.rb
index 96d57db..ab1105d 100644
--- a/lib/fpg/parse/key_material.rb
+++ b/lib/fpg/parse/packets/key_material.rb
@@ -1,11 +1,11 @@
module FPG
module Parse
module KeyMaterialParser
- def parse_content
+ def parse_content_
parse_version
parse_creation
parse_algo
- @stream.seek(@byte_size-6,IO::SEEK_CUR)
+ parse_key_material
end
def parse_creation
@created= stream.read(4).unpack("N1")
@@ -13,6 +13,9 @@ module FPG
def parse_algo
@algo= PublicKeyAlgos::Algo.with_tag(stream.getbyte)
end
+ def parse_key_material
+ algo.parse_for(stream,self)
+ end
def parse_version
raise "only key material packets with version 4 are supported" unless @stream.getbyte == 4
end
diff --git a/lib/fpg/parse/packet.rb b/lib/fpg/parse/packets/packet.rb
index c24d5d6..2f34b83 100644
--- a/lib/fpg/parse/packet.rb
+++ b/lib/fpg/parse/packets/packet.rb
@@ -16,6 +16,9 @@ module FPG
def skip
stream.seek(byte_size,IO::SEEK_CUR)
end
+ def parse_content
+ skip
+ end
private
diff --git a/lib/fpg/parse/public_key.rb b/lib/fpg/parse/packets/public_key.rb
index 8e93a7e..9fe54a4 100644
--- a/lib/fpg/parse/public_key.rb
+++ b/lib/fpg/parse/packets/public_key.rb
@@ -1,7 +1,6 @@
module FPG
module Parse
module PublicKeyParser
- include KeyMaterialParser
end
end
end
diff --git a/lib/fpg/parse/public_key_encrypted_session_key.rb b/lib/fpg/parse/packets/public_key_encrypted_session_key.rb
index 68360c7..68360c7 100644
--- a/lib/fpg/parse/public_key_encrypted_session_key.rb
+++ b/lib/fpg/parse/packets/public_key_encrypted_session_key.rb
diff --git a/lib/fpg/parse/public_subkey.rb b/lib/fpg/parse/packets/public_subkey.rb
index 0b9e152..6b17fdf 100644
--- a/lib/fpg/parse/public_subkey.rb
+++ b/lib/fpg/parse/packets/public_subkey.rb
@@ -1,7 +1,6 @@
module FPG
module Parse
module PublicSubkeyParser
- include KeyMaterialParser
end
end
end
diff --git a/lib/fpg/parse/secret_key.rb b/lib/fpg/parse/packets/secret_key.rb
index 204fd2e..3937a0d 100644
--- a/lib/fpg/parse/secret_key.rb
+++ b/lib/fpg/parse/packets/secret_key.rb
@@ -1,7 +1,6 @@
module FPG
module Parse
module SecretKeyParser
- include KeyMaterialParser
end
end
end
diff --git a/lib/fpg/parse/secret_subkey.rb b/lib/fpg/parse/packets/secret_subkey.rb
index 5b4698c..dbf0c15 100644
--- a/lib/fpg/parse/secret_subkey.rb
+++ b/lib/fpg/parse/packets/secret_subkey.rb
@@ -1,7 +1,6 @@
module FPG
module Parse
module SecretSubkeyParser
- include KeyMaterialParser
end
end
end
diff --git a/lib/fpg/parse/signature.rb b/lib/fpg/parse/packets/signature.rb
index b0f043a..76937e2 100644
--- a/lib/fpg/parse/signature.rb
+++ b/lib/fpg/parse/packets/signature.rb
@@ -1,9 +1,6 @@
module FPG
module Parse
module SignatureParser
- def parse_content
- skip
- end
end
end
end
diff --git a/lib/fpg/parse/symmetric_encrypted_and_integrity_protected_data.rb b/lib/fpg/parse/packets/symmetric_encrypted_and_integrity_protected_data.rb
index ef12aab..ccf9dfe 100644
--- a/lib/fpg/parse/symmetric_encrypted_and_integrity_protected_data.rb
+++ b/lib/fpg/parse/packets/symmetric_encrypted_and_integrity_protected_data.rb
@@ -1,9 +1,6 @@
module FPG
module Parse
module SymmetricEncryptedAndIntegrityProtectedDataParser
- def parse_content
- skip
- end
end
end
end
diff --git a/lib/fpg/parse/user_id.rb b/lib/fpg/parse/packets/user_id.rb
index 9bda28d..c135f49 100644
--- a/lib/fpg/parse/user_id.rb
+++ b/lib/fpg/parse/packets/user_id.rb
@@ -1,9 +1,6 @@
module FPG
module Parse
module UserIdParser
- def parse_content
- skip
- end
end
end
end
diff --git a/lib/fpg/public_key_algos/algo.rb b/lib/fpg/public_key_algos/algo.rb
index b97b167..a4f6145 100644
--- a/lib/fpg/public_key_algos/algo.rb
+++ b/lib/fpg/public_key_algos/algo.rb
@@ -3,6 +3,11 @@ module FPG
class Algo
attr_accessor :key_material
include TaggedSubclasses
+ include Parseable
+ def parse_for(stream,packet)
+ @packet = packet
+ self << stream
+ end
end
end
end