ó
›t0^c           @   s   d  Z  y d d l m Z m Z Wn' e k
 rI d d l m Z m Z n Xd d l Z d d l Z d d l m	 Z	 d e
 f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e e f d „  ƒ  YZ d e e f d „  ƒ  YZ d S(   s   JOSE utilities.iÿÿÿÿ(   t   Hashablet   MappingN(   t   rsat   abstractclassmethodc           B   s   e  Z d  Z e Z d „  Z RS(   sÚ  Descriptor for an abstract classmethod.

    It augments the :mod:`abc` framework with an abstract
    classmethod. This is implemented as :class:`abc.abstractclassmethod`
    in the standard Python library starting with version 3.2.

    This implementation is from a StackOverflow answer that was derived from
    the implementation in the Python 3.3 abc library.
    http://stackoverflow.com/questions/11217878/python-2-7-combine-abc-abstractmethod-and-classmethod.

    c         C   s#   t  | _ t t |  ƒ j | ƒ d  S(   N(   t   Truet   __isabstractmethod__t   superR   t   __init__(   t   selft   target(    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR      s    	(   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR      s   t   ComparableX509c           B   sV   e  Z d  Z d „  Z d „  Z e j j d „ Z d „  Z	 d „  Z
 d „  Z d „  Z RS(   sË   Wrapper for OpenSSL.crypto.X509** objects that supports __eq__.

    :ivar wrapped: Wrapped certificate or certificate request.
    :type wrapped: `OpenSSL.crypto.X509` or `OpenSSL.crypto.X509Req`.

    c         C   s   | |  _  d  S(   N(   t   wrapped(   R   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR   '   s    c         C   s   t  |  j | ƒ S(   N(   t   getattrR   (   R   t   name(    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyt   __getattr__,   s    c         C   sC   t  |  j t j j ƒ r' t j j } n t j j } | | |  j ƒ S(   sL  Dumps the object into a buffer with the specified encoding.

        :param int filetype: The desired encoding. Should be one of
            `OpenSSL.crypto.FILETYPE_ASN1`,
            `OpenSSL.crypto.FILETYPE_PEM`, or
            `OpenSSL.crypto.FILETYPE_TEXT`.

        :returns: Encoded X509 object.
        :rtype: str

        (   t
   isinstanceR   t   OpenSSLt   cryptot   X509t   dump_certificatet   dump_certificate_request(   R   t   filetypet   func(    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyt   _dump/   s    c         C   s,   t  | |  j ƒ s t S|  j ƒ  | j ƒ  k S(   N(   R   t	   __class__t   NotImplementedR   (   R   t   other(    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyt   __eq__A   s    c         C   s   t  |  j |  j ƒ  f ƒ S(   N(   t   hashR   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyt   __hash__G   s    c         C   s   |  | k S(   N(    (   R   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyt   __ne__J   s    c         C   s   d j  |  j j |  j ƒ S(   Ns   <{0}({1!r})>(   t   formatR   R
   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyt   __repr__M   s    (   R
   R   R   R   R   R   R   t   FILETYPE_ASN1R   R   R    R!   R#   (    (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR       s   					t   ComparableKeyc           B   sJ   e  Z d  Z e Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   sn   Comparable wrapper for ``cryptography`` keys.

    See https://github.com/pyca/cryptography/issues/2122.

    c         C   s   | |  _  d  S(   N(   t   _wrapped(   R   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR   Y   s    c         C   s   t  |  j | ƒ S(   N(   R   R&   (   R   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR   \   s    c         C   s‡   t  | |  j ƒ s+ |  j j | j j k	 r/ t St |  j d ƒ rW |  j ƒ  | j ƒ  k St |  j d ƒ r |  j ƒ  | j ƒ  k St Sd  S(   Nt   private_numberst   public_numbers(   R   R   R&   R   t   hasattrR'   R(   (   R   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR   _   s    c         C   s   |  | k S(   N(    (   R   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR!   k   s    c         C   s   d j  |  j j |  j ƒ S(   Ns   <{0}({1!r})>(   R"   R   R
   R&   (   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR#   n   s    c         C   s   |  j  |  j j ƒ  ƒ S(   s   Get wrapped public key.(   R   R&   t
   public_key(   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR*   q   s    (   R
   R   R   R   R    R   R   R   R!   R#   R*   (    (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR%   Q   s   					t   ComparableRSAKeyc           B   s   e  Z d  Z d „  Z RS(   s×   Wrapper for ``cryptography`` RSA keys.

    Wraps around:

    - :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`
    - :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`

    c      	   C   s¥   t  |  j t j ƒ rd |  j ƒ  } | j } t |  j | j | j	 | j
 | j | j | j | j f ƒ St  |  j t j ƒ r¡ |  j ƒ  } t |  j | j | j f ƒ Sd  S(   N(   R   R&   R   t   RSAPrivateKeyWithSerializationR'   R(   R   R   t   pt   qt   dmp1t   dmq1t   iqmpt   nt   et   RSAPublicKeyWithSerialization(   R   t   privt   pub(    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR    €   s    	(   R
   R   R   R    (    (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR+   v   s   t   ImmutableMapc           B   s\   e  Z d  Z d	 Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(
   s5   Immutable key to value mapping with attribute access.c         K   s‹   t  | ƒ t  |  j ƒ k rW t d j d j |  j ƒ | rH d j | ƒ n d ƒ ƒ ‚ n  x- |  j D]" } t j |  | | j | ƒ ƒ qa Wd  S(   NsA   __init__() takes exactly the following arguments: {0} ({1} given)s   , t   none(   t   sett	   __slots__t	   TypeErrorR"   t   joint   objectt   __setattr__t   pop(   R   t   kwargst   slot(    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR   ”   s    $c         K   s)   t  |  ƒ } | j | ƒ t |  ƒ |   S(   s   Return updated map.(   t   dictt   updatet   type(   R   R@   t   items(    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyRC      s    c         C   s5   y t  |  | ƒ SWn t k
 r0 t | ƒ ‚ n Xd  S(   N(   R   t   AttributeErrort   KeyError(   R   t   key(    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyt   __getitem__£   s    c         C   s   t  |  j ƒ S(   N(   t   iterR:   (   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyt   __iter__©   s    c         C   s   t  |  j ƒ S(   N(   t   lenR:   (   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyt   __len__¬   s    c            s#   t  t ‡  f d †  ˆ  j Dƒ ƒ ƒ S(   Nc         3   s   |  ] } t  ˆ  | ƒ Vq d  S(   N(   R   (   t   .0RA   (   R   (    s/   /usr/lib/python2.7/site-packages/josepy/util.pys	   <genexpr>°   s    (   R   t   tupleR:   (   R   (    (   R   s/   /usr/lib/python2.7/site-packages/josepy/util.pyR    ¯   s    c         C   s   t  d ƒ ‚ d  S(   Ns   can't set attribute(   RF   (   R   R   t   value(    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR>   ²   s    c         C   s2   d j  |  j j d j d „  t j |  ƒ Dƒ ƒ ƒ S(   Ns   {0}({1})s   , c         s   s'   |  ] \ } } d  j  | | ƒ Vq d S(   s	   {0}={1!r}N(   R"   (   RN   RH   RP   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pys	   <genexpr>·   s   (   R"   R   R
   R<   t   sixt	   iteritems(   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR#   µ   s    (    (   R
   R   R   R:   R   RC   RI   RK   RM   R    R>   R#   (    (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR7      s   								t
   frozendictc           B   se   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z RS(   s   Frozen dictionary.t   _itemst   _keysc      	   O   s–   | r | r t  | ƒ } n; t | ƒ d k rN t | d t ƒ rN | d } n	 t ƒ  ‚ t j |  d | ƒ t j |  d t t t	 j
 | ƒ ƒ ƒ ƒ d  S(   Ni   i    RT   RU   (   RB   RL   R   R   R;   R=   R>   RO   t   sortedRQ   t   iterkeys(   R   t   argsR@   RE   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR   À   s    %	c         C   s   |  j  | S(   N(   RT   (   R   RH   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyRI   Ì   s    c         C   s   t  |  j ƒ S(   N(   RJ   RU   (   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyRK   Ï   s    c         C   s   t  |  j ƒ S(   N(   RL   RT   (   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyRM   Ò   s    c            s   t  ‡  f d †  ˆ  j Dƒ ƒ S(   Nc         3   s   |  ] } | ˆ  | f Vq d  S(   N(    (   RN   RH   (   R   (    s/   /usr/lib/python2.7/site-packages/josepy/util.pys	   <genexpr>Ö   s    (   RO   RU   (   R   (    (   R   s/   /usr/lib/python2.7/site-packages/josepy/util.pyt   _sorted_itemsÕ   s    c         C   s   t  |  j ƒ  ƒ S(   N(   R   RY   (   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR    Ø   s    c         C   s3   y |  j  | SWn t k
 r. t | ƒ ‚ n Xd  S(   N(   RT   RG   RF   (   R   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR   Û   s    c         C   s   t  d ƒ ‚ d  S(   Ns   can't set attribute(   RF   (   R   R   RP   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR>   á   s    c         C   s&   d j  d j d „  |  j ƒ  Dƒ ƒ ƒ S(   Ns   frozendict({0})s   , c         s   s'   |  ] \ } } d  j  | | ƒ Vq d S(   s	   {0}={1!r}N(   R"   (   RN   RH   RP   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pys	   <genexpr>å   s   (   R"   R<   RY   (   R   (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyR#   ä   s    (   s   _itemss   _keys(   R
   R   R   R:   R   RI   RK   RM   RY   R    R   R>   R#   (    (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyRS   »   s   								(   R   t   collections.abcR    R   t   ImportErrort   collectionsR   RQ   t)   cryptography.hazmat.primitives.asymmetricR   t   classmethodR   R=   R   R%   R+   R7   RS   (    (    (    s/   /usr/lib/python2.7/site-packages/josepy/util.pyt   <module>   s   1%.