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

Method add_subkey

pgpy/pgp.py:1866–1899  ·  view source on GitHub ↗

Add a key as a subkey to this key. :param key: A private :py:obj:`~pgpy.PGPKey` that does not have any subkeys of its own :keyword usage: A ``set`` of key usage flags, as :py:obj:`~constants.KeyFlags` for the subkey to be added. :type usage: ``set`` Other v

(self, key, **prefs)

Source from the content-addressed store, hash-verified

1864 self._uids.remove(u)
1865
1866 def add_subkey(self, key, **prefs):
1867 """
1868 Add a key as a subkey to this key.
1869
1870 :param key: A private :py:obj:`~pgpy.PGPKey` that does not have any subkeys of its own
1871 :keyword usage: A ``set`` of key usage flags, as :py:obj:`~constants.KeyFlags` for the subkey to be added.
1872 :type usage: ``set``
1873
1874 Other valid optional keyword arguments are identical to those of self-signatures for :py:meth:`PGPKey.certify`
1875 """
1876 if self.is_public:
1877 raise PGPError("Cannot add a subkey to a public key. Add the subkey to the private component first!")
1878
1879 if key.is_public:
1880 raise PGPError("Cannot add a public key as a subkey to this key")
1881
1882 if key.is_primary:
1883 if len(key._children) > 0:
1884 raise PGPError("Cannot add a key that already has subkeys as a subkey!")
1885
1886 # convert key into a subkey
1887 npk = PrivSubKeyV4()
1888 npk.pkalg = key._key.pkalg
1889 npk.created = key._key.created
1890 npk.keymaterial = key._key.keymaterial
1891 key._key = npk
1892 key._key.update_hlen()
1893
1894 self._children[key.fingerprint.keyid] = key
1895 key._parent = self
1896
1897 ##TODO: skip this step if the key already has a subkey binding signature
1898 bsig = self.bind(key, **prefs)
1899 key |= bsig
1900
1901 def _get_key_flags(self, user=None):
1902 if self.is_primary:

Callers 6

temp_keyFunction · 0.80
test_add_subkeyMethod · 0.80
abeFunction · 0.80

Calls 4

bindMethod · 0.95
PGPErrorClass · 0.85
PrivSubKeyV4Class · 0.85
update_hlenMethod · 0.45

Tested by 6

temp_keyFunction · 0.64
test_add_subkeyMethod · 0.64
abeFunction · 0.64