/usr/lib/python2.6/site-packages/rsa
Edit: /usr/lib/python2.6/site-packages/rsa/transform.pyc (5856B)
Ñò
Ï€öVc
@@ sþ d Z d d k l Z y d d k Z e i ƒ Wn e j
o n Xd d k Z d d k l Z d d k l
Z
d d k l Z l
Z
l Z l Z l Z l Z d „ Z d d „ Z e d „ Z d d e d
„ Z e d j o d d k Z e i ƒ n d S( sN Data transformation functions.
From bytes to a number, number to bytes, etc.
i ( t absolute_importN( t pack( t common( t
is_integert bt bytet get_word_alignmentt ZERO_BYTEt
EMPTY_BYTEc C@ s t t i | ƒ d ƒ S( sî Converts a list of bytes or an 8-bit string to an integer.
When using unicode strings, encode it to some encoding like UTF8 first.
>>> (((128 * 256) + 64) * 256) + 15
8405007
>>> bytes2int(b'\x80@\x0f')
8405007
i ( t intt binasciit hexlify( t raw_bytes( ( s1 /usr/lib/python2.6/site-packages/rsa/transform.pyt bytes2int( s c C@ s/ t | ƒ p t d | i ƒ ‚ n | d j o t d | ƒ ‚ n | d j o d } t g } n t i | ƒ } g } | o8 | d j o+ | | j o t d | | f ƒ ‚ q¹ n x6 | d j o( | i d t | d @ƒ ƒ | d L} q¼ W| o | d j o | | t } n t
} | t
i | ƒ S( sM Converts a number to a string of bytes.
Usage::
>>> _int2bytes(123456789)
b'\x07[\xcd\x15'
>>> bytes2int(_int2bytes(123456789))
123456789
>>> _int2bytes(123456789, 6)
b'\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,
the returned block is not padded.
@throws OverflowError when block_size is given and the number takes up more
bytes than fit into the block.
s- You must pass an integer for 'number', not %si s# Negative numbers cannot be used: %ii s0 Needed %i bytes for number, but block size is %iiÿ i ( R t TypeErrort __class__t
ValueErrorR R t byte_sizet
OverflowErrort insertR R t join( t numbert
block_sizet needed_bytesR t padding( ( s1 /usr/lib/python2.6/site-packages/rsa/transform.pyt
_int2bytes7 s,
c C@ sA d } | d } x* | D]" } | | j o | d 7} q Pq W| S( s
Finds the number of prefixed byte occurrences in the haystack.
Useful when you want to deal with padding.
:param raw_bytes:
Raw bytes.
:param needle:
The byte to count. Default .
:returns:
The number of leading needle bytes.
i i ( ( R t needlet leadingt _bytet x( ( s1 /usr/lib/python2.6/site-packages/rsa/transform.pyt
bytes_leadingx s
c C@ s” | d j o t d | ƒ ‚ n | o | o t d ƒ ‚ n | d @t d ƒ } | } t | ƒ \ } } } } d | }
x3 | d j o% t |
| | @ƒ | } | | L} q~ Wt | ƒ } | d j o
t } n | | } t | ƒ } | oR | d j oE | o' | | j o t d | | f ƒ ‚ n | i | t ƒ } nN | oF | d j o9 | | }
|
o$ | |
} | i | | t ƒ } qn | S( s)
Convert an unsigned integer to bytes (base-256 representation)::
Does not preserve leading zeros if you don't specify a chunk size or
fill size.
.. NOTE:
You must not specify both fill_size and chunk_size. Only one
of them is allowed.
:param number:
Integer value
:param fill_size:
If the optional fill size is given the length of the resulting
byte string is expected to be the fill size and will be padded
with prefix zero bytes to satisfy that length.
:param chunk_size:
If optional chunk size is given and greater than zero, pad the front of
the byte string with binary zeros so that the length is a multiple of
``chunk_size``.
:param overflow:
``False`` (default). If this is ``True``, no ``OverflowError``
will be raised when the fill_size is shorter than the length
of the generated byte sequence. Instead the byte sequence will
be returned as is.
:returns:
Raw bytes (base-256 representation).
:raises:
``OverflowError`` when fill_size is given and the number takes up more
bytes than fit into the block. This requires the ``overflow``
argument to this function to be set to ``False`` otherwise, no
error will be raised.
i s&