ó
Ą\\c           @   sŲ   d  Z  d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l	 Z
 d d l m Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d S(   sJ   Test utilities.

.. warning:: This module is not part of the public API.

iĸĸĸĸN(   t   default_backend(   t   serialization(   t   cryptoc          G   s   t  j t t j j d |    S(   s   Path to a test vector.t   testdata(   t   pkg_resourcest   resource_filenamet   __name__t   ost   patht   join(   t   names(    (    s2   /usr/lib/python2.7/dist-packages/acme/test_util.pyt   vector_path   s    c          G   s   t  j t t j j d |    S(   s   Load contents of a test vector.R   (   R   t   resource_stringR   R   R   R	   (   R
   (    (    s2   /usr/lib/python2.7/dist-packages/acme/test_util.pyt   load_vector   s    c         C   sT   t  j j |   \ } } | j   d k r. | S| j   d k rD | St d   d  S(   Ns   .pems   .ders1   Loader could not be recognized based on extension(   R   R   t   splitextt   lowert
   ValueError(   t   filenamet
   loader_pemt
   loader_dert   _t   ext(    (    s2   /usr/lib/python2.7/dist-packages/acme/test_util.pyt   _guess_loader   s    c          G   s2   t  |  d t j t j  } t j | t |     S(   s   Load certificate.iĸĸĸĸ(   R   R   t   FILETYPE_PEMt   FILETYPE_ASN1t   load_certificateR   (   R
   t   loader(    (    s2   /usr/lib/python2.7/dist-packages/acme/test_util.pyt	   load_cert(   s    c          G   s   t  j t |     S(   s   Load ComparableX509 cert.(   t   joset   ComparableX509R   (   R
   (    (    s2   /usr/lib/python2.7/dist-packages/acme/test_util.pyt   load_comparable_cert/   s    c          G   s2   t  |  d t j t j  } t j | t |     S(   s   Load certificate request.iĸĸĸĸ(   R   R   R   R   t   load_certificate_requestR   (   R
   R   (    (    s2   /usr/lib/python2.7/dist-packages/acme/test_util.pyt   load_csr4   s    c          G   s   t  j t |     S(   s(   Load ComparableX509 certificate request.(   R   R   R    (   R
   (    (    s2   /usr/lib/python2.7/dist-packages/acme/test_util.pyt   load_comparable_csr;   s    c          G   sD   t  |  d t j t j  } t j | t |    d d d t    S(   s   Load RSA private key.iĸĸĸĸt   passwordt   backendN(	   R   R   t   load_pem_private_keyt   load_der_private_keyR   t   ComparableRSAKeyR   t   NoneR    (   R
   R   (    (    s2   /usr/lib/python2.7/dist-packages/acme/test_util.pyt   load_rsa_private_key@   s    	c          G   s2   t  |  d t j t j  } t j | t |     S(   s   Load pyOpenSSL private key.iĸĸĸĸ(   R   R   R   R   t   load_privatekeyR   (   R
   R   (    (    s2   /usr/lib/python2.7/dist-packages/acme/test_util.pyt   load_pyopenssl_private_keyH   s    c         C   s7   t  t d  r t j |  |  S|  r, d   Sd   Sd S(   sq  Skip tests unless a condition holds.

    This implements the basic functionality of unittest.skipUnless
    which is only available on Python 2.7+.

    :param bool condition: If ``False``, the test will be skipped
    :param str reason: the reason for skipping the test

    :rtype: callable
    :returns: decorator that hides tests unless condition is ``True``

    t
   skipUnlessc         S   s   |  S(   N(    (   t   cls(    (    s2   /usr/lib/python2.7/dist-packages/acme/test_util.pyt   <lambda>_   s    c         S   s   d  S(   N(   R'   (   R,   (    (    s2   /usr/lib/python2.7/dist-packages/acme/test_util.pyR-   a   s    N(   t   hasattrt   unittestR+   (   t	   conditiont   reason(    (    s2   /usr/lib/python2.7/dist-packages/acme/test_util.pyt   skip_unlessO   s
    c         C   s@   d } t  j t j d k o3 t j j d d  d k |  |   S(   s7   Decorator to skip temporarily a broken test on Windows.s:   Test is broken and ignored on windows but should be fixed.t   win32t   SKIP_BROKEN_TESTS_ON_WINDOWSt   true(   R/   t   skipIft   syst   platformR   t   environt   get(   t   functionR1   (    (    s2   /usr/lib/python2.7/dist-packages/acme/test_util.pyt   broken_on_windowsc   s
    (   t   __doc__R   R7   R   R/   t   cryptography.hazmat.backendsR    t   cryptography.hazmat.primitivesR   t   josepyR   t   OpenSSLR   R   R   R   R   R   R    R!   R(   R*   R2   R<   (    (    (    s2   /usr/lib/python2.7/dist-packages/acme/test_util.pyt   <module>   s&   			
							