ó
Q'—^c           @   s¥   d  Z  d „  e  j d ƒ Dƒ Z d d l Z d d l Z d Z d Z d e f d „  ƒ  YZ d	 „  Z	 d
 „  Z
 e d „ Z e d „ Z d „  Z e d „ Z d „  Z d S(   s   1.4.0c         c   s   |  ] } t  | ƒ Vq d  S(   N(   t   int(   t   .0t   v(    (    s/   /tmp/pip-unpacked-wheel-sZlFzC/pgcrypto/base.pys	   <genexpr>   s    t   .iÿÿÿÿNiÎ· iûL†t   BadChecksumErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s/   /tmp/pip-unpacked-wheel-sZlFzC/pgcrypto/base.pyR      s   c         C   s   t  |  t ƒ r |  St |  ƒ S(   N(   t
   isinstanceR    t   ord(   t   ch(    (    s/   /tmp/pip-unpacked-wheel-sZlFzC/pgcrypto/base.pyt   ord_safe   s    c         C   sk   t  } xZ |  D]R } | t | ƒ d >N} x5 t d ƒ D]' } | d K} | d @r4 | t N} q4 q4 Wq W| d @S(   Ni   i   i   i   iÿÿÿ (   t
   CRC24_INITR
   t   ranget
   CRC24_POLY(   t   datat   crct   bytet   _i(    (    s/   /tmp/pip-unpacked-wheel-sZlFzC/pgcrypto/base.pyt   crc24   s    

c         C   sy   d } t  j |  ƒ } t  j t j d t |  ƒ ƒ d ƒ } | i | rP d t n d d 6| j d ƒ d 6| j d ƒ d	 6S(
   sš   
    Returns a string in ASCII Armor format, for the given binary data. The
    output of this is compatiple with pgcrypto's armor/dearmor functions.
    sR   -----BEGIN PGP MESSAGE-----
%(headers)s%(body)s
=%(crc)s
-----END PGP MESSAGE-----s   >Li   s   Version: django-pgcrypto %s

s   
t   headerst   asciit   bodyR   (   t   base64t	   b64encodet   structt   packR   t   __version__t   decode(   R   t	   versionedt   templateR   R   (    (    s/   /tmp/pip-unpacked-wheel-sZlFzC/pgcrypto/base.pyt   armor!   s    %c         C   sA  |  j  ƒ  j d ƒ } g  } d } t } t } x– | D]Ž } | j d ƒ rR t } q4 | j d ƒ re Pq4 | r4 | rª | j d ƒ rš | d d !j d ƒ } Pq¿ | j | ƒ qÂ | j  ƒ  r¹ qÂ t } q4 q4 Wd j | ƒ } t	 j
 | j d ƒ ƒ }	 | r=| r=t j d	 d
 t	 j
 | ƒ ƒ d }
 |
 t |	 ƒ k r=t ƒ  ‚ q=n  |	 S(   s  
    Given a string in ASCII Armor format, returns the decoded binary data.
    If verify=True (the default), the CRC is decoded and checked against that
    of the decoded data, otherwise it is ignored. If the checksum does not
    match, a BadChecksumError exception is raised.
    s   
s
   -----BEGINs   -----ENDt   =i   i   R   t    s   >Ls    i    N(   t   stript   splitt   Nonet   Falset
   startswitht   Truet   encodet   appendt   joinR   t	   b64decodeR   t   unpackR   R   (   t   textt   verifyt   linest
   data_linest
   check_datat   startedt   in_bodyt   linet   b64_strR   R   (    (    s/   /tmp/pip-unpacked-wheel-sZlFzC/pgcrypto/base.pyt   dearmor1   s4    	#c         C   s…   t  |  ƒ } | d k r |  St |  | d ƒ } | | k r@ |  Sx: | d k r| t |  | d ƒ d | f k r| | d 8} qC W|  |  S(   s#  
    Takes the last character of the text, and if it is less than the block_size,
    assumes the text is padded, and removes any trailing zeros or bytes with the
    value of the pad character. See http://www.di-mgt.com.au/cryptopad.html for
    more information (methods 1, 3, and 4).
    i    i   (   t   lenR
   (   R,   t
   block_sizet   endt   padch(    (    s/   /tmp/pip-unpacked-wheel-sZlFzC/pgcrypto/base.pyt   unpad]   s    /c         C   sA   | t  |  ƒ | } | r  d n t | ƒ j d ƒ } |  | | S(   s  
    Given a text string and a block size, pads the text with bytes of the same value
    as the number of padding bytes. This is the recommended method, and the one used
    by pgcrypto. See http://www.di-mgt.com.au/cryptopad.html for more information.
    s    s   latin-1(   R6   t   chrR'   (   R,   R7   t   zerot   numR	   (    (    s/   /tmp/pip-unpacked-wheel-sZlFzC/pgcrypto/base.pyt   padp   s    !c         C   s{   t  |  ƒ d k r |  St  |  ƒ d k  r; t |  d d t ƒSt  |  ƒ d k  r` t |  d d t ƒSt |  d  d d t ƒSd S(   s§   
    AES keys must be either 16, 24, or 32 bytes long. If a key is provided that is not
    one of these lengths, pad it with zeroes (this is what pgcrypto does).
    i   i   i    R<   N(   i   i   i    (   R6   R>   R&   (   t   key(    (    s/   /tmp/pip-unpacked-wheel-sZlFzC/pgcrypto/base.pyt   aes_pad_key{   s    (   R   R"   t   __version_info__R   R   R   R   t	   ExceptionR   R
   R   R&   R   R5   R:   R$   R>   R@   (    (    (    s/   /tmp/pip-unpacked-wheel-sZlFzC/pgcrypto/base.pyt   <module>   s   		,	