
    hD              
          U d Z ddlZddlZddlZddlZddlmZmZ ddlZ	ddl
Z	ddlZ	ddlZ	ddlZ	ddlZ	ddlZ	 G d de	j                   j"                        Z G d d      Z G d d	e      Z G d
 de      Z G d de	j                   j"                        Z G d de      Z G d de      Z G d de      Z G d de      Zej6                  eej8                  eej:                  eej<                  eej>                  eiZ eeef   e!d<   dedefdZ"dee#z  dddefdZ$dee#z  de%de&de&def
d Z'd!ededdfd"Z(ej:                  ZejR                  Z)ejT                  Z*ejV                  Z+ej6                  ZejX                  Z,ej<                  ZejZ                  Z-ej\                  Z.ej^                  Z/ej8                  Zej>                  Zy)#zEDNS Options    N)AnyDictc                   P    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ZdZdZed        Zy)
OptionTypezEDNS option type codes               	   
                  c                      yNi   clss    F/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/dns/edns.py_maximumzOptionType._maximum?           N)__name__
__module____qualname____doc__NSIDDAUDHUN3UECSEXPIRECOOKIE	KEEPALIVEPADDINGCHAINEDEREPORTCHANNELclassmethodr   r   r   r   r   r   #   sU      D
C
C
C
CFFIGE
CM r   r   c                       e Zd ZdZdeez  fdZddedz  dedz  fdZ	defdZ
dd	Zeded
ddd fd       Zd Zd Zd Zd Zd Zd Zd Zd Zy)Optionz%Base class for all EDNS option types.otypec                 8    t         j                  |      | _        y)z_Initialize an option.

        *otype*, a ``dns.edns.OptionType``, is the option type.
        N)r   maker/   )selfr/   s     r   __init__zOption.__init__G   s    
  __U+
r   Nfilereturnc                     t         )zUConvert an option to wire format.

        Returns a ``bytes`` or ``None``.

        NotImplementedErrorr2   r4   s     r   to_wirezOption.to_wireN   s
     "!r   c                     t         Nr7   r2   s    r   to_textzOption.to_textV   s    !!r   c                 V    | j                         }|J t        | j                  |      S )zrCreates a dns.edns.GenericOption equivalent of this rdata.

        Returns a ``dns.edns.GenericOption``.
        )r:   GenericOptionr/   )r2   wires     r   
to_genericzOption.to_genericY   s,    
 ||~TZZ..r   parserdns.wire.Parserc                     t         )a  Build an EDNS option object from wire format.

        *otype*, a ``dns.edns.OptionType``, is the option type.

        *parser*, a ``dns.wire.Parser``, the parser, which should be
        restructed to the option length.

        Returns a ``dns.edns.Option``.
        r7   r   r/   rC   s      r   from_wire_parserzOption.from_wire_parserb   s
     "!r   c                 \    | j                         }|j                         }||k(  ry||kD  ryy)zCompare an EDNS option with another option of the same type.

        Returns < 0 if < *other*, 0 if == *other*, and > 0 if > *other*.
        r      )r:   )r2   otherrA   owires       r   _cmpzOption._cmpo   s1    
 ||~5=%<r   c                     t        |t              sy| j                  |j                  k7  ry| j                  |      dk(  S )NFr   
isinstancer.   r/   rM   r2   rK   s     r   __eq__zOption.__eq__|   s6    %(::$yy1$$r   c                     t        |t              sy| j                  |j                  k7  ry| j                  |      dk7  S )NTr   rO   rQ   s     r   __ne__zOption.__ne__   s6    %(::$yy1$$r   c                     t        |t              r| j                  |j                  k7  rt        S | j	                  |      dk  S Nr   rP   r.   r/   NotImplementedrM   rQ   s     r   __lt__zOption.__lt__   5    %(DJJ%++,E!!yy!##r   c                     t        |t              r| j                  |j                  k7  rt        S | j	                  |      dk  S rV   rW   rQ   s     r   __le__zOption.__le__   5    %(DJJ%++,E!!yy1$$r   c                     t        |t              r| j                  |j                  k7  rt        S | j	                  |      dk\  S rV   rW   rQ   s     r   __ge__zOption.__ge__   r]   r   c                     t        |t              r| j                  |j                  k7  rt        S | j	                  |      dkD  S rV   rW   rQ   s     r   __gt__zOption.__gt__   rZ   r   c                 "    | j                         S r<   )r>   r=   s    r   __str__zOption.__str__   s    ||~r   r<   r5   r@   )r   r   r   r   r   strr3   r   bytesr:   r>   rB   r,   rG   rM   rR   rT   rY   r\   r_   ra   rc   r   r   r   r.   r.   D   s    /,j3. ,"C$J "%$, "" "/ 
"Z 
"9J 
"x 
" 
"%%$
%
%
$
r   r.   c                        e Zd ZdZdeez  deez  f fdZddedz  dedz  fdZ	defd	Z
dd
Zedeez  dddefd       Z xZS )r@   zwGeneric Option Class

    This class is used for EDNS option types for which we have no better
    implementation.
    r/   datac                     t         |   |       t        j                  j                  j                  |d      | _        y )NT)superr3   dnsrdataRdata	_as_bytesrh   )r2   r/   rh   	__class__s      r   r3   zGenericOption.__init__   s,    IIOO--dD9	r   Nr4   r5   c                 V    |r|j                  | j                         y | j                  S r<   )writerh   r9   s     r   r:   zGenericOption.to_wire   "    JJtyy!99r   c                      d| j                    S )NzGeneric )r/   r=   s    r   r>   zGenericOption.to_text   s    $**&&r   c                     | S r<   r   r=   s    r   rB   zGenericOption.to_generic   s    r   rC   rD   c                 0     | ||j                               S r<   get_remainingrF   s      r   rG   zGenericOption.from_wire_parser   s     5&..011r   r<   rd   )r   r   r   r   r   re   rf   r3   r   r:   r>   rB   r,   r.   rG   __classcell__ro   s   @r   r@   r@      s    :j3. :eck :C$J %$, ' ' 2$2.?2	2 2r   r@   c                        e Zd ZdZddededz  def fdZdefdZed	ede	fd
       Z
ddedz  dedz  fdZedeez  ddde	fd       Z xZS )	ECSOptionz!EDNS Client Subnet (ECS, RFC7871)Naddresssrclenscopelenc                    t         	|   t        j                         t        j
                  j                  |      }|t        j                  k(  rd| _	        |d}t        j                  j                  j                  |      }t        j                  j                  j                  |dd      }t        j                  j                  j                  |dd      }n|t        j                  k(  rd| _	        |d}t        j                  j                  j                  |      }t        j                  j                  j                  |dd      }t        j                  j                  j                  |dd      }nt!        d	      |J || _        || _        || _        t        j
                  j)                  ||      }t+        t-        j.                  |d
z              }|d| | _        |dz  }|dk7  rMt3        j4                  dt7        | j0                  dd       dd|z
  z  z        }| j0                  dd |z   | _        yy)a  *address*, a ``str``, 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   r      rI          zBad address family       @r   BrJ      )rj   r3   r   r$   rk   inetaf_for_addresssocketAF_INET6familyrl   rm   _as_ipv6_address_as_intAF_INET_as_ipv4_address
ValueErrorr|   r}   r~   	inet_ptonintmathceiladdrdatastructpackord)
r2   r|   r}   r~   afr   nbytesnbitslastro   s
            r   r3   zECSOption.__init__   s    	(XX$$W- DK~iioo66w?GYY__,,VQ<Fyy..xC@H6>>!DK~iioo66w?GYY__,,VQ;Fyy..xB?H122!!! 88%%b'2TYYv|,- !&)
A:;;sCbc(:$;tE	?R$STD MM#2.5DM r   r5   c                 T    d| j                    d| j                   d| j                   S )NzECS /z scope/)r|   r}   r~   r=   s    r   r>   zECSOption.to_text   s'    dll^1T[[MHHr   textc                 :   d}| j                         }d}t        |      dk(  r|d   }n:t        |      dk(  r|d   |k7  rt        d|  d      |d   }nt        d|  d      |j                  d      }|dk(  r|j                  d      \  }}d	}n*|dk(  r|j                  d      \  }}}nt        d|  d      	 t	        |      }	 t	        |      }	t        ||	|      S # t        $ r t        d
d| dz         w xY w# t        $ r t        dd| dz         w xY w)a  Convert a string into a `dns.edns.ECSOption`

        *text*, a `str`, the text form of the option.

        Returns a `dns.edns.ECSOption`.

        Examples:

        >>> import dns.edns
        >>>
        >>> # basic example
        >>> dns.edns.ECSOption.from_text('1.2.3.4/24')
        >>>
        >>> # also understands scope
        >>> dns.edns.ECSOption.from_text('1.2.3.4/24/32')
        >>>
        >>> # IPv6
        >>> dns.edns.ECSOption.from_text('2001:4b98::1/64/64')
        >>>
        >>> # it understands results from `dns.edns.ECSOption.to_text()`
        >>> dns.edns.ECSOption.from_text('ECS 1.2.3.4/24/32')
        r$   NrI   r   r   zcould not parse ECS from ""r   0zinvalid scope z": scope must be an integerzinvalid srclen z": srclen must be an integer)splitlenr   countr   r{   )
r   optional_prefixtokensecs_text	n_slashesr|   tsrclentscopescoper}   s
             r   	from_textzECSOption.from_text   sb   0  v;!ayH[AayO+ #=dV1!EFFayH9$qABBNN3'	>'~~c2GWF!^'/~~c':$GWf9$qABB	YKE	\F
 &%00  	Y-!F8;V0WWXX	Y  	!ay0L$MM 	s   ;C C> C;>Dr4   c                     t        j                  d| j                  | j                  | j                        | j
                  z   }|r|j                  |       y |S )N!HBB)r   r   r   r}   r~   r   rq   r2   r4   values      r   r:   zECSOption.to_wire-  sG    KKT[[$--H4==X 	 JJuLr   r/   rC   rD   c                 z   |j                  d      \  }}}t        t        j                  |dz              }|j	                  |      }|dk(  r+d|z
  }t
        j                  j                  |d|z  z         }	n;|dk(  r+d|z
  }t
        j                  j                  |d|z  z         }	nt        d       | |	||      S )	Nr   r   rI          r      zunsupported family)

get_structr   r   r   	get_bytesrk   ipv4	inet_ntoaipv6r   )
r   r/   rC   r   srcr   addrlenprefixpadaddrs
             r   rG   zECSOption.from_wire_parser7  s     $..v6Udiic	*+!!'*Q;g+C88%%fw}&<=Dq[w,C88%%fw}&<=D1224e$$r   rV   r<   )r   r   r   r   re   r   r3   r>   staticmethodr.   r   r   rf   r:   r,   r   rG   rx   ry   s   @r   r{   r{      s    +-6 -6S4Z -6# -6^I I 41 41 41 41lC$J %$,  %$%.?%	% %r   r{   c                       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ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZed        Zy)EDECodezExtended DNS Error (EDE) codesr   rI   r   r   r   r   r	   r
   r   r   r   r   r   r      r   r      r                  r   c                      yr   r   r   s    r   r   zEDECode._maximumg  r   r   N)r   r   r   r   OTHERUNSUPPORTED_DNSKEY_ALGORITHMUNSUPPORTED_DS_DIGEST_TYPESTALE_ANSWERFORGED_ANSWERDNSSEC_INDETERMINATEDNSSEC_BOGUSSIGNATURE_EXPIREDSIGNATURE_NOT_YET_VALIDDNSKEY_MISSINGRRSIGS_MISSINGNO_ZONE_KEY_BIT_SETNSEC_MISSINGCACHED_ERROR	NOT_READYBLOCKEDCENSOREDFILTERED
PROHIBITEDSTALE_NXDOMAIN_ANSWERNOT_AUTHORITATIVENOT_SUPPORTEDNO_REACHABLE_AUTHORITYNETWORK_ERRORINVALID_DATAr,   r   r   r   r   r   r   J  s    (E#$ !"LMLNNLLIGHHJMML r   r   c                        e Zd ZdZh dZddeez  dedz  f fdZdefdZdd	e	dz  de
dz  fd
Zedeez  dddefd       Z xZS )	EDEOptionz!Extended DNS Error (EDE, RFC8914)>   DSNSECDNSKEYDNSSECRRSIGsNXDOMAINNcoder   c                     t         |   t        j                         t        j                  |      | _        |t        |t              st        d      || _
        y)z*code*, a ``dns.edns.EDECode`` or ``str``, the info code of the
        extended error.

        *text*, a ``str`` or ``None``, specifying additional information about
        the error.
        Nztext must be string or None)rj   r3   r   r*   r   r1   r   rP   re   r   r   )r2   r   r   ro   s      r   r3   zEDEOption.__init__q  sH     	(LL&	JtS$9:;;	r   r5   c                 (    d j                    } j                   t        v rQt        j                   j                         }dj                   fd|j	                  d      D              }|d| dz  } j
                  |d j
                   z  }|S )NzEDE  c              3   ^   K   | ]$  }|j                   v r|n|j                          & y wr<   )_preserve_casetitle).0wordr2   s     r   	<genexpr>z$EDEOption.to_text.<locals>.<genexpr>  s1        3 33Es   *-_z ()z: )r   r   r>   joinr   r   )r2   outputdescs   `  r   r>   zEDEOption.to_text  s    		{#99??499-D88  JJsO D 4&l"F99 499+&&Fr   r4   c                     t        j                  d| j                        }| j                  || j                  j	                  d      z  }|r|j                  |       y |S )Nz!Hutf8)r   r   r   r   encoderq   r   s      r   r:   zEDEOption.to_wire  sP    D$)),99 TYY%%f--EJJuLr   r/   rC   rD   c                     t         j                  |j                               }|j                         }|r|d   dk(  r|d d }|j	                  d      }nd } | ||      S )NrJ   r   r   )r   r1   
get_uint16rw   decode)r   r/   rC   r   r   btexts         r   rG   zEDEOption.from_wire_parser  sb     ||F--/0##%Bx1}CRyKK'EE4r   r<   )r   r   r   r   r   r   re   r3   r>   r   rf   r:   r,   r   r.   rG   rx   ry   s   @r   r   r   l  s~    +MNWs] #*  	C$J 	%$, 	  $ .? 	   r   r   c                        e Zd Zdef fdZddededz  fdZdefdZe	de
ez  d	ej                  j                  defd
       Z xZS )
NSIDOptionnsidc                 N    t         |   t        j                         || _        y r<   )rj   r3   r   r    r  )r2   r  ro   s     r   r3   zNSIDOption.__init__  s    )	r   Nr4   r5   c                 V    |r|j                  | j                         y | j                  S r<   )rq   r  r9   s     r   r:   zNSIDOption.to_wire  rr   r   c                     t        d | j                  D              r| j                  j                         }n-t        j                  | j                        j                         }d| S )Nc              3   4   K   | ]  }|d k\  xr |dk    yw)r   ~   Nr   )r   cs     r   r   z%NSIDOption.to_text.<locals>.<genexpr>  s      :1qDy&Q$Y&:s   zNSID )allr  r  binasciihexlify)r2   r   s     r   r>   zNSIDOption.to_text  sO    :		::II$$&E$$TYY/668Eugr   r/   rC   c                 .     | |j                               S r<   rv   rF   s      r   rG   zNSIDOption.from_wire_parser  s     6'')**r   r<   r   r   r   rf   r3   r   r:   re   r>   r,   r   rk   rA   Parserr.   rG   rx   ry   s   @r   r  r    sk    U C 54<   +$+.1hhoo+	+ +r   r  c                        e Zd Zdedef fdZddededz  fdZdefdZe	d	e
ez  d
ej                  j                  defd       Z xZS )CookieOptionclientserverc                     t         |   t        j                         || _        || _        t        |      dk7  rt        d      t        |      dk7  r(t        |      dk  st        |      dkD  rt        d      y y )Nr   zclient cookie must be 8 bytesr   r   z5server cookie must be empty or between 8 and 32 bytes)rj   r3   r   r&   r  r  r   r   )r2   r  r  ro   s      r   r3   zCookieOption.__init__  sr    **+v;!<==v;!VqCK"4DTUU 5Er   Nr4   r5   c                     |rO|j                  | j                         t        | j                        dkD  r|j                  | j                         y | j                  | j                  z   S rV   )rq   r  r   r  r9   s     r   r:   zCookieOption.to_wire  sL    JJt{{#4;;!#

4;;';;,,r   c                     t        j                  | j                        j                         }t	        | j
                        dkD  r.t        j                  | j
                        j                         }nd}d| | S )Nr    zCOOKIE )r  r  r  r  r   r  )r2   r  r  s      r   r>   zCookieOption.to_text  sc    !!$++.557t{{a%%dkk299;FF))r   r/   rC   c                 N     | |j                  d      |j                               S )Nr   )r   rw   rF   s      r   rG   zCookieOption.from_wire_parser  s%     6##A&(<(<(>??r   r<   r  ry   s   @r   r  r    sz    Vu Ve V-C -54< -* * @$@.1hhoo@	@ @r   r  c                        e Zd Zdej                  j
                  f fdZddededz  fdZ	de
fdZedee
z  d	ej                  j                  defd
       Z xZS )ReportChannelOptionagent_domainc                 N    t         |   t        j                         || _        y r<   )rj   r3   r   r+   r  )r2   r  ro   s     r   r3   zReportChannelOption.__init__  s    112(r   Nr4   r5   c                 8    | j                   j                  |      S r<   )r  r:   r9   s     r   r:   zReportChannelOption.to_wire  s      ((..r   c                 <    d| j                   j                         z   S )NzREPORTCHANNEL )r  r>   r=   s    r   r>   zReportChannelOption.to_text  s    $"3"3";";"===r   r/   rC   c                 .     | |j                               S r<   )get_namerF   s      r   rG   z$ReportChannelOption.from_wire_parser  s     6??$%%r   r<   )r   r   r   rk   nameNamer3   r   rf   r:   re   r>   r,   r   rA   r  r.   rG   rx   ry   s   @r   r  r    ss    )SXX]] )/C /54< /> > &$&.1hhoo&	& &r   r  _type_to_classr/   r5   c                 @    t         j                  |       }|t        }|S )zReturn the class for the specified option type.

    The GenericOption class is used if a more specific class is not
    known.
    )r%  getr@   )r/   r   s     r   get_option_classr(    s#     

U
#C
{Jr   rC   rD   c                 f    t         j                  |       } t        |       }|j                  | |      S )a  Build an EDNS option object from wire format.

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

    *parser*, a ``dns.wire.Parser``, the parser, which should be
    restricted to the option length.

    Returns an instance of a subclass of ``dns.edns.Option``.
    )r   r1   r(  rG   )r/   rC   r   s      r   option_from_wire_parserr*    s/     OOE"E
5
!Cv..r   rA   currentolenc                     t         j                  j                  ||      }|j                  |      5  t	        | |      cddd       S # 1 sw Y   yxY w)ar  Build an EDNS option object from wire format.

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

    *wire*, a ``bytes``, 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``.
    N)rk   rA   r  restrict_tor*  )r/   rA   r+  r,  rC   s        r   option_from_wirer/     sE      XX__T7+F			D	! 6&uf56 6 6s   AAimplementationc                     | t         |<   y)zRegister the implementation of an option type.

    *implementation*, a ``class``, is a subclass of ``dns.edns.Option``.

    *otype*, an ``int``, is the option type.
    N)r%  )r0  r/   s     r   register_typer2  5  s     +N5r   )0r   r  r   r   r   typingr   r   dns.enumrk   dns.inetdns.ipv4dns.ipv6dns.name	dns.rdatadns.wireenumIntEnumr   r.   r@   r{   r   r   r  r  r  r$   r*   r    r&   r+   r%  __annotations__r(  re   r*  rf   r   r/  r2  r!   r"   r#   r%   r'   r(   r)   r   r   r   <module>r>     s  $             !! B[ [|2F 2>F% F%Rchh D:  : z+ +6@6 @D&& &( NNINNIOOZ|1)Z_% 
J 
3 
//%6//"66#(6366>A66*+# +j +T + nnnnnnnn						  	


nn((r   