³ò
9Jc           @   s±   d  Z  d d k Z d d k Z d d k l Z d d k l Z d d k l Z d d k l Z e i i e i i	 e i
   d d d   Z d	 e i f d
     YZ d   Z d S(   s_   
Testcases to test behavior of Keyczar Crypters.

@author: arkajit.dey@gmail.com (Arkajit Dey)
iÿÿÿÿN(   t   errors(   t   keyczar(   t   readers(   t   utils   ..t   testdatat   CrypterTestc           B   se   e  Z d    Z d
 d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z RS(   c         C   s   d |  _  d  S(   Ns   This is some test data(   t   input(   t   self(    (    sB   /home/sweis/workspace/Keyczar-Python/tests/keyczar/crypter_test.pyt   setUp#   s    c   	      C   sÅ   t  i i t |  } | o t i |  } n t i i |  } t i t  i i | d   } t i t  i i | d   } | i	 |  } |  i
 |  i |  | i	 |  } |  i
 |  i |  d  S(   Ns   1.outs   2.out(   t   ost   patht   joint	   TEST_DATAR   t   Cryptert   ReadR   t   ReadFilet   Decryptt   assertEqualsR   (	   R   t   subdirt   readerR
   t   cryptert   active_ciphertextt   primary_ciphertextt   active_decryptedt   primary_decrypted(    (    sB   /home/sweis/workspace/Keyczar-Python/tests/keyczar/crypter_test.pyt   __testDecrypt&   s    c         C   sY   t  i i t i i t |   } | i |  i  } | i	 |  } |  i
 |  i |  d  S(   N(   R   R   R   R	   R
   R   R   t   EncryptR   R   R   (   R   R   R   t
   ciphertextt	   plaintext(    (    sB   /home/sweis/workspace/Keyczar-Python/tests/keyczar/crypter_test.pyt   __testEncryptAndDecrypt3   s    !c         C   s   |  i  d  d  S(   Nt   aes(   t   _CrypterTest__testDecrypt(   R   (    (    sB   /home/sweis/workspace/Keyczar-Python/tests/keyczar/crypter_test.pyt   testAesDecrypt9   s    c         C   se   t  i t i i t d   } t i i t i i t d   } t  i	 | |  } |  i
 d |  d  S(   Ns   aes-cryptedR   (   R   t
   FileReaderR	   R
   R   R   R   R   R   t   EncryptedReaderR   (   R   t   file_readert   key_decrypterR   (    (    sB   /home/sweis/workspace/Keyczar-Python/tests/keyczar/crypter_test.pyt   testAesEncryptedKeyDecrypt<   s    !c         C   s   |  i  d  d  S(   Nt   rsa(   R   (   R   (    (    sB   /home/sweis/workspace/Keyczar-Python/tests/keyczar/crypter_test.pyt   testRsaDecryptB   s    c         C   s   |  i  d  d  S(   NR   (   t#   _CrypterTest__testEncryptAndDecrypt(   R   (    (    sB   /home/sweis/workspace/Keyczar-Python/tests/keyczar/crypter_test.pyt   testAesEncryptAndDecryptE   s    c         C   s   |  i  d  d  S(   NR&   (   R(   (   R   (    (    sB   /home/sweis/workspace/Keyczar-Python/tests/keyczar/crypter_test.pyt   testRsaEncryptAndDecryptH   s    c         C   sÀ   t  i i t i i t d   } t i | i	 |  i
   } t i t d   } t t | d  d A } t i | d  | | d  } |  i t i | i |  |  i t i | i |  d  S(   NR   i    i   i,   i   (   R   R   R   R	   R
   R   R   R   t   DecodeR   R   t   Encodet   chrt   ordt   assertRaisesR    t   ShortCiphertextErrorR   t   KeyNotFoundError(   R   R   R   t   badt   char(    (    sB   /home/sweis/workspace/Keyczar-Python/tests/keyczar/crypter_test.pyt   testBadAesCiphertextsK   s    !c         C   s   d  |  _ d  S(   N(   t   NoneR   (   R   (    (    sB   /home/sweis/workspace/Keyczar-Python/tests/keyczar/crypter_test.pyt   tearDownT   s    N(   t   __name__t
   __module__R   R5   R   R(   R    R%   R'   R)   R*   R4   R6   (    (    (    sB   /home/sweis/workspace/Keyczar-Python/tests/keyczar/crypter_test.pyR   !   s   									c           C   s   t  i t d  S(   Nt   test(   t   unittestt	   makeSuiteR   (    (    (    sB   /home/sweis/workspace/Keyczar-Python/tests/keyczar/crypter_test.pyt   suiteW   s    (   t   __doc__R	   R:   R   R    R   R   R
   t   realpathR   t   getcwdR   t   TestCaseR   R<   (    (    (    sB   /home/sweis/workspace/Keyczar-Python/tests/keyczar/crypter_test.pys   <module>   s   -6