
    L}bg;              
          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mZm	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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ef         dddefdZde	eef         de de!de!def
dZ"dededdfdZ#ej        Zej$        Z$ej%        Z%ej&        Z&ej        Zej'        Z'ej(        Z(ej)        Z)ej*        Z*ej+        Z+ej        ZdS )zEDNS Options    N)AnyDictOptionalUnionc                   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ed             ZdS )
OptionType               	   
               c                     dS Ni   clss    [/home/e360mart.nyusoft.in/public_html/e360mart_env/lib/python3.11/site-packages/dns/edns.py_maximumzOptionType._maximum8       u    N)__name__
__module____qualname__NSIDDAUDHUN3UECSEXPIRECOOKIE	KEEPALIVEPADDINGCHAINEDEclassmethodr   r   r   r   r   r       sd        D
C
C
C
CFFIGE
C  [  r   r   c                       e Zd ZdZdeeef         fdZddee	         dee
         fdZdef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dS )Optionz%Base class for all EDNS option types.otypec                 D    t                               |          | _        dS )z_Initialize an option.

        *otype*, a ``dns.edns.OptionType``, is the option type.
        N)r   maker.   )selfr.   s     r   __init__zOption.__init__@   s    
  __U++


r   Nfilereturnc                     t           )zUConvert an option to wire format.

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

        NotImplementedErrorr1   r3   s     r   to_wirezOption.to_wireG   s
     "!r   c                     t           Nr6   r1   s    r   to_textzOption.to_textO   s    !!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``.
        r6   r   r.   r>   s      r   from_wire_parserzOption.from_wire_parserR   s
     "!r   c                 v    |                                  }|                                 }||k    rdS ||k    rdS dS )zCompare an EDNS option with another option of the same type.

        Returns < 0 if < *other*, 0 if == *other*, and > 0 if > *other*.
        r      )r9   )r1   otherwireowires       r   _cmpzOption._cmp_   s?    
 ||~~5==1%<<1rr   c                     t          |t                    sdS | j        |j        k    rdS |                     |          dk    S )NFr   
isinstancer-   r.   rI   r1   rF   s     r   __eq__zOption.__eq__l   sD    %(( 	5:$$5yy1$$r   c                     t          |t                    sdS | j        |j        k    rdS |                     |          dk    S )NTr   rK   rM   s     r   __ne__zOption.__ne__s   sD    %(( 	4:$$4yy1$$r   c                     t          |t                    r| j        |j        k    rt          S |                     |          dk     S Nr   rL   r-   r.   NotImplementedrI   rM   s     r   __lt__zOption.__lt__z   ?    %(( 	"DJ%+,E,E!!yy!##r   c                     t          |t                    r| j        |j        k    rt          S |                     |          dk    S rR   rS   rM   s     r   __le__zOption.__le__   ?    %(( 	"DJ%+,E,E!!yy1$$r   c                     t          |t                    r| j        |j        k    rt          S |                     |          dk    S rR   rS   rM   s     r   __ge__zOption.__ge__   rY   r   c                     t          |t                    r| j        |j        k    rt          S |                     |          dk    S rR   rS   rM   s     r   __gt__zOption.__gt__   rV   r   c                 *    |                                  S r;   )r=   r<   s    r   __str__zOption.__str__   s    ||~~r   r;   )r   r   r   __doc__r   r   strr2   r   r   bytesr9   r=   r+   rB   rI   rN   rP   rU   rX   r[   r]   r_   r   r   r   r-   r-   =   s6       //,eJO4 , , , ," "HSM "Xe_ " " " "" " " " " 
"Z 
"9J 
"x 
" 
" 
" [
"  % % %% % %$ $ $
% % %
% % %
$ $ $
    r   r-   c                        e Zd ZdZdeeef         deeef         f fdZdde	e
         de	e         fdZdefd	Zedeeef         d
ddefd            Z xZS )GenericOptionzwGeneric Option Class

    This class is used for EDNS option types for which we have no better
    implementation.
    r.   datac                     t                                          |           t          j        j                            |d          | _        d S )NT)superr2   dnsrdataRdata	_as_bytesre   )r1   r.   re   	__class__s      r   r2   zGenericOption.__init__   s:    IO--dD99			r   Nr3   r4   c                 L    |r|                     | j                   d S | j        S r;   )writere   r8   s     r   r9   zGenericOption.to_wire   +     	JJty!!!49r   c                     d| j         z  S )Nz
Generic %d)r.   r<   s    r   r=   zGenericOption.to_text   s    dj((r   r>   r?   c                 >     | ||                                           S r;   get_remainingrA   s      r   rB   zGenericOption.from_wire_parser   s"     s5&..00111r   r;   )r   r   r   r`   r   r   ra   rb   r2   r   r   r9   r=   r+   r-   rB   __classcell__rl   s   @r   rd   rd      s         :eJO4 :E%*<M : : : : : : HSM Xe_    ) ) ) ) ) 2*c/*24E2	2 2 2 [2 2 2 2 2r   rd   c                        e Zd ZdZddedee         def fdZdefd	Ze	d
ede
fd            Zddee         dee         fdZedeeef         ddde
fd            Z xZS )	ECSOptionz!EDNS Client Subnet (ECS, RFC7871)Nr   addresssrclenscopelenc                 z   t                                          t          j                   t          j                            |          }|t          j        k    r|d| _	        |d}t          j
        j                            |          }t          j
        j                            |dd          }t          j
        j                            |dd          }n|t          j        k    r|d| _	        |d}t          j
        j                            |          }t          j
        j                            |dd          }t          j
        j                            |dd          }nt!          d	          |J || _        || _        || _        t          j                            ||          }t+          t-          j        |d
z                      }|d|         | _        |dz  }|dk    rQt3          j        dt7          | j        dd                   dd|z
  z  z            }| j        dd         |z   | _        dS dS )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      rD          zBad address family       @r   BrE      )rg   r2   r   r$   rh   inetaf_for_addresssocketAF_INET6familyri   rj   _as_ipv6_address_as_intAF_INET_as_ipv4_address
ValueErrorrx   ry   rz   	inet_ptonintmathceiladdrdatastructpackord)
r1   rx   ry   rz   afr   nbytesnbitslastrl   s
            r   r2   zECSOption.__init__   s    	(((X$$W--  DK~io66w??GY_,,VQ<<Fy..xC@@HH6>!!DK~io66w??GY_,,VQ;;Fy..xB??HH1222!!! 8%%b'22TYv|,,-- !&)
A::;sCbcc(:$;$;tE	?R$STTD M#2#.5DMMM :r   r4   c                 N    d                     | j        | j        | j                  S )NzECS {}/{} scope/{})formatrx   ry   rz   r<   s    r   r=   zECSOption.to_text   s     #**4<dmTTTr   textc                 d   d}|                                  }d}t          |          dk    r	|d         }nlt          |          dk    r7|d         |k    r"t          d                    |                     |d         }n"t          d                    |                     |                    d          }|dk    r|                     d          \  }}d}nB|dk    r|                     d          \  }}}n"t          d                    |                     	 t          |          }n3# t          $ r& t          d	d
                    |          z             w xY w	 t          |          }	n3# t          $ r& t          dd                    |          z             w xY wt          ||	|          S )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$   NrD   r   r|   zcould not parse ECS from "{}"/0zinvalid scope z"{}": scope must be an integerzinvalid srclen z"{}": srclen must be an integer)splitlenr   r   countr   rw   )
r   optional_prefixtokensecs_text	n_slashesrx   tsrclentscopescopery   s
             r   	from_textzECSOption.from_text   s   0  v;;!ayHH[[AayO++ !@!G!G!M!MNNNayHH<CCDIIJJJNN3''	>>'~~c22GWFF!^^'/~~c':':$GWff<CCDIIJJJ	KKEE 	 	 	 #C#J#J6#R#RR  		\\FF 	 	 	!$E$L$LW$U$UU  	 &%000s   D* *0EE. .0Fr3   c                     t          j        d| j        | j        | j                  | j        z   }|r|                    |           d S |S )N!HBB)r   r   r   ry   rz   r   rn   r1   r3   values      r   r9   zECSOption.to_wire  sM    KT[$-HH4=X 	  	JJu4Lr   r.   r>   r?   c                    |                     d          \  }}}t          t          j        |dz                      }|                    |          }|dk    r+d|z
  }t
          j                            |d|z  z             }	n@|dk    r+d|z
  }t
          j                            |d|z  z             }	nt          d           | |	||          S )	Nr   r   rD          r|      zunsupported family)

get_structr   r   r   	get_bytesrh   ipv4	inet_ntoaipv6r   )
r   r.   r>   r   srcr   addrlenprefixpadaddrs
             r   rB   zECSOption.from_wire_parser&  s     $..v66Udic	**++!!'**Q;;g+C8%%fw}&<==DDq[[w,C8%%fw}&<==DD1222s4e$$$r   rR   r;   )r   r   r   r`   ra   r   r   r2   r=   staticmethodr-   r   r   rb   r9   r+   r   r   rB   rt   ru   s   @r   rw   rw      s!       ++-6 -6 -6Xc] -6S -6 -6 -6 -6 -6 -6^U U U U U 61 61 61 61 61 \61p HSM Xe_     %*c/*%4E%	% % % [% % % % %r   rw   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ed             ZdS )EDECoder   rD   r|   r	   r   r
   r   r   r   r   r   r   r   r      r   r                        r   c                     dS r   r   r   s    r   r   zEDECode._maximumT  r   r   N)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   9  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ef         dee         f fdZ	defdZ
dd	ee         dee         fd
Zedeeef         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                              |          | _        |$t          |t                    st          d          || _
        dS )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)rg   r2   r   r*   r   r0   r   rL   ra   r   r   )r1   r   r   rl   s      r   r2   zEDEOption.__init__^  sa     	(((LL&&	JtS$9$9:;;;			r   r4   c                     d j          } j         t          v r\t                               j                   }d                     fd|                    d          D                       }|d| dz  } j        |d j         z  }|S )NzEDE  c              3   V   K   | ]#}|j         v r|n|                                V  $d S r;   )_preserve_casetitle).0wordr1   s     r   	<genexpr>z$EDEOption.to_text.<locals>.<genexpr>q  sP          333     r   _z ()z: )r   r   r=   joinr   r   )r1   outputdescs   `  r   r=   zEDEOption.to_textm  s    #	##9??49--D88     JJsOO    D l4lll"F9 &49&&&Fr   r3   c                     t          j        d| j                  }| j        || j                            d          z  }|r|                    |           d S |S )Nz!Hutf8)r   r   r   r   encodern   r   s      r   r9   zEDEOption.to_wirez  s[    D$),,9 TY%%f---E 	JJu4Lr   r.   r>   r?   c                     t                               |                                          }|                                }|r,|d         dk    r
|d d         }|                    d          }nd } | ||          S )NrE   r   r   )r   r0   
get_uint16rs   decode)r   r.   r>   r   r   btexts         r   rB   zEDEOption.from_wire_parser  s~     ||F--//00##%% 	Bx1}}CRCyKK''EEEs4r   r;   )r   r   r   r`   r   r   r   ra   r   r2   r=   r   rb   r9   r+   r   r-   rB   rt   ru   s   @r   r   r   Y  s        ++MMMN U7C<0           	 	HSM 	Xe_ 	 	 	 	  *c/* 4E 	      [         r   r   c                        e Zd Zdef fdZddedee         fdZdefdZ	e
deeef         d	ej        j        defd
            Z xZS )
NSIDOptionnsidc                 l    t                                          t          j                   || _        d S r;   )rg   r2   r   r    r  )r1   r  rl   s     r   r2   zNSIDOption.__init__  s(    )))			r   Nr3   r4   c                 L    |r|                     | j                   d S | j        S r;   )rn   r  r8   s     r   r9   zNSIDOption.to_wire  ro   r   c                     t          d | j        D                       r| j                                        }n+t          j        | j                                                  }d| S )Nc              3   .   K   | ]}|d k    o|dk    V  dS )r   ~   Nr   )r   cs     r   r   z%NSIDOption.to_text.<locals>.<genexpr>  s/      ::1qDy&Q$Y::::::r   zNSID )allr  r   binasciihexlify)r1   r   s     r   r=   zNSIDOption.to_text  sb    ::	::::: 	9I$$&&EE$TY//6688Eur   r.   r>   c                 <     | |                                           S r;   rr   rA   s      r   rB   zNSIDOption.from_wire_parser  s      s6''))***r   r;   )r   r   r   rb   r2   r   r   r9   ra   r=   r+   r   r   rh   rG   Parserr-   rB   rt   ru   s   @r   r  r    s        U       C 8E?         +*c/*+47HO+	+ + + [+ + + + +r   r  _type_to_classr.   r4   c                 L    t                               |           }|t          }|S )zReturn the class for the specified option type.

    The GenericOption class is used if a more specific class is not
    known.
    )r  getrd   )r.   r   s     r   get_option_classr    s&     

U
#
#C
{Jr   r>   r?   c                     t                               |           } t          |           }|                    | |          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   r0   r  rB   )r.   r>   r   s      r   option_from_wire_parserr    s8     OOE""E
5
!
!Cv...r   rG   currentolenc                     t           j                            ||          }|                    |          5  t	          | |          cddd           S # 1 swxY w Y   dS )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)rh   rG   r  restrict_tor  )r.   rG   r  r  r>   s        r   option_from_wirer    s      X__T7++F			D	!	! 6 6&uf556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6s   AAAimplementationc                     | t           |<   dS )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  )r  r.   s     r   register_typer    s     +N5r   ),r`   r
  r   r   r   typingr   r   r   r   dns.enumrh   dns.inet	dns.rdatadns.wireenumIntEnumr   r-   rd   rw   r   r   r  r$   r*   r    r  __annotations__r  ra   r  rb   r   r  r  r!   r"   r#   r%   r&   r'   r(   r)   r   r   r   <module>r$     s  $        - - - - - - - - - - - -           !   :R R R R R R R Rj2 2 2 2 2F 2 2 28H% H% H% H% H% H% H% H%V    ch   @:  :  :  :  :  :  :  : z+ + + + + + + +8 NINIOZ)Z_%   
J 
3 
 
 
 
/S!/+<// / / /"6S!6).69<6DG66 6 6 6*+# +j +T + + + + nnnn				 	

nr   