summaryrefslogtreecommitdiff
path: root/rsa/common.py
diff options
context:
space:
mode:
authorYesudeep Mangalapilly <yesudeep@gmail.com>2011-08-17 00:19:39 +0530
committerYesudeep Mangalapilly <yesudeep@gmail.com>2011-08-17 00:19:39 +0530
commita5a43a5545c80bbc9d3df83011d0da41316d4afc (patch)
tree41392d0fcb91dcfafd2694a4300d45faecb38b7a /rsa/common.py
parent9358b1cb945ed4aa340785e766a42459fb161c03 (diff)
downloadrsa-git-a5a43a5545c80bbc9d3df83011d0da41316d4afc.tar.gz
Fixes a silly error.
Diffstat (limited to 'rsa/common.py')
-rw-r--r--rsa/common.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/rsa/common.py b/rsa/common.py
index 7801b59..eb95e82 100644
--- a/rsa/common.py
+++ b/rsa/common.py
@@ -22,6 +22,9 @@ def bit_size(num):
Number of bits needed to represent a integer excluding any prefix
0 bits.
+ As per definition from http://wiki.python.org/moin/BitManipulation and
+ to match the behavior of the Python 3 API.
+
:param num:
Integer value. If num is 0, returns 0. Only the absolute value of the
number is considered. Therefore, signed integers will be abs(num)
@@ -67,16 +70,13 @@ def _bit_size(number):
def byte_size(number):
- """Returns the number of bytes required to hold a specific long number.
+ """
+ Returns the number of bytes required to hold a specific long number.
The number of bytes is rounded up.
"""
- if number == 0:
- return 0
- # Does not perform floating-point division and uses built-in divmod
- # operator.
quanta, mod = divmod(bit_size(number), 8)
- if mod:
+ if mod or number == 0:
quanta += 1
return quanta
#return int(math.ceil(bit_size(number) / 8.0))