1
1
import binascii
2
2
import math
3
3
4
+ from datetime import datetime
5
+
4
6
NEW_TAG_FLAG = 0x40
5
7
TAG_MASK = 0x3f
6
8
PARTIAL_MASK = 0x1f
@@ -279,6 +281,36 @@ def lookup_signature_subtype(typ):
279
281
return "reserved"
280
282
return subpacket_types .get (typ , "unknown" )
281
283
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
+
282
314
TAG_TYPES = {
283
315
# (Name, PacketType) tuples
284
316
0 : ("Reserved" , None ),
@@ -287,7 +319,7 @@ def lookup_signature_subtype(typ):
287
319
3 : ("Symmetric-Key Encrypted Session Key Packet" , None ),
288
320
4 : ("One-Pass Signature Packet" , None ),
289
321
5 : ("Secret Key Packet" , None ),
290
- 6 : ("Public Key Packet" , None ),
322
+ 6 : ("Public Key Packet" , PublicKeyPacket ),
291
323
7 : ("Secret Subkey Packet" , None ),
292
324
8 : ("Compressed Data Packet" , None ),
293
325
9 : ("Symmetrically Encrypted Data Packet" , None ),
0 commit comments