Skip to content

Commit

Permalink
fix weird typing thing
Browse files Browse the repository at this point in the history
  • Loading branch information
JJTech0130 committed Jul 28, 2023
1 parent f6f2c30 commit 7d3fc92
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions ids/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ def dearmour(armoured: str) -> str:
)

from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric.types import (
PrivateKeyTypes,
PublicKeyTypes,
)
from cryptography.hazmat.primitives.asymmetric import ec, rsa
def parse_key(key: str):
# Check if it is a public or private key
if "PUBLIC" in key:
return serialization.load_pem_public_key(key.encode())
else:
return serialization.load_pem_private_key(key.encode(), None)

def serialize_key(key: PrivateKeyTypes | PublicKeyTypes):
if isinstance(key, PrivateKeyTypes):
def serialize_key(key):
if isinstance(key, ec.EllipticCurvePrivateKey) or isinstance(key, rsa.RSAPrivateKey):
return key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.TraditionalOpenSSL,
Expand Down

0 comments on commit 7d3fc92

Please sign in to comment.