in asfpy/crypto.py [0:0]
def __init__(self, pubkey: str = None, privkey: str = None):
"""Loads an existing ED25519 key or instantiates a new ED25519 key pair.
If pubkey is set, it loads it as a PEM-formatted key, same with privkey.
If no public or private key is passed on, a new keypair is created instead."""
if pubkey:
self._pubkey = cryptography.hazmat.primitives.serialization.load_pem_public_key(pubkey.encode("us-ascii"))
self._privkey = None
elif privkey:
self._privkey = cryptography.hazmat.primitives.serialization.load_pem_private_key(
privkey.encode("us-ascii"), password=None
)
else:
self._privkey = cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey.generate()
# Private keys can be used to generate as many public keys as needed, so we can create one for testing.
if self._privkey:
self._pubkey = self._privkey.public_key()