summaryrefslogtreecommitdiff
path: root/rsa/prime.py
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2019-08-04 16:41:01 +0200
committerSybren A. Stüvel <sybren@stuvel.eu>2019-08-04 17:05:58 +0200
commitb6cebd53fcafd3088fc8361f6d3466166f75410b (patch)
treea1a3912fb9e91e249e433df0a9b79572f46340f3 /rsa/prime.py
parent6760eb76e665dc81863a82110164c4b3b38e7ee9 (diff)
downloadrsa-git-b6cebd53fcafd3088fc8361f6d3466166f75410b.tar.gz
Added type annotations + some fixes to get them correct
One functional change: `CryptoOperation.read_infile()` now reads bytes from `sys.stdin` instead of text. This is necessary to be consistent with the rest of the code, which all deals with bytes.
Diffstat (limited to 'rsa/prime.py')
-rw-r--r--rsa/prime.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/rsa/prime.py b/rsa/prime.py
index a45f659..dcd60dd 100644
--- a/rsa/prime.py
+++ b/rsa/prime.py
@@ -26,7 +26,7 @@ import rsa.randnum
__all__ = ['getprime', 'are_relatively_prime']
-def gcd(p, q):
+def gcd(p: int, q: int) -> int:
"""Returns the greatest common divisor of p and q
>>> gcd(48, 180)
@@ -38,7 +38,7 @@ def gcd(p, q):
return p
-def get_primality_testing_rounds(number):
+def get_primality_testing_rounds(number: int) -> int:
"""Returns minimum number of rounds for Miller-Rabing primality testing,
based on number bitsize.
@@ -64,7 +64,7 @@ def get_primality_testing_rounds(number):
return 10
-def miller_rabin_primality_testing(n, k):
+def miller_rabin_primality_testing(n: int, k: int) -> bool:
"""Calculates whether n is composite (which is always correct) or prime
(which theoretically is incorrect with error probability 4**-k), by
applying Miller-Rabin primality testing.
@@ -117,7 +117,7 @@ def miller_rabin_primality_testing(n, k):
return True
-def is_prime(number):
+def is_prime(number: int) -> bool:
"""Returns True if the number is prime, and False otherwise.
>>> is_prime(2)
@@ -143,7 +143,7 @@ def is_prime(number):
return miller_rabin_primality_testing(number, k + 1)
-def getprime(nbits):
+def getprime(nbits: int) -> int:
"""Returns a prime number that can be stored in 'nbits' bits.
>>> p = getprime(128)
@@ -171,7 +171,7 @@ def getprime(nbits):
# Retry if not prime
-def are_relatively_prime(a, b):
+def are_relatively_prime(a: int, b: int) -> bool:
"""Returns True if a and b are relatively prime, and False if they
are not.