26
26
from dataclasses import dataclass
27
27
from email .parser import BytesParser
28
28
from io import BytesIO
29
+ from pathlib import Path
29
30
from random import shuffle
30
31
from secrets import token_hex
31
32
from typing import Any , Awaitable , Callable , Dict , List , Optional , Tuple , Union
@@ -107,7 +108,7 @@ class RawCredentials(UserString):
107
108
pass
108
109
109
110
110
- Credentials = Union [str , Tuple [str , str ], RawCredentials ]
111
+ Credentials = Union [str , Tuple [str , str ], RawCredentials , Path ]
111
112
112
113
113
114
@dataclass
@@ -558,7 +559,8 @@ def sig_cb(nonce: str) -> bytes:
558
559
return sig
559
560
560
561
self ._signature_cb = sig_cb
561
- elif isinstance (creds , str ) or isinstance (creds , UserString ):
562
+ elif (isinstance (creds , str ) or isinstance (creds , UserString )
563
+ or isinstance (creds , Path )):
562
564
# Define the functions to be able to sign things using nkeys.
563
565
def user_cb () -> bytearray :
564
566
return self ._read_creds_user_jwt (creds )
@@ -579,7 +581,9 @@ def sig_cb(nonce: str) -> bytes:
579
581
580
582
self ._signature_cb = sig_cb
581
583
582
- def _read_creds_user_nkey (self , creds : str | UserString ) -> bytearray :
584
+ def _read_creds_user_nkey (
585
+ self , creds : str | UserString | Path
586
+ ) -> bytearray :
583
587
584
588
def get_user_seed (f ):
585
589
for line in f :
@@ -608,7 +612,7 @@ def get_user_seed(f):
608
612
with open (creds , "rb" , buffering = 0 ) as f :
609
613
return get_user_seed (f )
610
614
611
- def _read_creds_user_jwt (self , creds : str | RawCredentials ):
615
+ def _read_creds_user_jwt (self , creds : str | RawCredentials | Path ):
612
616
613
617
def get_user_jwt (f ):
614
618
user_jwt = None
0 commit comments