2626from dataclasses import dataclass
2727from email .parser import BytesParser
2828from io import BytesIO
29+ from pathlib import Path
2930from random import shuffle
3031from secrets import token_hex
3132from typing import Any , Awaitable , Callable , Dict , List , Optional , Tuple , Union
@@ -107,7 +108,7 @@ class RawCredentials(UserString):
107108 pass
108109
109110
110- Credentials = Union [str , Tuple [str , str ], RawCredentials ]
111+ Credentials = Union [str , Tuple [str , str ], RawCredentials , Path ]
111112
112113
113114@dataclass
@@ -558,7 +559,8 @@ def sig_cb(nonce: str) -> bytes:
558559 return sig
559560
560561 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 )):
562564 # Define the functions to be able to sign things using nkeys.
563565 def user_cb () -> bytearray :
564566 return self ._read_creds_user_jwt (creds )
@@ -579,7 +581,9 @@ def sig_cb(nonce: str) -> bytes:
579581
580582 self ._signature_cb = sig_cb
581583
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 :
583587
584588 def get_user_seed (f ):
585589 for line in f :
@@ -608,7 +612,7 @@ def get_user_seed(f):
608612 with open (creds , "rb" , buffering = 0 ) as f :
609613 return get_user_seed (f )
610614
611- def _read_creds_user_jwt (self , creds : str | RawCredentials ):
615+ def _read_creds_user_jwt (self , creds : str | RawCredentials | Path ):
612616
613617 def get_user_jwt (f ):
614618 user_jwt = None
0 commit comments