fix weird typing thing

This commit is contained in:
JJTech0130 2023-07-27 20:13:54 -04:00
parent f6f2c304af
commit 7d3fc921ec
No known key found for this signature in database
GPG key ID: 23C92EBCCF8F93D6

View file

@ -16,10 +16,7 @@ def dearmour(armoured: str) -> str:
) )
from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric.types import ( from cryptography.hazmat.primitives.asymmetric import ec, rsa
PrivateKeyTypes,
PublicKeyTypes,
)
def parse_key(key: str): def parse_key(key: str):
# Check if it is a public or private key # Check if it is a public or private key
if "PUBLIC" in key: if "PUBLIC" in key:
@ -27,8 +24,8 @@ def parse_key(key: str):
else: else:
return serialization.load_pem_private_key(key.encode(), None) return serialization.load_pem_private_key(key.encode(), None)
def serialize_key(key: PrivateKeyTypes | PublicKeyTypes): def serialize_key(key):
if isinstance(key, PrivateKeyTypes): if isinstance(key, ec.EllipticCurvePrivateKey) or isinstance(key, rsa.RSAPrivateKey):
return key.private_bytes( return key.private_bytes(
encoding=serialization.Encoding.PEM, encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.TraditionalOpenSSL, format=serialization.PrivateFormat.TraditionalOpenSSL,