σ
/<υ\c           @` 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 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  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(    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyt   name   t    c         C` s   d S(   sW   
        The size of the key being used as an integer in bits (e.g. 128, 256).
        N(    (   R   (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyt   key_size   R   (   t   __name__t
   __module__t   abct   abstractpropertyR   R   (    (    (    sJ   lib/python2.7/site-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   (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyt
   block_size%   R   (   R   R   R   R   R   (    (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyR   #   s   t   CipherContextc           B` s>   e  Z e j d     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(    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyt   update.   R   c         C` s   d S(   s   
        Processes the provided bytes and writes the resulting data into the
        provided buffer. Returns the number of bytes written.
        N(    (   R   R   t   buf(    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyt   update_into5   R   c         C` s   d S(   sM   
        Returns the results of processing the final block as bytes.
        N(    (   R   (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyt   finalize<   R   (   R   R   R   t   abstractmethodR   R   R   (    (    (    sJ   lib/python2.7/site-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   (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyt   authenticate_additional_dataE   R   (   R   R   R   R   R   (    (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyR   C   s   t   AEADDecryptionContextc           B` s   e  Z e j d     Z RS(   c         C` s   d S(   s   
        Returns the results of processing the final block as bytes and allows
        delayed passing of the authentication tag.
        N(    (   R   t   tag(    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyt   finalize_with_tagN   R   (   R   R   R   R   R!   (    (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyR   L   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   (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyR    X   R   (   R   R   R   R   R    (    (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyR"   V   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(    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyt   __init__a   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(    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyt	   encryptorr   s    	c         C` s.   |  j  j |  j |  j  } |  j | d t S(   NR.   (   R+   t   create_symmetric_decryption_ctxR)   R*   R2   t   False(   R   R4   (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyt	   decryptor}   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   R4   R.   (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyR2      s
    
(   R   R   R-   R5   R8   R2   (    (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyR#   `   s   			R;   c           B` s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C` s   | |  _  d  S(   N(   t   _ctx(   R   R4   (    (    sJ   lib/python2.7/site-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.(   R<   R'   R   R   (   R   R   (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyR      s    c         C` s1   |  j  d  k r t d   n  |  j  j | |  S(   Ns   Context was already finalized.(   R<   R'   R   R   (   R   R   R   (    (    sJ   lib/python2.7/site-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.(   R<   R'   R   R   (   R   R   (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyR      s
    	(   R   R   R-   R   R   R   (    (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyR;      s   			R:   c           B` sG   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C` s1   | |  _  d |  _ d |  _ d  |  _ t |  _ d  S(   Ni    (   R<   t   _bytes_processedt   _aad_bytes_processedR'   t   _tagR7   t   _updated(   R   R4   (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyR-   ¨   s
    				c         C` s   |  j  d  k r t d   n  t |  _ |  j | 7_ |  j |  j  j j k r{ t d j	 |  j  j j
 |  j  j j    n  d  S(   Ns   Context was already finalized.s+   {} has a maximum encrypted byte limit of {}(   R<   R'   R   R3   R@   R=   t   _modet   _MAX_ENCRYPTED_BYTESR0   t   formatR   (   R   t	   data_size(    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyt   _check_limit―   s    	c         C` s#   |  j  t |   |  j j |  S(   N(   RE   t   lenR<   R   (   R   R   (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyR   »   s    c         C` s&   |  j  t |   |  j j | |  S(   N(   RE   RF   R<   R   (   R   R   R   (    (    sJ   lib/python2.7/site-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.(   R<   R'   R   R   R    R?   (   R   R   (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyR   Γ   s    	c         C` sL   |  j  d  k r t d   n  |  j  j |  } |  j  j |  _ d  |  _  | S(   Ns   Context was already finalized.(   R<   R'   R   R!   R    R?   (   R   R    R   (    (    sJ   lib/python2.7/site-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%   {} has a maximum AAD byte limit of {}(   R<   R'   R   R@   R   R>   RF   RA   t   _MAX_AAD_BYTESR0   RC   R   R   (   R   R   (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyR   Σ   s    	$(	   R   R   R-   RE   R   R   R   R!   R   (    (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyR:   €   s   						R9   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.(   R<   R'   R   R?   (   R   (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyR    ζ   s    (   R   R   t   propertyR    (    (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyR9   δ   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"   R#   t   register_interfaceR;   R:   R9   (    (    (    sJ   lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.pyt   <module>   s6   (		-=