summaryrefslogtreecommitdiff
path: root/rsa
diff options
context:
space:
mode:
authorYesudeep Mangalapilly <yesudeep@gmail.com>2011-08-24 16:31:54 +0530
committerYesudeep Mangalapilly <yesudeep@gmail.com>2011-08-24 16:31:54 +0530
commitf4283ae7b366233afa29a8c62a432480cd17b706 (patch)
tree5acf4e489798809c32cbf0c8c65cb1a27a864a59 /rsa
parent517e0e8084c003539d8b757152b1815ff37372bc (diff)
downloadrsa-f4283ae7b366233afa29a8c62a432480cd17b706.tar.gz
Adds back older doctests for _int2bytes for compliance.
Diffstat (limited to 'rsa')
-rw-r--r--rsa/transform.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/rsa/transform.py b/rsa/transform.py
index 2734788..7be272c 100644
--- a/rsa/transform.py
+++ b/rsa/transform.py
@@ -54,6 +54,23 @@ def bytes2int(raw_bytes):
def _int2bytes(number, block_size=None):
"""Converts a number to a string of bytes.
+ Usage::
+
+ >>> _int2bytes(123456789)
+ '\x07[\xcd\x15'
+ >>> bytes2int(_int2bytes(123456789))
+ 123456789
+
+ >>> _int2bytes(123456789, 6)
+ '\x00\x00\x07[\xcd\x15'
+ >>> bytes2int(_int2bytes(123456789, 128))
+ 123456789
+
+ >>> _int2bytes(123456789, 3)
+ Traceback (most recent call last):
+ ...
+ OverflowError: Needed 4 bytes for number, but block size is 3
+
@param number: the number to convert
@param block_size: the number of bytes to output. If the number encoded to
bytes is less than this, the block will be zero-padded. When not given,