ó
BwLc           @   sh   d  d l  m Z m Z d 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_longt	   DerObjectt
   DerIntegert   DerSequencec           B   sV   e  Z i d  d 6d d 6d 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 | |  |  _ d |  _ d  S(   Nt    (   t   typeTagst   gett   typeTagt   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   chrt   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   ordR   t
   ValueError(   R   t   idxt   strt   lengtht   payloadLength(    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt
   _decodeLen0   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   decode?   s    N(	   t   __name__t
   __module__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   M   s    c         C   sK   t  |  j  |  _ t |  j d  d k r> d |  j |  _ n  t j |   S(   Ni    i   t    (   R    R$   R   R   R   R   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyR   Q   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    W   s
    (   R!   R"   R   R   R    (    (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyR   L   s   	c           B   sw   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z 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   _   s    c         C   s   |  j  | =d  S(   N(   R'   (   R   t   n(    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   __delitem__b   s    c         C   s   |  j  | S(   N(   R'   (   R   R(   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   __getitem__d   s    c         C   s   | |  j  | <d  S(   N(   R'   (   R   t   keyR$   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   __setitem__f   s    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__h   s    c         C   s   |  j  | | 5d  S(   N(   R'   (   R   R-   R.   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   __delslice__j   s    c         C   s    |  j  t d |  t d |  !S(   Ni    (   R'   t   max(   R   R-   R.   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   __getslice__l   s    c         C   s   t  |  j  S(   N(   R   R'   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   __len__n   s    c         C   s   |  j  j |  S(   N(   R'   t   append(   R   t   item(    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyR5   p   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   testR6   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   hasOnlyIntss   s    	 	c         C   s|   d |  _  xc |  j D]X } y |  j  | 7_  Wq y |  j  t |  j   7_  Wqk t d   qk 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   R6   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyR   }   s    	i    c   	      C   s-  g  |  _  y t j |  | |  } |  j |  j d k rF t d   n  d } xđ | t |  j  k  r|  j | } | |  j d k r― t   } | | j |  j |  7} |  j  j	 | j
  qO |  j | d |  j  \ } } |  j  j	 |  j | | | ! | | } qO WWn t k
 r(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   s   Not a DER SEQUENCE.i    R   i   s   Not a valid DER SEQUENCE.(   R'   R   R    R   R	   R   R   R   R   R5   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,   R0   R1   R3   R4   R5   R9   R   R    (    (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyR   ^   s   										
	N(    (   t   Crypto.Util.numberR    R   t   __all__R   R   R   (    (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Util/asn1.pyt   <module>   s   1