11import binascii
22import math
33
4+ from datetime import datetime
5+
46NEW_TAG_FLAG = 0x40
57TAG_MASK = 0x3f
68PARTIAL_MASK = 0x1f
@@ -279,6 +281,36 @@ def lookup_signature_subtype(typ):
279281 return "reserved"
280282 return subpacket_types .get (typ , "unknown" )
281283
284+
285+ class PublicKeyPacket (Packet , AlgoLookup ):
286+ def __init__ (self , * args , ** kwargs ):
287+ self .pubkey_version = None
288+ self .creation_time = None
289+ self .datetime = None
290+ self .mod = None
291+ self .exp = None
292+ super (PublicKeyPacket , self ).__init__ (* args , ** kwargs )
293+
294+ def parse (self ):
295+ self .pubkey_version = self .data [0 ]
296+ offset = 1
297+ if self .pubkey_version == 4 :
298+ ts = _getint (self .data , offset , 4 )
299+ self .creation_time = ts
300+ self .datetime = datetime .fromtimestamp (ts )
301+ offset += 4
302+
303+ self .raw_pub_algorithm = self .data [offset ]
304+ self .pub_algorithm = self .lookup_pub_algorithm (self .data [offset ])
305+ offset += 1
306+
307+ #If RSA:
308+ if self .raw_pub_algorithm == 1 :
309+ self .mod , offset = _get_mpi (self .data , offset )
310+ self .exp , offset = _get_mpi (self .data , offset )
311+ self .exp_int = int (self .exp , 16 )
312+
313+
282314TAG_TYPES = {
283315 # (Name, PacketType) tuples
284316 0 : ("Reserved" , None ),
@@ -287,7 +319,7 @@ def lookup_signature_subtype(typ):
287319 3 : ("Symmetric-Key Encrypted Session Key Packet" , None ),
288320 4 : ("One-Pass Signature Packet" , None ),
289321 5 : ("Secret Key Packet" , None ),
290- 6 : ("Public Key Packet" , None ),
322+ 6 : ("Public Key Packet" , PublicKeyPacket ),
291323 7 : ("Secret Subkey Packet" , None ),
292324 8 : ("Compressed Data Packet" , None ),
293325 9 : ("Symmetrically Encrypted Data Packet" , None ),
0 commit comments