MCPcopy Create free account
hub / github.com/SecurityInnovation/PGPy / parse

Method parse

pgpy/pgp.py:1269–1293  ·  view source on GitHub ↗
(self, packet)

Source from the content-addressed store, hash-verified

1267 return decmsg
1268
1269 def parse(self, packet):
1270 unarmored = self.ascii_unarmor(packet)
1271 data = unarmored['body']
1272
1273 if unarmored['magic'] is not None and unarmored['magic'] not in ['MESSAGE', 'SIGNATURE']:
1274 raise ValueError('Expected: MESSAGE. Got: {}'.format(str(unarmored['magic'])))
1275
1276 if unarmored['headers'] is not None:
1277 self.ascii_headers = unarmored['headers']
1278
1279 # cleartext signature
1280 if unarmored['magic'] == 'SIGNATURE':
1281 # the composition for this will be the 'cleartext' as a str,
1282 # followed by one or more signatures (each one loaded into a PGPSignature)
1283 self |= self.dash_unescape(unarmored['cleartext'])
1284 while len(data) > 0:
1285 pkt = Packet(data)
1286 if not isinstance(pkt, Signature): # pragma: no cover
1287 warnings.warn("Discarded unexpected packet: {:s}".format(pkt.__class__.__name__), stacklevel=2)
1288 continue
1289 self |= PGPSignature() | pkt
1290
1291 else:
1292 while len(data) > 0:
1293 self |= Packet(data)
1294
1295
1296class PGPKey(Armorable, ParentRef, PGPObject):

Callers 5

decryptMethod · 0.95
decryptMethod · 0.95
test_load_blobMethod · 0.95

Calls 4

dash_unescapeMethod · 0.95
PacketClass · 0.85
PGPSignatureClass · 0.85
ascii_unarmorMethod · 0.80

Tested by 3

test_load_blobMethod · 0.76