Make a KeyPair dataclass for passing around key pairs

This commit is contained in:
Alex Stokes
2019-08-13 20:23:07 -07:00
parent 329bd4eb0f
commit ad20d8cb00
5 changed files with 17 additions and 14 deletions

View File

@ -1,9 +1,7 @@
from typing import Tuple
import Crypto.PublicKey.RSA as RSA
from Crypto.PublicKey.RSA import RsaKey
from libp2p.crypto.keys import KeyType, PrivateKey, PublicKey
from libp2p.crypto.keys import KeyPair, KeyType, PrivateKey, PublicKey
class RSAPublicKey(PublicKey):
@ -42,13 +40,11 @@ class RSAPrivateKey(PrivateKey):
return RSAPublicKey(self.impl.publickey())
def create_new_key_pair(
bits: int = 2048, e: int = 65537
) -> Tuple[PrivateKey, PublicKey]:
def create_new_key_pair(bits: int = 2048, e: int = 65537) -> KeyPair:
"""
Returns a new RSA keypair with the requested key size (``bits``) and the given public
exponent ``e``. Sane defaults are provided for both values.
"""
private_key = RSAPrivateKey.new(bits, e)
public_key = private_key.get_public_key()
return private_key, public_key
return KeyPair(private_key, public_key)