Skip to content

Commit e590365

Browse files
committed
style: fix typing impors, and function arguments
1 parent 869e102 commit e590365

File tree

1 file changed

+11
-12
lines changed
  • binding/python/py/synlink/crypto

1 file changed

+11
-12
lines changed

binding/python/py/synlink/crypto/io.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,24 @@
22
import os
33
import pathlib
44

5-
from typing import Union
5+
from typing import Union, Optional
66

77
from cryptography.hazmat.primitives import serialization
88
from cryptography.hazmat.primitives.asymmetric import (
99
ed25519 as ED25519,
1010
)
1111

1212
import synlink.crypto.ed25519 as ed25519
13-
from synlink.crypto.typing import PrivateKey, KeyPair
14-
15-
16-
17-
from typing import Optional
13+
from synlink.crypto.typing import KeyPair
1814

1915
HOME_DIR : str = pathlib.Path.home().__str__()
2016
SSH_DEFAULT_DIRECTORY = os.path.join(HOME_DIR, ".ssh")
2117

18+
__all__ = ["load_open_ssh_private_key"]
19+
2220
def load_ssh_private_key(
23-
ssh_dir: Union[str, os.PathLike] = SSH_DEFAULT_DIRECTORY,
24-
key_name: str = "id_ed25519",
25-
password : Optional[str] = None,
21+
file : Union[str, os.PathLike] = SSH_DEFAULT_DIRECTORY,
22+
password : Optional[Union[str, bytes]] = None,
2623
) -> KeyPair:
2724
"""Load private key from OpenSSL custom encoding, and reconstruct
2825
key pair.
@@ -39,12 +36,14 @@ def load_ssh_private_key(
3936
ValueError: If keys are malformed or incompatible
4037
NotImplemented: If other then ed25519
4138
Example:
42-
>>> keypair = load_ssh_keys(key_name="id_ed25519")
39+
>>> keypair = load_ssh_private_key(key_name="~/.ssh/synlink_ed25519")
4340
"""
44-
file = os.path.join(ssh_dir, key_name)
41+
if isinstance(password, str):
42+
password = password.encode()
43+
4544
with open(
4645
file,
47-
"rb",
46+
"r+b",
4847
) as reader:
4948
buffer = serialization.load_ssh_private_key(
5049
reader.read(-1),

0 commit comments

Comments
 (0)