diff options
author | Haibo Huang <hhb@google.com> | 2020-07-10 20:22:28 -0700 |
---|---|---|
committer | Haibo Huang <hhb@google.com> | 2020-07-29 00:52:07 +0000 |
commit | 248aba47a609d40ca1fc9fce4e6ca35935ca71d1 (patch) | |
tree | 51130a47b9f85ff001627c9fdabf69dfc7293a1b /rsa/randnum.py | |
parent | 70615f0491ec1dafe7302d863a49b6714a01166b (diff) | |
parent | cedefea7b455375e5a87200866809be59d718968 (diff) | |
download | rsa-248aba47a609d40ca1fc9fce4e6ca35935ca71d1.tar.gz |
Upgrade python/rsa to version-4.6
Exempt-From-Owner-Approval: upgrade lib
Change-Id: I0060c7ba0043698a3d7c12f36765641cfd0f8408
Diffstat (limited to 'rsa/randnum.py')
-rw-r--r-- | rsa/randnum.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/rsa/randnum.py b/rsa/randnum.py index 310acaa..a5bb850 100644 --- a/rsa/randnum.py +++ b/rsa/randnum.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# # Copyright 2011 Sybren A. Stüvel <sybren@stuvel.eu> # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,12 +17,12 @@ # Source inspired by code by Yesudeep Mangalapilly <yesudeep@gmail.com> import os +import struct from rsa import common, transform -from rsa._compat import byte -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 @@ -40,12 +38,12 @@ def read_random_bits(nbits): if rbits > 0: randomvalue = ord(os.urandom(1)) randomvalue >>= (8 - rbits) - randomdata = byte(randomvalue) + randomdata + randomdata = struct.pack("B", randomvalue) + randomdata return randomdata -def read_random_int(nbits): +def read_random_int(nbits: int) -> int: """Reads a random integer of approximately nbits bits. """ @@ -59,7 +57,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 +70,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 |