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

Method new

pgpy/pgp.py:1588–1612  ·  view source on GitHub ↗

Generate a new PGP key :param key_algorithm: Key algorithm to use. :type key_algorithm: :py:obj:`~constants.PubKeyAlgorithm` :param key_size: Key size in bits, unless `key_algorithm` is :py:obj:`~constants.PubKeyAlgorithm.ECDSA` or :py:obj:`~constants

(cls, key_algorithm, key_size, created=None)

Source from the content-addressed store, hash-verified

1586
1587 @classmethod
1588 def new(cls, key_algorithm, key_size, created=None):
1589 """
1590 Generate a new PGP key
1591
1592 :param key_algorithm: Key algorithm to use.
1593 :type key_algorithm: :py:obj:`~constants.PubKeyAlgorithm`
1594 :param key_size: Key size in bits, unless `key_algorithm` is :py:obj:`~constants.PubKeyAlgorithm.ECDSA` or
1595 :py:obj:`~constants.PubKeyAlgorithm.ECDH`, in which case it should be the Curve OID to use.
1596 :type key_size: ``int`` or :py:obj:`~constants.EllipticCurveOID`
1597
1598 :param created: When was the key created? (``None`` or unset means now)
1599 :type created: :py:obj:`~datetime.datetime` or ``None``
1600 :return: A newly generated :py:obj:`PGPKey`
1601 """
1602 # new private key shell first
1603 key = PGPKey()
1604
1605 if key_algorithm in {PubKeyAlgorithm.RSAEncrypt, PubKeyAlgorithm.RSASign}: # pragma: no cover
1606 warnings.warn('{:s} is deprecated - generating key using RSAEncryptOrSign'.format(key_algorithm.name))
1607 key_algorithm = PubKeyAlgorithm.RSAEncryptOrSign
1608
1609 # generate some key data to match key_algorithm and key_size
1610 key._key = PrivKeyV4.new(key_algorithm, key_size, created=created)
1611
1612 return key
1613
1614 def __init__(self):
1615 """

Callers

nothing calls this directly

Calls 2

PGPKeyClass · 0.85
newMethod · 0.45

Tested by

no test coverage detected