@@ -94,7 +94,7 @@ def _save_pkcs1_der(self) -> bytes:
94
94
"""
95
95
96
96
@classmethod
97
- def load_pkcs1 (cls , keyfile : bytes , format = 'PEM' ) -> 'AbstractKey' :
97
+ def load_pkcs1 (cls , keyfile : bytes , format : str = 'PEM' ) -> 'AbstractKey' :
98
98
"""Loads a key in PKCS#1 DER or PEM format.
99
99
100
100
: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.
128
128
raise ValueError ('Unsupported format: %r, try one of %s' % (file_format ,
129
129
formats ))
130
130
131
- def save_pkcs1 (self , format = 'PEM' ) -> bytes :
131
+ def save_pkcs1 (self , format : str = 'PEM' ) -> bytes :
132
132
"""Saves the key in PKCS#1 DER or PEM format.
133
133
134
134
:param format: the format to save; 'PEM' or 'DER'
@@ -203,7 +203,7 @@ class PublicKey(AbstractKey):
203
203
204
204
__slots__ = ('n' , 'e' )
205
205
206
- def __getitem__ (self , key ) :
206
+ def __getitem__ (self , key : str ) -> int :
207
207
return getattr (self , key )
208
208
209
209
def __repr__ (self ) -> str :
@@ -378,7 +378,7 @@ def __init__(self, n: int, e: int, d: int, p: int, q: int) -> None:
378
378
self .exp2 = int (d % (q - 1 ))
379
379
self .coef = rsa .common .inverse (q , p )
380
380
381
- def __getitem__ (self , key ) :
381
+ def __getitem__ (self , key : str ) -> int :
382
382
return getattr (self , key )
383
383
384
384
def __repr__ (self ) -> str :
@@ -388,7 +388,7 @@ def __getstate__(self) -> typing.Tuple[int, int, int, int, int, int, int, int]:
388
388
"""Returns the key as tuple for pickling."""
389
389
return self .n , self .e , self .d , self .p , self .q , self .exp1 , self .exp2 , self .coef
390
390
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 :
392
392
"""Sets the key from tuple."""
393
393
self .n , self .e , self .d , self .p , self .q , self .exp1 , self .exp2 , self .coef = state
394
394
@@ -574,7 +574,9 @@ def _save_pkcs1_pem(self) -> bytes:
574
574
return rsa .pem .save_pem (der , b'RSA PRIVATE KEY' )
575
575
576
576
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 ]:
578
580
"""Returns a tuple of two different primes of nbits bits each.
579
581
580
582
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
619
621
log .debug ('find_p_q(%i): Finding q' , nbits )
620
622
q = getprime_func (qbits )
621
623
622
- def is_acceptable (p , q ) :
624
+ def is_acceptable (p : int , q : int ) -> bool :
623
625
"""Returns True iff p and q are acceptable:
624
626
625
627
- p and q differ
@@ -697,8 +699,8 @@ def calculate_keys(p: int, q: int) -> typing.Tuple[int, int]:
697
699
698
700
def gen_keys (nbits : int ,
699
701
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 ]:
702
704
"""Generate RSA keys of nbits bits. Returns (p, q, e, d).
703
705
704
706
Note: this can take a long time, depending on the key size.
@@ -726,8 +728,10 @@ def gen_keys(nbits: int,
726
728
return p , q , e , d
727
729
728
730
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 ]:
731
735
"""Generates public and private keys, and returns them as (pub, priv).
732
736
733
737
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) \
763
767
if poolsize > 1 :
764
768
from rsa import parallel
765
769
766
- def getprime_func (nbits ) :
770
+ def getprime_func (nbits : int ) -> int :
767
771
return parallel .getprime (nbits , poolsize = poolsize )
768
772
else :
769
773
getprime_func = rsa .prime .getprime
0 commit comments