ó
íÂĞZc           @   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	 m
 Z
 m 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   ComparableRSAKeyt   ComparableX509c          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(    (    s4   /usr/lib/python2.7/dist-packages/josepy/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   (    (    s4   /usr/lib/python2.7/dist-packages/josepy/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(    (    s4   /usr/lib/python2.7/dist-packages/josepy/test_util.pyt   _guess_loader   s    c          G   s;   t  |  d t j j t j j ƒ } t j j | t |  Œ  ƒ S(   s   Load certificate.iÿÿÿÿ(   R   t   OpenSSLt   cryptot   FILETYPE_PEMt   FILETYPE_ASN1t   load_certificateR   (   R   t   loader(    (    s4   /usr/lib/python2.7/dist-packages/josepy/test_util.pyt	   load_cert(   s    c          G   s   t  t |  Œ  ƒ S(   s   Load ComparableX509 cert.(   R   R   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/josepy/test_util.pyt   load_comparable_cert/   s    c          G   s;   t  |  d t j j t j j ƒ } t j j | t |  Œ  ƒ S(   s   Load certificate request.iÿÿÿÿ(   R   R   R   R   R   t   load_certificate_requestR   (   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/josepy/test_util.pyt   load_csr4   s    c          G   s   t  t |  Œ  ƒ S(   s(   Load ComparableX509 certificate request.(   R   R!   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/josepy/test_util.pyt   load_comparable_csr;   s    c          G   sA   t  |  d t j t j ƒ } t | 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   R   t   NoneR    (   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/josepy/test_util.pyt   load_rsa_private_key@   s    c          G   s;   t  |  d t j j t j j ƒ } t j j | t |  Œ  ƒ S(   s   Load pyOpenSSL private key.iÿÿÿÿ(   R   R   R   R   R   t   load_privatekeyR   (   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/josepy/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(    (    s4   /usr/lib/python2.7/dist-packages/josepy/test_util.pyt   <lambda>_   s    c         S   s   d  S(   N(   R'   (   R,   (    (    s4   /usr/lib/python2.7/dist-packages/josepy/test_util.pyR-   a   s    N(   t   hasattrt   unittestR+   (   t	   conditiont   reason(    (    s4   /usr/lib/python2.7/dist-packages/josepy/test_util.pyt   skip_unlessO   s
    (   t   __doc__R   R/   R   R   t   cryptography.hazmat.backendsR    t   cryptography.hazmat.primitivesR   t   josepyR   R   R   R   R   R   R   R!   R"   R(   R*   R2   (    (    (    s4   /usr/lib/python2.7/dist-packages/josepy/test_util.pyt   <module>   s"   			
						