ó
T:´Nc           @   s~   d  d l  m Z m Z d  d l Z d  d l Td d d g Z d d
 d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d S(   iÿÿÿÿ(   t   long_to_bytest   bytes_to_longN(   t   *t	   DerObjectt
   DerIntegert   DerSequencec           B   sh   e  Z i e d  ƒ d 6e d ƒ d 6e d ƒ d 6Z d d „ Z d „  Z d „  Z d	 „  Z d
 d „ Z	 RS(   t   0t   SEQUENCEs   s
   BIT STRINGs   t   INTEGERc         C   s+   |  j  j | | ƒ |  _ t d ƒ |  _ d  S(   Nt    (   t   typeTagst   gett   typeTagt   bt   payload(   t   selft   ASN1Type(    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   __init__    s    c         C   s:   | d k r0 t  | ƒ } t t | ƒ d ƒ | St | ƒ S(   s¡   
        Return an octet string that is suitable for the BER/DER
        length element if the relevant payload is of the given
        size (in bytes).
        i   i€   (   R    t   bchrt   len(   R   t
   payloadLent   encoding(    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   _lengthOctets$   s    c         C   s$   |  j  |  j t |  j ƒ ƒ |  j S(   N(   R   R   R   R   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   encode/   s    c         C   s‚   t  | | ƒ } | d k r* | | d f St | | d | d | d @!ƒ } | d k rh t d ƒ ‚ n  | | d | d @f Sd S(   s£   
        Given a string and an index to a DER LV,
        this function returns a tuple with the length of V
        and an index to the first byte of it.
        i   i   s   Not a DER length tag.N(   t   bordR   t
   ValueError(   R   t   idxt   strt   lengtht   payloadLength(    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt
   _decodeLen2   s    #i    c         C   s¸   y | d |  _  t |  j  ƒ d @d k r8 t d ƒ ‚ n  |  j d | ƒ \ } } | r{ t | ƒ | | k r{ t d ƒ ‚ n  | | | | !|  _ Wn t k
 r¯ t d ƒ ‚ n X| | S(   Ni    i   s   Unsupported DER tagi   s   Not a DER structures   Not a valid DER SEQUENCE.(   R   R   R   R   R   R   t
   IndexError(   R   t   inputt   noLeftOversR   R   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   decodeA   s    N(
   t   __name__t
   __module__R   R
   t   NoneR   R   R   R   R"   (    (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyR      s   -			c           B   s)   e  Z d  d „ Z d „  Z d  d „ Z RS(   i    c         C   s   t  j |  d ƒ | |  _ d  S(   NR   (   R   R   t   value(   R   R&   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyR   O   s    c         C   sQ   t  |  j ƒ |  _ t |  j d ƒ d k rD t d ƒ |  j |  _ n  t j |  ƒ S(   Ni    i   t    (   R    R&   R   R   R   R   R   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyR   S   s    c         C   sS   t  j |  | | ƒ } t |  j d ƒ d k r= t d ƒ ‚ n  t |  j ƒ |  _ | S(   Ni    i   s   Negative INTEGER.(   R   R"   R   R   R   R   R&   (   R   R    R!   t	   tlvLength(    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyR"   Y   s
    (   R#   R$   R   R   R"   (    (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyR   N   s   	c           B   s   e  Z d  „  Z d „  Z d „  Z d „  Z e j d d k r[ d „  Z d „  Z	 d „  Z
 n  d	 „  Z d
 „  Z d „  Z d „  Z d d „ Z RS(   c         C   s   t  j |  d ƒ g  |  _ d  S(   NR   (   R   R   t   _seq(   R   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyR   a   s    c         C   s   |  j  | =d  S(   N(   R)   (   R   t   n(    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   __delitem__d   s    c         C   s   |  j  | S(   N(   R)   (   R   R*   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   __getitem__f   s    c         C   s   | |  j  | <d  S(   N(   R)   (   R   t   keyR&   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   __setitem__h   s    i    i   c         C   s   | |  j  | | +d  S(   N(   R)   (   R   t   it   jt   sequence(    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   __setslice__k   s    c         C   s   |  j  | | 5d  S(   N(   R)   (   R   R/   R0   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   __delslice__m   s    c         C   s    |  j  t d | ƒ t d | ƒ !S(   Ni    (   R)   t   max(   R   R/   R0   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   __getslice__o   s    c         C   s   t  |  j ƒ S(   N(   R   R)   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   __len__q   s    c         C   s   |  j  j | ƒ S(   N(   R)   t   append(   R   t   item(    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyR7   s   s    c         C   sN   |  j  s d Sd } x4 |  j  D]) } y | | 7} Wq t k
 rE d SXq Wd S(   Ni    i   (   R)   t	   TypeError(   R   t   testR8   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   hasOnlyIntsv   s    	 	c         C   s‚   t  d ƒ |  _ xc |  j D]X } y |  j | 7_ Wq y |  j t | ƒ j ƒ  7_ Wqq t d ƒ ‚ qq Xq Xq Wt j |  ƒ S(   s   
        Return the DER encoding for the ASN.1 SEQUENCE containing
        the non-negative integers and longs added to this object.
        R	   s&   Trying to DER encode an unknown object(   R   R   R)   R   R   R   R   (   R   R8   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyR   €   s    c   	      C   s5  g  |  _  yt j |  | | ƒ } |  j |  j d d k rJ t d ƒ ‚ n  d } x½ | t |  j ƒ k  r|  j | } | |  j d d k rÅ t ƒ  } | | j |  j | ƒ 7} |  j  j	 | j
 ƒ qS |  j | d |  j ƒ \ } } |  j  j	 |  j | | | !ƒ | | } qS WWn t k
 r0t d ƒ ‚ n X| S(   s
  
        This function decodes the given string into a sequence of
        ASN.1 objects. Yet, we only know about unsigned INTEGERs.
        Any other type is stored as its rough TLV. In the latter
        case, the correctectness of the TLV is not checked.
        R   i    s   Not a DER SEQUENCE.R   i   s   Not a valid DER SEQUENCE.(   R)   R   R"   R   R
   R   R   R   R   R7   R&   R   R   (	   R   R    R!   R(   R   R   t
   newIntegert   itemLent   itemIdx(    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyR"      s$    		(   R#   R$   R   R+   R,   R.   t   syst   version_infoR2   R3   R5   R6   R7   R;   R   R"   (    (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyR   `   s   									
	(    (	   t   Crypto.Util.numberR    R   R?   t   Crypto.Util.py3compatt   __all__R   R   R   (    (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   <module>   s   
1