mirror of
https://github.com/Sneed-Group/pypush-plus-plus
synced 2024-12-24 03:42:43 -06:00
fix weird typing thing
This commit is contained in:
parent
f6f2c304af
commit
7d3fc921ec
1 changed files with 3 additions and 6 deletions
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue