@@ -94,7 +94,7 @@ def _save_pkcs1_der(self) -> bytes:
9494 """
9595
9696 @classmethod
97- def load_pkcs1 (cls , keyfile : bytes , format = 'PEM' ) -> 'AbstractKey' :
97+ def load_pkcs1 (cls , keyfile : bytes , format : str = 'PEM' ) -> 'AbstractKey' :
9898 """Loads a key in PKCS#1 DER or PEM format.
9999
100100 :param keyfile: contents of a DER- or PEM-encoded file that contains
@@ -128,7 +128,7 @@ def _assert_format_exists(file_format: str, methods: typing.Mapping[str, typing.
128128 raise ValueError ('Unsupported format: %r, try one of %s' % (file_format ,
129129 formats ))
130130
131- def save_pkcs1 (self , format = 'PEM' ) -> bytes :
131+ def save_pkcs1 (self , format : str = 'PEM' ) -> bytes :
132132 """Saves the key in PKCS#1 DER or PEM format.
133133
134134 :param format: the format to save; 'PEM' or 'DER'
@@ -203,7 +203,7 @@ class PublicKey(AbstractKey):
203203
204204 __slots__ = ('n' , 'e' )
205205
206- def __getitem__ (self , key ) :
206+ def __getitem__ (self , key : str ) -> int :
207207 return getattr (self , key )
208208
209209 def __repr__ (self ) -> str :
@@ -378,7 +378,7 @@ def __init__(self, n: int, e: int, d: int, p: int, q: int) -> None:
378378 self .exp2 = int (d % (q - 1 ))
379379 self .coef = rsa .common .inverse (q , p )
380380
381- def __getitem__ (self , key ) :
381+ def __getitem__ (self , key : str ) -> int :
382382 return getattr (self , key )
383383
384384 def __repr__ (self ) -> str :
@@ -388,7 +388,7 @@ def __getstate__(self) -> typing.Tuple[int, int, int, int, int, int, int, int]:
388388 """Returns the key as tuple for pickling."""
389389 return self .n , self .e , self .d , self .p , self .q , self .exp1 , self .exp2 , self .coef
390390
391- def __setstate__ (self , state : typing .Tuple [int , int , int , int , int , int , int , int ]):
391+ def __setstate__ (self , state : typing .Tuple [int , int , int , int , int , int , int , int ]) -> None :
392392 """Sets the key from tuple."""
393393 self .n , self .e , self .d , self .p , self .q , self .exp1 , self .exp2 , self .coef = state
394394
@@ -574,7 +574,9 @@ def _save_pkcs1_pem(self) -> bytes:
574574 return rsa .pem .save_pem (der , b'RSA PRIVATE KEY' )
575575
576576
577- def find_p_q (nbits : int , getprime_func = rsa .prime .getprime , accurate = True ) -> typing .Tuple [int , int ]:
577+ def find_p_q (nbits : int ,
578+ getprime_func : typing .Callable [[int ], int ] = rsa .prime .getprime ,
579+ accurate : bool = True ) -> typing .Tuple [int , int ]:
578580 """Returns a tuple of two different primes of nbits bits each.
579581
580582 The resulting p * q has exacty 2 * nbits bits, and the returned p and q
@@ -619,7 +621,7 @@ def find_p_q(nbits: int, getprime_func=rsa.prime.getprime, accurate=True) -> typ
619621 log .debug ('find_p_q(%i): Finding q' , nbits )
620622 q = getprime_func (qbits )
621623
622- def is_acceptable (p , q ) :
624+ def is_acceptable (p : int , q : int ) -> bool :
623625 """Returns True iff p and q are acceptable:
624626
625627 - p and q differ
@@ -697,8 +699,8 @@ def calculate_keys(p: int, q: int) -> typing.Tuple[int, int]:
697699
698700def gen_keys (nbits : int ,
699701 getprime_func : typing .Callable [[int ], int ],
700- accurate = True ,
701- exponent = DEFAULT_EXPONENT ) -> typing .Tuple [int , int , int , int ]:
702+ accurate : bool = True ,
703+ exponent : int = DEFAULT_EXPONENT ) -> typing .Tuple [int , int , int , int ]:
702704 """Generate RSA keys of nbits bits. Returns (p, q, e, d).
703705
704706 Note: this can take a long time, depending on the key size.
@@ -726,8 +728,10 @@ def gen_keys(nbits: int,
726728 return p , q , e , d
727729
728730
729- def newkeys (nbits : int , accurate = True , poolsize = 1 , exponent = DEFAULT_EXPONENT ) \
730- -> typing .Tuple [PublicKey , PrivateKey ]:
731+ def newkeys (nbits : int ,
732+ accurate : bool = True ,
733+ poolsize : int = 1 ,
734+ exponent : int = DEFAULT_EXPONENT ) -> typing .Tuple [PublicKey , PrivateKey ]:
731735 """Generates public and private keys, and returns them as (pub, priv).
732736
733737 The public key is also known as the 'encryption key', and is a
@@ -763,7 +767,7 @@ def newkeys(nbits: int, accurate=True, poolsize=1, exponent=DEFAULT_EXPONENT) \
763767 if poolsize > 1 :
764768 from rsa import parallel
765769
766- def getprime_func (nbits ) :
770+ def getprime_func (nbits : int ) -> int :
767771 return parallel .getprime (nbits , poolsize = poolsize )
768772 else :
769773 getprime_func = rsa .prime .getprime
0 commit comments