summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoro <o@immerda.ch>2011-06-27 17:32:16 +0200
committero <o@immerda.ch>2011-06-27 17:32:16 +0200
commit82d4d4e18b6688c8b2c986ec38e18e9602edf60e (patch)
tree4b4609fbb7eb69ec2577923e46a427e3368ee76d
parent9a0e273f172b886602a24ac05ea993d2daee4f96 (diff)
ok now we parse rsa public keys :)
-rw-r--r--lib/fpg/packets/_packet.rb (renamed from lib/fpg/packets/packet.rb)1
-rw-r--r--lib/fpg/packets/key_material.rb7
-rw-r--r--lib/fpg/packets/public_key.rb3
-rw-r--r--lib/fpg/packets/secret_key.rb3
-rw-r--r--lib/fpg/parse/algos/rsa.rb8
-rw-r--r--lib/fpg/parse/packets/key_material.rb10
-rw-r--r--lib/fpg/parse/packets/public_key.rb13
-rw-r--r--lib/fpg/public_key_algos/algo.rb3
8 files changed, 35 insertions, 13 deletions
diff --git a/lib/fpg/packets/packet.rb b/lib/fpg/packets/_packet.rb
index 1f3d542..f04ab78 100644
--- a/lib/fpg/packets/packet.rb
+++ b/lib/fpg/packets/_packet.rb
@@ -3,6 +3,7 @@ module FPG
class Packet
include TaggedSubclasses
include Parseable
+
attr_accessor :byte_size
end
end
diff --git a/lib/fpg/packets/key_material.rb b/lib/fpg/packets/key_material.rb
new file mode 100644
index 0000000..90b5e58
--- /dev/null
+++ b/lib/fpg/packets/key_material.rb
@@ -0,0 +1,7 @@
+module FPG
+ module Packets
+ class KeyMaterial < Packet
+ attr_accessor :created,:algo,:key_material
+ end
+ end
+end
diff --git a/lib/fpg/packets/public_key.rb b/lib/fpg/packets/public_key.rb
index be77437..5f81a9b 100644
--- a/lib/fpg/packets/public_key.rb
+++ b/lib/fpg/packets/public_key.rb
@@ -1,7 +1,6 @@
module FPG
module Packets
- class PublicKey < Packet
- attr_accessor :created,:algo,:key_material
+ class PublicKey < KeyMaterial
def self.tag
6
end
diff --git a/lib/fpg/packets/secret_key.rb b/lib/fpg/packets/secret_key.rb
index 00b6da7..b809185 100644
--- a/lib/fpg/packets/secret_key.rb
+++ b/lib/fpg/packets/secret_key.rb
@@ -1,7 +1,6 @@
module FPG
module Packets
- attr_accessor :created,:algo,:key_material
- class SecretKey < Packet
+ class SecretKey < KeyMaterial
def self.tag
5
end
diff --git a/lib/fpg/parse/algos/rsa.rb b/lib/fpg/parse/algos/rsa.rb
new file mode 100644
index 0000000..23ba5fa
--- /dev/null
+++ b/lib/fpg/parse/algos/rsa.rb
@@ -0,0 +1,8 @@
+module FPG
+ module RsaParser
+ def parse(stream)
+ #just one value: m**e mod n
+ @packet.key_material = stream.read( @size )
+ end
+ end
+end
diff --git a/lib/fpg/parse/packets/key_material.rb b/lib/fpg/parse/packets/key_material.rb
index ab1105d..78c53b5 100644
--- a/lib/fpg/parse/packets/key_material.rb
+++ b/lib/fpg/parse/packets/key_material.rb
@@ -1,20 +1,14 @@
module FPG
module Parse
module KeyMaterialParser
- def parse_content_
- parse_version
- parse_creation
- parse_algo
- parse_key_material
- end
- def parse_creation
+ def parse_creation
@created= stream.read(4).unpack("N1")
end
def parse_algo
@algo= PublicKeyAlgos::Algo.with_tag(stream.getbyte)
end
def parse_key_material
- algo.parse_for(stream,self)
+ algo.parse_for(stream,self,@byte_size-6)
end
def parse_version
raise "only key material packets with version 4 are supported" unless @stream.getbyte == 4
diff --git a/lib/fpg/parse/packets/public_key.rb b/lib/fpg/parse/packets/public_key.rb
new file mode 100644
index 0000000..b156529
--- /dev/null
+++ b/lib/fpg/parse/packets/public_key.rb
@@ -0,0 +1,13 @@
+module FPG
+ module Parse
+ module PublicKeyParser
+ def parse_content
+ parse_version
+ parse_creation
+ parse_algo
+ parse_key_material
+ end
+ end
+ end
+end
+
diff --git a/lib/fpg/public_key_algos/algo.rb b/lib/fpg/public_key_algos/algo.rb
index a4f6145..9d5e52e 100644
--- a/lib/fpg/public_key_algos/algo.rb
+++ b/lib/fpg/public_key_algos/algo.rb
@@ -4,8 +4,9 @@ module FPG
attr_accessor :key_material
include TaggedSubclasses
include Parseable
- def parse_for(stream,packet)
+ def parse_for(stream,packet,size)
@packet = packet
+ @size = size
self << stream
end
end