
                              S r SSKJr  SSKrSSKrSSKrSrSrSr	Sr
SrS	rS
rSrSrSr " S S\5      r " S S\5      r " S S\5      r\\0rS rS rg)zEDNS Options    )absolute_importN               	   
            c                   ^    \ rS rSrSrS rS r\S 5       rS r	S r
S rS	 rS
 rS rS rSrg)Option0   z%Base class for all EDNS option types.c                     Xl         g)z@Initialize an option.

*otype*, an ``int``, is the option type.
Notype)selfr   s     lib/third_party/dns/edns.py__init__Option.__init__4   s	    
 
    c                     [         e)z*Convert an option to wire format.
        NotImplementedErrorr   files     r   to_wireOption.to_wire;   s
     "!r   c                     [         e)a<  Build an EDNS option object from wire format.

*otype*, an ``int``, is the option type.

*wire*, a ``binary``, is the wire-format message.

*current*, an ``int``, is the offset in *wire* of the beginning
of the rdata.

*olen*, an ``int``, is the length of the wire-format option data

Returns a ``dns.edns.Option``.
r   clsr   wirecurrentolens        r   	from_wireOption.from_wire@   s
      "!r   c                     [         e)zCompare an EDNS option with another option of the same type.

Returns < 0 if < *other*, 0 if == *other*, and > 0 if > *other*.
r   r   others     r   _cmpOption._cmpR   s
    
 "!r   c                     [        U[        5      (       d  gU R                  UR                  :w  a  gU R                  U5      S:H  $ NFr   
isinstancer   r   r+   r)   s     r   __eq__Option.__eq__Y   9    %((::$yy1$$r   c                     [        U[        5      (       d  gU R                  UR                  :w  a  gU R                  U5      S:g  $ r.   r/   r)   s     r   __ne__Option.__ne__`   r3   r   c                     [        U[        5      (       a  U R                  UR                  :w  a  [        $ U R	                  U5      S:  $ Nr   r0   r   r   NotImplementedr+   r)   s     r   __lt__Option.__lt__g   9    %((

ekk)!!yy!##r   c                     [        U[        5      (       a  U R                  UR                  :w  a  [        $ U R	                  U5      S:*  $ r8   r9   r)   s     r   __le__Option.__le__m   9    %((

ekk)!!yy1$$r   c                     [        U[        5      (       a  U R                  UR                  :w  a  [        $ U R	                  U5      S:  $ r8   r9   r)   s     r   __ge__Option.__ge__s   rA   r   c                     [        U[        5      (       a  U R                  UR                  :w  a  [        $ U R	                  U5      S:  $ r8   r9   r)   s     r   __gt__Option.__gt__y   r=   r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   classmethodr&   r+   r1   r5   r;   r?   rC   rF   __static_attributes__ r   r   r   r   0   sF    /"
 " """%%$%%$r   r   c                   N   ^  \ rS rSrSrU 4S jrS rS r\S 5       r	S r
SrU =r$ )	GenericOption   zkGeneric Option Class

This class is used for EDNS option types for which we have no better
implementation.
c                 8   > [         [        U ]  U5        X l        g N)superrQ   r   data)r   r   rV   	__class__s      r   r   GenericOption.__init__   s    mT+E2	r   c                 :    UR                  U R                  5        g rT   )writerV   r   s     r   r   GenericOption.to_wire   s    

499r   c                      SU R                   -  $ )Nz
Generic %dr   r   s    r   to_textGenericOption.to_text   s    djj((r   c                     U " XX3U-    5      $ rT   rO   r!   s        r   r&   GenericOption.from_wire   s    5w$788r   c                 p    U R                   UR                   :X  a  gU R                   UR                   :  a  ggNr      rV   r)   s     r   r+   GenericOption._cmp   s+    99

"99uzz!r   rf   )rH   rI   rJ   rK   rL   r   r   r^   rM   r&   r+   rN   __classcell__rW   s   @r   rQ   rQ      s5    ) 9 9 r   rQ   c                   R   ^  \ rS rSrSrS	U 4S jjrS rS r\S 5       r	S r
SrU =r$ )
	ECSOption   z!EDNS Client Subnet (ECS, RFC7871)c                   > [         [        U ]  [        5        [        R
                  R                  U5      nU[        R
                  R                  :X  a  SU l        Uc  SnO6U[        R
                  R                  :X  a  SU l        Uc  SnO[        S5      eXl        X l        X0l        [        R
                  R                  XA5      n[        [         R"                  " US-  5      5      nUSU U l        US-  nUS	:w  aK  [&        R(                  " S
[+        U R$                  SS 5      SU-  -  5      nU R$                  SS U-   U l        gg)a[  *address*, a ``text``, is the client address information.

*srclen*, an ``int``, the source prefix length, which is the
leftmost number of bits of the address to be used for the
lookup.  The default is 24 for IPv4 and 56 for IPv6.

*scopelen*, an ``int``, the scope prefix length.  This value
must be 0 in queries, and should be set in responses.
   N8   rd      zBad ip family       @r   r   Bre      )rU   rk   r   ECSdnsinetaf_for_addressAF_INET6familyAF_INET
ValueErroraddresssrclenscopelen	inet_ptonintmathceiladdrdatastructpackord)
r   r|   r}   r~   afr   nbytesnbitslastrW   s
            r   r   ECSOption.__init__   s    	i',XX$$W-"""DK~388###DK~_-- 88%%b2TYYvcz*+ !&)
A:;;sCbc(:$;tu}$MND MM#2.5DM r   c                 d    SR                  U R                  U R                  U R                  5      $ )NzECS {}/{} scope/{})formatr|   r}   r~   r]   s    r   r^   ECSOption.to_text   s(    #**4<<+/==: 	:r   c                    UR                  [        R                  " SU R                  5      5        UR                  [        R                  " SU R                  U R
                  5      5        UR                  U R                  5        g )Nz!Hz!BB)rZ   r   r   ry   r}   r~   r   r   s     r   r   ECSOption.to_wire   sN    

6;;tT[[12

6;;udkk4==AB

4==!r   c                    [         R                  " SX#US-    5      u  pVnUS-  n[        [        R                  " US-  5      5      nUS:X  a   [
        R                  R                  n	SU-
  n
O1US:X  a   [
        R                  R                  n	SU-
  n
O[        S5      e[
        R                  R                  XX3U-    SU
-  -   5      nU " XU5      $ )	Nz!HBB   rq   rd   rn      zunsupported family    )r   unpackr   r   r   ru   rv   rz   rx   r{   	inet_ntop)r"   r   r#   curr%   ry   srcscopeaddrlenr   padaddrs               r   r&   ECSOption.from_wire   s    #]]64CE?CUqdiiC()Q;!!Bg+Cq[""Bw,C122xx!!"37{&;gm&KL4e$$r   c                 p    U R                   UR                   :X  a  gU R                   UR                   :  a  ggrc   )r   r)   s     r   r+   ECSOption._cmp   s+    ==ENN*==5>>)r   )r   r|   ry   r~   r}   r8   )rH   rI   rJ   rK   rL   r   r^   r   rM   r&   r+   rN   rh   ri   s   @r   rk   rk      s4    +&6P:"
 % %$ r   rk   c                 B    [         R                  U 5      nUc  [        nU$ )zxReturn the class for the specified option type.

The GenericOption class is used if a more specific class is not
known.
)_type_to_classgetrQ   )r   r"   s     r   get_option_classr      s#     

U
#C
{Jr   c                 <    [        U 5      nUR                  XX#5      $ )aW  Build an EDNS option object from wire format.

*otype*, an ``int``, is the option type.

*wire*, a ``binary``, is the wire-format message.

*current*, an ``int``, is the offset in *wire* of the beginning
of the rdata.

*olen*, an ``int``, is the length of the wire-format option data

Returns an instance of a subclass of ``dns.edns.Option``.
)r   r&   )r   r#   r$   r%   r"   s        r   option_from_wirer      s     5
!C==g44r   )rL   
__future__r   r   r   dns.inetru   NSIDDAUDHUN3Urt   EXPIRECOOKIE	KEEPALIVEPADDINGCHAINobjectr   rQ   rk   r   r   r   rO   r   r   <module>r      s   $  &    		
		

M$V M$`F <L L^ 	Y
5r   