If the :py:obj:`PGPKey` object is a private key, this method returns a corresponding public key object with all the trimmings. If it is already a public key, just return it.
(self)
| 1481 | |
| 1482 | @property |
| 1483 | def pubkey(self): |
| 1484 | """If the :py:obj:`PGPKey` object is a private key, this method returns a corresponding public key object with |
| 1485 | all the trimmings. If it is already a public key, just return it. |
| 1486 | """ |
| 1487 | if self.is_public: |
| 1488 | return self |
| 1489 | if self._sibling is None or isinstance(self._sibling, weakref.ref): |
| 1490 | # create a new key shell |
| 1491 | pub = PGPKey() |
| 1492 | pub.ascii_headers = self.ascii_headers.copy() |
| 1493 | |
| 1494 | # get the public half of the primary key |
| 1495 | pub._key = self._key.pubkey() |
| 1496 | |
| 1497 | # get the public half of each subkey |
| 1498 | for skid, subkey in self.subkeys.items(): |
| 1499 | pub |= subkey.pubkey |
| 1500 | |
| 1501 | # copy user ids and user attributes |
| 1502 | for uid in self._uids: |
| 1503 | pub |= copy.copy(uid) |
| 1504 | |
| 1505 | # copy signatures that weren't copied with uids |
| 1506 | for sig in self._signatures: |
| 1507 | if sig.parent is None: |
| 1508 | pub |= copy.copy(sig) |
| 1509 | |
| 1510 | # keep connect the two halves using a weak reference |
| 1511 | self._sibling = weakref.ref(pub) |
| 1512 | pub._sibling = weakref.ref(self) |
| 1513 | |
| 1514 | # copy parent |
| 1515 | if self.parent: |
| 1516 | pub._parent = weakref.ref(self.parent) |
| 1517 | |
| 1518 | return self._sibling() |
| 1519 | |
| 1520 | @pubkey.setter |
| 1521 | def pubkey(self, pubkey): |