
®Aj¾z  ã               @   s·  d  Z  d d l m Z m Z m Z d d l m Z m Z m Z	 m
 Z d d l m Z m Z m Z d d l Z e j e ƒ Z d d l m Z d d l m Z m Z m Z m Z m Z m Z m Z m Z m  Z  m! Z! m" Z" m# Z# d d l$ m% Z% d	 d
 d d d d d d d d d d d d d d d d d d d g Z& e! d ƒ Z' e! d ƒ Z( e! d  ƒ Z) e! d! ƒ Z* e' e! d" ƒ Z+ e! d# ƒ Z, e! d$ ƒ Z- e! d% ƒ Z. e e d& ƒ ƒ Z/ d' Z0 d( Z1 d) Z2 e3 e e/ ƒ ƒ Z4 d d* d „ Z5 d+ d „  Z6 d, d „  Z7 d- Z8 d) Z9 d. Z: d/ d „  Z; d0 d „  Z< d1 d „  Z
 e5 d2 d3 d4 d5 i ƒ Z= e2 d6 Z> d7 d „  Z Gd8 d „  d e? ƒ Z@ Gd9 d „  d e@ ƒ ZA eA e) ƒ ZB eA e) d: d; ƒZC eA e* d: d; ƒZD d S)<zC
passlib.utils.binary - binary data encoding/decoding/manipulation
é    )Úabsolute_importÚdivisionÚprint_function)Ú	b64encodeÚ	b64decodeÚ	b32decodeÚ	b32encode)Ú
b2a_base64Ú
a2b_base64ÚErrorN)Úexc)ÚPY3Úbascii_to_strÚirangeÚimapÚiter_byte_charsÚjoin_byte_valuesÚjoin_byte_elemsÚ
nextgetterÚsuppress_causeÚuÚunicodeÚunicode_or_bytes_types)Úmemoized_propertyÚBASE64_CHARSÚPADDED_BASE64_CHARSÚ
AB64_CHARSÚHASH64_CHARSÚBCRYPT_CHARSÚ	HEX_CHARSÚLOWER_HEX_CHARSÚUPPER_HEX_CHARSÚALL_BYTE_VALUESÚcompile_byte_translationÚab64_encodeÚab64_decodeÚb64s_encodeÚb64s_decoder   r   ÚBase64EngineÚLazyBase64EngineÚh64Úh64bigÚbcrypt64z@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/z@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./z@./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzz@./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ú=Z0123456789abcdefABCDEFZ0123456789ABCDEFZ0123456789abcdefé   ó    s    ó   =c             C   s  | d k r t  d d … } n9 t | t ƒ r@ t | ƒ d k sF t ‚ t t | ƒ ƒ } xµ |  j ƒ  D]§ \ } } t | t ƒ rŒ t	 | ƒ } t | t
 ƒ r· d | k o² d k  n s½ t ‚ t | t ƒ rÛ | j d ƒ } t | t ƒ rü t | ƒ d k st ‚ | | | <qe Wt j | ƒ S)aÖ  
    return a 256-byte string for translating bytes using specified mapping.
    bytes not specified by mapping will be left alone.

    :param mapping:
        dict mapping input byte (str or int) -> output byte (str or int).

    :param source:
        optional existing byte translation string to use as base.
        (must be 255-length byte string).  defaults to identity mapping.

    :returns:
        255-length byte string for passing to bytes().translate.
    Néÿ   r   r.   Úasciié   )Ú_TRANSLATE_SOURCEÚ
isinstanceÚbytesÚlenÚAssertionErrorÚlistr   Úitemsr   ÚordÚintr   ÚencodeÚB_EMPTYÚjoin)ÚmappingÚsourceÚtargetÚkÚv© rE   ú../../passlib/utils/binary.pyr#   n   s    '1'c             C   s   t  |  ƒ j t ƒ S)zr
    encode using shortened base64 format which omits padding & whitespace.
    uses default ``+/`` altchars.
    )r	   ÚrstripÚ_BASE64_STRIP)ÚdatarE   rE   rF   r&   �   s    c             C   sò   t  |  t ƒ rI y |  j d ƒ }  Wn$ t k
 rH t t d ƒ ƒ ‚ Yn Xt |  ƒ d @} | d k rh n> | d k r� |  t 7}  n% | d k rš |  t 7}  n t d ƒ ‚ y t	 |  ƒ SWn7 t
 k
 rí } z t t | ƒ ƒ ‚ WYd d } ~ Xn Xd S)zq
    decode from shortened base64 format which omits padding & whitespace.
    uses default ``+/`` altchars.
    r2   z4string argument should contain only ASCII charactersé   r   é   zinvalid base64 inputN)r5   r   r=   ÚUnicodeEncodeErrorr   Ú
ValueErrorr7   Ú_BASE64_PAD2Ú_BASE64_PAD1r
   Ú_BinAsciiErrorÚ	TypeError)rI   ÚoffÚerrrE   rE   rF   r'   –   s"    s   =
s   ==c             C   s   t  |  ƒ j d d ƒ S)z®
    encode using shortened base64 format which omits padding & whitespace.
    uses custom ``./`` altchars.

    it is primarily used by Passlib's custom pbkdf2 hashes.
    ó   +ó   .)r&   Úreplace)rI   rE   rE   rF   r$   ¹   s    c             C   s_   t  |  t ƒ rI y |  j d ƒ }  Wn$ t k
 rH t t d ƒ ƒ ‚ Yn Xt |  j d d ƒ ƒ S)zã
    decode from shortened base64 format which omits padding & whitespace.
    uses custom ``./`` altchars, but supports decoding normal ``+/`` altchars as well.

    it is primarily used by Passlib's custom pbkdf2 hashes.
    r2   z4string argument should contain only ASCII charactersrU   rT   )r5   r   r=   rL   r   rM   r'   rV   )rI   rE   rE   rF   r%   Â   s    c             C   s   t  t |  ƒ j t ƒ ƒ S)zh
    wrapper around :func:`base64.b32encode` which strips padding,
    and returns a native string.
    )r   Ú
_b32encoderG   ÚB_EQUAL)rA   rE   rE   rF   r   Õ   s    Ú8ÚBÚ0ÚOé   c             C   se   t  |  t ƒ r |  j d ƒ }  |  j t ƒ }  t |  ƒ d @} | rX |  t d | … 7}  t |  d ƒ S)z„
    wrapper around :func:`base64.b32decode`
    which handles common mistyped chars.
    padding optional, ignored if present.
    r2   é   NT)r5   r   r=   Ú	translateÚ_b32_translater7   Ú_b32_decode_padÚ
_b32decode)rA   Z	remainderrE   rE   rF   r   å   s    c               @   s“  e  Z d  Z d Z d Z d Z d Z d Z d Z d Z	 d d d „ Z
 e d d „  ƒ Z d d	 „  Z d
 d „  Z d d „  Z d d „  Z d d „  Z d d „  Z d d „  Z e d d „  ƒ Z e d d „  ƒ Z d d „  Z d d „  Z d d „  Z d  d! „  Z d" d# „  Z d$ d% „  Z d& d' „  Z d( d) „  Z d* d+ „  Z d, d- „  Z  d. d/ „  Z! d0 d1 „  Z" d2 d3 „  Z# d4 d5 „  Z$ d6 d7 „  Z% d8 d9 „  Z& d S):r(   ac  Provides routines for encoding/decoding base64 data using
    arbitrary character mappings, selectable endianness, etc.

    :arg charmap:
        A string of 64 unique characters,
        which will be used to encode successive 6-bit chunks of data.
        A character's position within the string should correspond
        to its 6-bit value.

    :param big:
        Whether the encoding should be big-endian (default False).

    .. note::
        This class does not currently handle base64's padding characters
        in any way what so ever.

    Raw Bytes <-> Encoded Bytes
    ===========================
    The following methods convert between raw bytes,
    and strings encoded using the engine's specific base64 variant:

    .. automethod:: encode_bytes
    .. automethod:: decode_bytes
    .. automethod:: encode_transposed_bytes
    .. automethod:: decode_transposed_bytes

    ..
        .. automethod:: check_repair_unused
        .. automethod:: repair_unused

    Integers <-> Encoded Bytes
    ==========================
    The following methods allow encoding and decoding
    unsigned integers to and from the engine's specific base64 variant.
    Endianess is determined by the engine's ``big`` constructor keyword.

    .. automethod:: encode_int6
    .. automethod:: decode_int6

    .. automethod:: encode_int12
    .. automethod:: decode_int12

    .. automethod:: encode_int24
    .. automethod:: decode_int24

    .. automethod:: encode_int64
    .. automethod:: decode_int64

    Informational Attributes
    ========================
    .. attribute:: charmap

        unicode string containing list of characters used in encoding;
        position in string matches 6bit value of character.

    .. attribute:: bytemap

        bytes version of :attr:`charmap`

    .. attribute:: big

        boolean flag indicating this using big-endian encoding.
    NFc             C   s
  t  | t ƒ r! | j d ƒ } n! t  | t ƒ sB t j | d ƒ ‚ t | ƒ d k r` t d ƒ ‚ t t | ƒ ƒ d k r„ t d ƒ ‚ | |  _	 | j
 |  _ t d d „  t | ƒ Dƒ ƒ } | j
 |  _ | |  _ | rî |  j |  _ |  j |  _ n |  j |  _ |  j |  _ d  S)Nzlatin-1Úcharmapé@   z'charmap must be 64 characters in lengthz-charmap must not contain duplicate charactersc             s   s!   |  ] \ } } | | f Vq d  S)NrE   )Ú.0ÚidxÚvaluerE   rE   rF   ú	<genexpr>]  s    z(Base64Engine.__init__.<locals>.<genexpr>)r5   r   r=   r6   r   ÚExpectedStringErrorr7   rM   ÚsetÚbytemapÚ__getitem__Ú	_encode64ÚdictÚ	enumerateÚ	_decode64ÚbigÚ_encode_bytes_bigÚ_encode_bytesÚ_decode_bytes_bigÚ_decode_bytesÚ_encode_bytes_littleÚ_decode_bytes_little)Úselfrc   rq   ÚlookuprE   rE   rF   Ú__init__Q  s$    		zBase64Engine.__init__c             C   s   |  j  j d ƒ S)zcharmap as unicodezlatin-1)rk   Údecode)rx   rE   rE   rF   rc   s  s    zBase64Engine.charmapc             C   s¨   t  | t ƒ s( t d t | ƒ f ƒ ‚ t t | ƒ d ƒ \ } } t r^ t t | ƒ ƒ } n t d d „  | Dƒ ƒ } |  j	 | | | ƒ } t
 t |  j | ƒ ƒ } | S)z‹encode bytes to base64 string.

        :arg source: byte string to encode.
        :returns: byte string containing encoded data.
        zsource must be bytes, not %srJ   c             s   s   |  ] } t  | ƒ Vq d  S)N)r;   )re   ÚelemrE   rE   rF   rh   ‡  s    z,Base64Engine.encode_bytes.<locals>.<genexpr>)r5   r6   rQ   ÚtypeÚdivmodr7   r   r   Úiterrs   r   r   rm   )rx   rA   ÚchunksÚtailÚ
next_valueÚgenÚoutrE   rE   rF   Úencode_bytes{  s    zBase64Engine.encode_bytesc             c   sð   d } xq | | k  ry | ƒ  } | ƒ  } | ƒ  } | d @V| d @d >| d ?BV| d @d >| d ?BV| d ?V| d 7} q	 W| rì | ƒ  } | d k rª | d @V| d ?VnB | d k s¼ t  ‚ | ƒ  } | d @V| d @d >| d ?BV| d ?Vd	 S)
z>helper used by encode_bytes() to handle little-endian encodingr   é?   é   rK   é   rJ   é   r3   N)r8   )rx   r‚   r€   r�   rf   Úv1Úv2Úv3rE   rE   rF   rv   �  s(    									z!Base64Engine._encode_bytes_littlec             c   sø   d } xq | | k  ry | ƒ  } | ƒ  } | ƒ  } | d ?V| d @d >| d ?BV| d @d >| d ?BV| d @V| d 7} q	 W| rô | ƒ  } | d k r® | d ?V| d @d >VnF | d k sÀ t  ‚ | ƒ  } | d ?V| d @d >| d ?BV| d @d >Vd	 S)
z;helper used by encode_bytes() to handle big-endian encodingr   rK   rJ   r‰   r‡   rˆ   r†   r3   N)r8   )rx   r‚   r€   r�   rf   rŠ   r‹   rŒ   rE   rE   rF   rr   ·  s(    									zBase64Engine._encode_bytes_bigc             C   sÖ   t  | t ƒ s( t d t | ƒ f ƒ ‚ t t | ƒ d ƒ \ } } | d k r[ t d ƒ ‚ t t |  j	 | ƒ ƒ } y t
 |  j | | | ƒ ƒ SWn? t k
 rÑ } z t d | j d f ƒ ‚ WYd d } ~ Xn Xd S)z�decode bytes from base64 string.

        :arg source: byte string to decode.
        :returns: byte string containing decoded data.
        zsource must be bytes, not %sr‰   r3   z(input string length cannot be == 1 mod 4zinvalid character: %rr   N)r5   r6   rQ   r}   r~   r7   rM   r   r   rp   r   ru   ÚKeyErrorÚargs)rx   rA   r€   r�   r‚   rS   rE   rE   rF   Údecode_bytesâ  s    zBase64Engine.decode_bytesc       	      c   sÕ   d } xu | | k  r} | ƒ  } | ƒ  } | ƒ  } | ƒ  } | | d @d >BV| d ?| d @d >BV| d ?| d >BV| d 7} q	 W| rÑ | ƒ  } | ƒ  } | | d @d >BV| d k rÑ | ƒ  } | d ?| d @d >BVd S)	z>helper used by decode_bytes() to handle little-endian encodingr   rJ   rˆ   rK   r‡   r‰   r3   NrE   )	rx   r‚   r€   r�   rf   rŠ   r‹   rŒ   Úv4rE   rE   rF   rw   ø  s"    							z!Base64Engine._decode_bytes_littlec       	      c   sÕ   d } xu | | k  r} | ƒ  } | ƒ  } | ƒ  } | ƒ  } | d >| d ?BV| d @d >| d ?BV| d @d >| BV| d 7} q	 W| rÑ | ƒ  } | ƒ  } | d >| d ?BV| d k rÑ | ƒ  } | d @d >| d ?BVd S)	z;helper used by decode_bytes() to handle big-endian encodingr   rK   r‰   r‡   rJ   rˆ   r3   NrE   )	rx   r‚   r€   r�   rf   rŠ   r‹   rŒ   r�   rE   rE   rF   rt     s"    							zBase64Engine._decode_bytes_bigc                s[   t  ‡  f d d †  t |  j ƒ Dƒ ƒ } | j ‡  f d d †  t |  j ƒ Dƒ ƒ t | ƒ S)z2helper to generate set of valid last chars & bytesc             3   s%   |  ] \ } } | ˆ  @s | Vq d  S)NrE   )re   ÚiÚc)ÚbitsrE   rF   rh   G  s    z-Base64Engine.__make_padset.<locals>.<genexpr>c             3   s%   |  ] \ } } | ˆ  @s | Vq d  S)NrE   )re   r‘   r’   )r“   rE   rF   rh   H  s    )rj   ro   rk   Úupdaterc   Ú	frozenset)rx   r“   ZpsetrE   )r“   rF   Z__make_padsetE  s    ()zBase64Engine.__make_padsetc             C   s)   |  j  r d n d } | |  j | ƒ f S)zDmask to clear padding bits, and valid last bytes (for strings 2 % 4)r‡   rK   é<   )rq   Ú_Base64Engine__make_padset)rx   r“   rE   rE   rF   Ú	_padinfo2K  s    zBase64Engine._padinfo2c             C   s)   |  j  r d n d } | |  j | ƒ f S)zDmask to clear padding bits, and valid last bytes (for strings 3 % 4)rJ   r‰   é0   )rq   r—   )rx   r“   rE   rE   rF   Ú	_padinfo3R  s    zBase64Engine._padinfo3c             C   s3  t  | ƒ d @} | d k r. |  j \ } } n: | d k rL |  j \ } } n | s\ d | f St d ƒ ‚ | d	 } | | k rˆ d | f St | t ƒ rÒ |  j } | | j | ƒ | @} | | k st d ƒ ‚ nI |  j	 |  j
 | ƒ | @ƒ } | | k st d ƒ ‚ t rt | g ƒ } d | d d
 … | f S)a  helper to detect & clear invalid unused bits in last character.

        :arg source:
            encoded data (as ascii bytes or unicode).

        :returns:
            `(True, result)` if the string was repaired,
            `(False, source)` if the string was ok as-is.
        rJ   rK   Fzsource length must != 1 mod 4r3   z%failed to generate valid padding charTNéÿÿÿÿr›   )r7   r˜   rš   rM   r5   r   rc   Úindexr8   rm   rp   r   r6   )rx   rA   r�   ÚmaskZpadsetÚlastÚcmrE   rE   rF   Úcheck_repair_unusedY  s(    


	z Base64Engine.check_repair_unusedc             C   s   |  j  | ƒ d S)Nr3   )r    )rx   rA   rE   rE   rF   Úrepair_unused‚  s    zBase64Engine.repair_unusedc                sT   t  ˆ  t ƒ s( t d t ˆ  ƒ f ƒ ‚ t ‡  f d d †  | Dƒ ƒ } |  j | ƒ S)z>encode byte string, first transposing source using offset listzsource must be bytes, not %sc             3   s   |  ] } ˆ  | Vq d  S)NrE   )re   rR   )rA   rE   rF   rh   ˜  s    z7Base64Engine.encode_transposed_bytes.<locals>.<genexpr>)r5   r6   rQ   r}   r   r…   )rx   rA   ÚoffsetsÚtmprE   )rA   rF   Úencode_transposed_bytes”  s    z$Base64Engine.encode_transposed_bytesc             C   sV   |  j  | ƒ } d g t | ƒ } x' t | | ƒ D] \ } } | | | <q2 Wt | ƒ S)zGdecode byte string, then reverse transposition described by offset listN)r�   r7   Úzipr   )rx   rA   r¢   r£   ZbufrR   ÚcharrE   rE   rF   Údecode_transposed_bytes›  s
    z$Base64Engine.decode_transposed_bytesc       	      C   s  t  | t ƒ s( t d t | ƒ f ƒ ‚ |  j } | d } | | d } t | ƒ | k ro t d | f ƒ ‚ |  j } d } y; x4 | r� | n	 t | ƒ D] } | d >| | ƒ } qš WWn% t	 k
 rà t d | f ƒ ‚ Yn X| r| rú | | L} n | d | >d M} | S)a«  decode base64 string -> integer

        :arg source: base64 string to decode.
        :arg bits: number of bits in resulting integer.

        :raises ValueError:
            * if the string contains invalid base64 characters.
            * if the string is not long enough - it must be at least
              ``int(ceil(bits/6))`` in length.

        :returns:
            a integer in the range ``0 <= n < 2**bits``
        zsource must be bytes, not %srˆ   zsource must be %d charsr   zinvalid character in string: %rr3   )
r5   r6   rQ   r}   rq   r7   rM   rp   Úreversedr�   )	rx   rA   r“   rq   ÚpadÚcharsr{   r„   r’   rE   rE   rF   Ú_decode_int©  s&    		zBase64Engine._decode_intc             C   sŒ   t  | t ƒ s( t d t | ƒ f ƒ ‚ t | ƒ d k rF t d ƒ ‚ t rV | d } y |  j | ƒ SWn t k
 r‡ t d ƒ ‚ Yn Xd S)z(decode single character -> 6 bit integerzsource must be bytes, not %sr3   zsource must be exactly 1 byter   zinvalid characterN)	r5   r6   rQ   r}   r7   rM   r   rp   r�   )rx   rA   rE   rE   rF   Údecode_int6Ñ  s    
zBase64Engine.decode_int6c             C   sÁ   t  | t ƒ s( t d t | ƒ f ƒ ‚ t | ƒ d k rF t d ƒ ‚ |  j } yM |  j r{ | | d ƒ | | d ƒ d >S| | d ƒ | | d ƒ d >SWn t k
 r¼ t d ƒ ‚ Yn Xd S)	z'decodes 2 char string -> 12-bit integerzsource must be bytes, not %srK   zsource must be exactly 2 bytesr3   r   rˆ   zinvalid characterN)	r5   r6   rQ   r}   r7   rM   rp   rq   r�   )rx   rA   r{   rE   rE   rF   Údecode_int12ß  s    		 $zBase64Engine.decode_int12c             C   s	  t  | t ƒ s( t d t | ƒ f ƒ ‚ t | ƒ d k rF t d ƒ ‚ |  j } y• |  j rŸ | | d ƒ | | d ƒ d >| | d ƒ d >| | d	 ƒ d
 >S| | d	 ƒ | | d ƒ d >| | d ƒ d >| | d ƒ d
 >SWn t k
 rt d ƒ ‚ Yn Xd S)z'decodes 4 char string -> 24-bit integerzsource must be bytes, not %sr‰   zsource must be exactly 4 bytesrJ   rK   rˆ   r3   é   r   é   zinvalid characterN)	r5   r6   rQ   r}   r7   rM   rp   rq   r�   )rx   rA   r{   rE   rE   rF   Údecode_int24î  s    		DHzBase64Engine.decode_int24c             C   s   |  j  | d ƒ S)z&decode 5 char string -> 30 bit integeré   )r«   )rx   rA   rE   rE   rF   Údecode_int30ÿ  s    zBase64Engine.decode_int30c             C   s   |  j  | d ƒ S)z±decode 11 char base64 string -> 64-bit integer

        this format is used primarily by des-crypt & variants to encode
        the DES output value used as a checksum.
        rd   )r«   )rx   rA   rE   rE   rF   Údecode_int64  s    zBase64Engine.decode_int64c                s”   ˆ  d k s t  d ƒ ‚ | d } | | 7} |  j rY t | d d d ƒ } ˆ  | K‰  n t d | d ƒ } t t |  j ‡  f d d †  | Dƒ ƒ ƒ S)zÕencode integer into base64 format

        :arg value: non-negative integer to encode
        :arg bits: number of bits to encode

        :returns:
            a string of length ``int(ceil(bits/6.0))``.
        r   zcaller did not sanitize inputrˆ   c             3   s   |  ] } ˆ  | ?d  @Vq d S)r†   NrE   )re   rR   )rg   rE   rF   rh   "  s    z+Base64Engine._encode_int.<locals>.<genexpr>iúÿÿÿiúÿÿÿ)r8   rq   r   r   r   rm   )rx   rg   r“   r©   ÚitrrE   )rg   rF   Ú_encode_int  s    	
	zBase64Engine._encode_intc             C   sP   | d k  s | d k r$ t  d ƒ ‚ t r? |  j | | d … S|  j | ƒ Sd S)z0encodes 6-bit integer -> single hash64 characterr   r†   zvalue out of ranger3   N)rM   r   rk   rm   )rx   rg   rE   rE   rF   Úencode_int6(  s
    zBase64Engine.encode_int6c             C   sg   | d k  s | d k r$ t  d ƒ ‚ | d @| d ?d @g } |  j rQ t | ƒ } t t |  j | ƒ ƒ S)z'encodes 12-bit integer -> 2 char stringr   iÿ  zvalue out of ranger†   rˆ   )rM   rq   r¨   r   r   rm   )rx   rg   ÚrawrE   rE   rF   Úencode_int121  s    	zBase64Engine.encode_int12c             C   s}   | d k  s | d k r$ t  d ƒ ‚ | d @| d ?d @| d ?d @| d ?d @g } |  j rg t | ƒ } t t |  j | ƒ ƒ S)z'encodes 24-bit integer -> 4 char stringr   iÿÿÿ zvalue out of ranger†   rˆ   r®   r¯   )rM   rq   r¨   r   r   rm   )rx   rg   r·   rE   rE   rF   Úencode_int24:  s    	zBase64Engine.encode_int24c             C   s4   | d k  s | d k r$ t  d ƒ ‚ |  j | d ƒ S)z&decode 5 char string -> 30 bit integerr   iÿÿÿ?zvalue out of ranger±   )rM   rµ   )rx   rg   rE   rE   rF   Úencode_int30D  s    zBase64Engine.encode_int30c             C   s4   | d k  s | d k r$ t  d ƒ ‚ |  j | d ƒ S)z±encode 64-bit integer -> 11 char hash64 string

        this format is used primarily by des-crypt & variants to encode
        the DES output value used as a checksum.
        r   l   ÿÿÿÿ zvalue out of rangerd   )rM   rµ   )rx   rg   rE   rE   rF   Úencode_int64J  s    zBase64Engine.encode_int64)'Ú__name__Ú
__module__Ú__qualname__Ú__doc__rk   rq   rm   rp   rs   ru   rz   Úpropertyrc   r…   rv   rr   r�   rw   rt   r—   r   r˜   rš   r    r¡   r¤   r§   r«   r¬   r­   r°   r²   r³   rµ   r¶   r¸   r¹   rº   r»   rE   rE   rE   rF   r(   ý   sD   ?"'+#*)(		
c                   sF   e  Z d  Z d Z d Z d d „  Z ‡  f d d †  Z d d „  Z ‡  S)	r)   z<Base64Engine which delays initialization until it's accessedNc             O   s   | | f |  _  d  S)N)Ú
_lazy_opts)rx   rŽ   ÚkwdsrE   rE   rF   rz   \  s    zLazyBase64Engine.__init__c                s;   |  j  \ } } t t |  ƒ j | | Ž  |  `  t |  _ d  S)N)rÁ   Úsuperr)   rz   r(   Ú	__class__)rx   rŽ   rÂ   )rÄ   rE   rF   Ú
_lazy_init_  s    zLazyBase64Engine._lazy_initc             C   s)   | j  d ƒ s |  j ƒ  t j |  | ƒ S)NÚ_)Ú
startswithrÅ   ÚobjectÚ__getattribute__)rx   ÚattrrE   rE   rF   rÉ   e  s    
z!LazyBase64Engine.__getattribute__)r¼   r½   r¾   r¿   rÁ   rz   rÅ   rÉ   rE   rE   )rÄ   rF   r)   X  s
   rq   T)Er¿   Z
__future__r   r   r   Úbase64r   r   r   rb   r   rW   Úbinasciir	   r
   r   rP   ÚloggingÚ	getLoggerr¼   ÚlogZpasslibr   Úpasslib.utils.compatr   r   r   r   r   r   r   r   r   r   r   r   Úpasslib.utils.decorr   Ú__all__r   r   r   r   r   r   r!   r    r"   r>   ZB_NULLrX   r9   r4   r#   r&   r'   rH   rO   rN   r$   r%   r`   ra   rÈ   r(   r)   r*   r+   r,   rE   rE   rE   rF   Ú<module>   sn   "R		!	
ÿ ÿ ]