ó
Õ{PXc           @` sė  d  d l  m Z m Z m Z d  d l Z d  d l Z d  d l m Z d  d l m	 Z	 m
 Z
 m Z m Z m Z d  d l m Z d  d l m Z e j e j  d e f d     Y Z e j e j  d	 e f d
     Y Z e j e j  d e f d     Y Z e j e j  d e f d     Y Z e j e j  d e f d     Y Z d e f d     YZ e j e  d e f d     Y Z e j e  e j e  d e f d     Y  Z e j e  d e f d     Y Z d S(   i    (   t   absolute_importt   divisiont   print_functionN(   t   utils(   t   AlreadyFinalizedt   AlreadyUpdatedt   NotYetFinalizedt   UnsupportedAlgorithmt   _Reasons(   t   CipherBackend(   t   modest   CipherAlgorithmc           B` s,   e  Z e j d     Z e j d    Z RS(   c         C` s   d S(   sE   
        A string naming this mode (e.g. "AES", "Camellia").
        N(    (   t   self(    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyt   name   s    c         C` s   d S(   sW   
        The size of the key being used as an integer in bits (e.g. 128, 256).
        N(    (   R   (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyt   key_size   s    (   t   __name__t
   __module__t   abct   abstractpropertyR   R   (    (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR      s   t   BlockCipherAlgorithmc           B` s   e  Z e j d     Z RS(   c         C` s   d S(   sK   
        The size of a block as an integer in bits (e.g. 64, 128).
        N(    (   R   (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyt
   block_size%   s    (   R   R   R   R   R   (    (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR   #   s   t   CipherContextc           B` s,   e  Z e j d     Z e j d    Z RS(   c         C` s   d S(   sk   
        Processes the provided bytes through the cipher and returns the results
        as bytes.
        N(    (   R   t   data(    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyt   update.   s    c         C` s   d S(   sM   
        Returns the results of processing the final block as bytes.
        N(    (   R   (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyt   finalize5   s    (   R   R   R   t   abstractmethodR   R   (    (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR   ,   s   t   AEADCipherContextc           B` s   e  Z e j d     Z RS(   c         C` s   d S(   s3   
        Authenticates the provided bytes.
        N(    (   R   R   (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyt   authenticate_additional_data>   s    (   R   R   R   R   R   (    (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR   <   s   t   AEADEncryptionContextc           B` s   e  Z e j d     Z RS(   c         C` s   d S(   sb   
        Returns tag bytes. This is only available after encryption is
        finalized.
        N(    (   R   (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyt   tagG   s    (   R   R   R   R   R   (    (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR   E   s   t   Cipherc           B` s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C` s}   t  | t  s$ t d t j   n  t  | t  sB t d   n  | d  k	 r^ | j |  n  | |  _	 | |  _
 | |  _ d  S(   Ns0   Backend object does not implement CipherBackend.s&   Expected interface of CipherAlgorithm.(   t
   isinstanceR	   R   R   t   BACKEND_MISSING_INTERFACER   t	   TypeErrort   Nonet   validate_for_algorithmt	   algorithmt   modet   _backend(   R   R$   R%   t   backend(    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyt   __init__P   s    		c         C` sg   t  |  j t j  r9 |  j j d  k	 r9 t d   q9 n  |  j j |  j	 |  j  } |  j
 | d t S(   Ns0   Authentication tag must be None when encrypting.t   encrypt(   R   R%   R
   t   ModeWithAuthenticationTagR   R"   t
   ValueErrorR&   t   create_symmetric_encryption_ctxR$   t	   _wrap_ctxt   True(   R   t   ctx(    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyt	   encryptora   s    	c         C` sg   t  |  j t j  r9 |  j j d  k r9 t d   q9 n  |  j j |  j	 |  j  } |  j
 | d t S(   Ns4   Authentication tag must be provided when decrypting.R)   (   R   R%   R
   R*   R   R"   R+   R&   t   create_symmetric_decryption_ctxR$   R-   t   False(   R   R/   (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyt	   decryptorl   s    	c         C` s@   t  |  j t j  r2 | r% t |  St |  Sn
 t |  Sd  S(   N(   R   R%   R
   R*   t   _AEADEncryptionContextt   _AEADCipherContextt   _CipherContext(   R   R/   R)   (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR-   w   s
    
(   R   R   R(   R0   R3   R-   (    (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR   O   s   			R6   c           B` s#   e  Z d    Z d   Z d   Z RS(   c         C` s   | |  _  d  S(   N(   t   _ctx(   R   R/   (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR(      s    c         C` s.   |  j  d  k r t d   n  |  j  j |  S(   Ns   Context was already finalized.(   R7   R"   R   R   (   R   R   (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR      s    c         C` s:   |  j  d  k r t d   n  |  j  j   } d  |  _  | S(   Ns   Context was already finalized.(   R7   R"   R   R   (   R   R   (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR      s
    	(   R   R   R(   R   R   (    (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR6      s   		R5   c           B` s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C` s1   | |  _  d |  _ d |  _ d  |  _ t |  _ d  S(   Ni    (   R7   t   _bytes_processedt   _aad_bytes_processedR"   t   _tagR2   t   _updated(   R   R/   (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR(      s
    				c         C` s   |  j  d  k r t d   n  t |  _ |  j t |  7_ |  j |  j  j j k r t	 d j
 |  j  j j |  j  j j    n  |  j  j |  S(   Ns   Context was already finalized.s-   {0} has a maximum encrypted byte limit of {1}(   R7   R"   R   R.   R;   R8   t   lent   _modet   _MAX_ENCRYPTED_BYTESR+   t   formatR   R   (   R   R   (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR      s    	$c         C` sI   |  j  d  k r t d   n  |  j  j   } |  j  j |  _ d  |  _  | S(   Ns   Context was already finalized.(   R7   R"   R   R   R   R:   (   R   R   (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR   Ŧ   s    	c         C` sĪ   |  j  d  k r t d   n  |  j r6 t d   n  |  j t |  7_ |  j |  j  j j k r t	 d j
 |  j  j j |  j  j j    n  |  j  j |  d  S(   Ns   Context was already finalized.s'   Update has been called on this context.s'   {0} has a maximum AAD byte limit of {1}(   R7   R"   R   R;   R   R9   R<   R=   t   _MAX_AAD_BYTESR+   R?   R   R   (   R   R   (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR   ģ   s    	$(   R   R   R(   R   R   R   (    (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR5      s   			R4   c           B` s   e  Z e d     Z RS(   c         C` s%   |  j  d  k	 r t d   n  |  j S(   Ns4   You must finalize encryption before getting the tag.(   R7   R"   R   R:   (   R   (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR   Æ   s    (   R   R   t   propertyR   (    (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyR4   Ä   s   (   t
   __future__R    R   R   R   t   sixt   cryptographyR   t   cryptography.exceptionsR   R   R   R   R   t'   cryptography.hazmat.backends.interfacesR	   t&   cryptography.hazmat.primitives.ciphersR
   t   add_metaclasst   ABCMetat   objectR   R   R   R   R   R   t   register_interfaceR6   R5   R4   (    (    (    sO   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/base.pyt   <module>   s0   (	2/