summaryrefslogtreecommitdiff
path: root/rsa/randnum.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/randnum.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/randnum.py')
-rw-r--r--rsa/randnum.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/rsa/randnum.py b/rsa/randnum.py
index 1f0a4e5..e9bfc87 100644
--- a/rsa/randnum.py
+++ b/rsa/randnum.py
@@ -24,7 +24,7 @@ import struct
from rsa import common, transform
-def read_random_bits(nbits):
+def read_random_bits(nbits: int) -> bytes:
"""Reads 'nbits' random bits.
If nbits isn't a whole number of bytes, an extra byte will be appended with
@@ -45,7 +45,7 @@ def read_random_bits(nbits):
return randomdata
-def read_random_int(nbits):
+def read_random_int(nbits: int) -> int:
"""Reads a random integer of approximately nbits bits.
"""
@@ -59,7 +59,7 @@ def read_random_int(nbits):
return value
-def read_random_odd_int(nbits):
+def read_random_odd_int(nbits: int) -> int:
"""Reads a random odd integer of approximately nbits bits.
>>> read_random_odd_int(512) & 1
@@ -72,7 +72,7 @@ def read_random_odd_int(nbits):
return value | 1
-def randint(maxvalue):
+def randint(maxvalue: int) -> int:
"""Returns a random integer x with 1 <= x <= maxvalue
May take a very long time in specific situations. If maxvalue needs N bits