
    ,hB              
          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 G d de      Z G d de      Zej4                  eej6                  eej8                  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j8                  ZejP                  Z(ejR                  Z)ejT                  Z*ej4                  ZejV                  Z+ej:                  ZejX                  Z,ejZ                  Z-ej\                  Z.ej6                  Zej<                  Zy)#zEDNS Options    N)AnyDictOptionalUnionc                   L    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ed        Zy)
OptionType               	   
                  c                      yNi   clss    J/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/dns/edns.py_maximumzOptionType._maximum:           N)__name__
__module____qualname__NSIDDAUDHUN3UECSEXPIRECOOKIE	KEEPALIVEPADDINGCHAINEDEREPORTCHANNELclassmethodr   r   r   r   r   r       sP    D
C
C
C
CFFIGE
CM 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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   maker0   )selfr0   s     r   __init__zOption.__init__B   s    
  __U+
r   Nfilereturnc                     t         )zUConvert an option to wire format.

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

        NotImplementedErrorr3   r5   s     r   to_wirezOption.to_wireI   s
     "!r   c                     t         Nr8   r3   s    r   to_textzOption.to_textQ   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``.
        r8   r   r0   r@   s      r   from_wire_parserzOption.from_wire_parserT   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;   )r3   otherwireowires       r   _cmpzOption._cmpa   s1    
 ||~5=%<r   c                     t        |t              sy| j                  |j                  k7  ry| j                  |      dk(  S )NFr   
isinstancer/   r0   rK   r3   rH   s     r   __eq__zOption.__eq__n   s6    %(::$yy1$$r   c                     t        |t              sy| j                  |j                  k7  ry| j                  |      dk7  S )NTr   rM   rO   s     r   __ne__zOption.__ne__u   s6    %(::$yy1$$r   c                     t        |t              r| j                  |j                  k7  rt        S | j	                  |      dk  S Nr   rN   r/   r0   NotImplementedrK   rO   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 rT   rU   rO   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 rT   rU   rO   s     r   __ge__zOption.__ge__   r[   r   c                     t        |t              r| j                  |j                  k7  rt        S | j	                  |      dkD  S rT   rU   rO   s     r   __gt__zOption.__gt__   rX   r   c                 "    | j                         S r=   )r?   r>   s    r   __str__zOption.__str__   s    ||~r   r=   )r   r   r    __doc__r   r   strr4   r   r   bytesr;   r?   r-   rD   rK   rP   rR   rW   rZ   r]   r_   ra   r   r   r   r/   r/   ?   s    /,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.
    r0   datac                     t         |   |       t        j                  j                  j                  |d      | _        y )NT)superr4   dnsrdataRdata	_as_bytesrg   )r3   r0   rg   	__class__s      r   r4   zGenericOption.__init__   s,    IIOO--dD9	r   r5   r6   c                 V    |r|j                  | j                         y | j                  S r=   )writerg   r:   s     r   r;   zGenericOption.to_wire   "    JJtyy!99r   c                      d| j                   z  S )Nz
Generic %d)r0   r>   s    r   r?   zGenericOption.to_text   s    djj((r   r@   rA   c                 0     | ||j                               S r=   get_remainingrC   s      r   rD   zGenericOption.from_wire_parser   s     5&..011r   r=   )r   r   r    rb   r   r   rc   rd   r4   r   r   r;   r?   r-   r/   rD   __classcell__rn   s   @r   rf   rf      s    :eJO4 :E%*<M :HSM Xe_ ) ) 2*c/*24E2	2 2r   rf   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)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      rF          zBad address family       @r   BrG      )ri   r4   r   r%   rj   inetaf_for_addresssocketAF_INET6familyrk   rl   _as_ipv6_address_as_intAF_INET_as_ipv4_address
ValueErrorrz   r{   r|   	inet_ptonintmathceiladdrdatastructpackord)
r3   rz   r{   r|   afr   nbytesnbitslastrn   s
            r   r4   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   r6   c                 T    d| j                    d| j                   d| j                   S )NzECS /z scope/)rz   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%   NrF   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   ry   )
r   optional_prefixtokensecs_text	n_slashesrz   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r5   c                     t        j                  d| j                  | j                  | j                        | j
                  z   }|r|j                  |       y |S )N!HBB)r   r   r   r{   r|   r   rp   r3   r5   values      r   r;   zECSOption.to_wire  sG    KKT[[$--H4==X 	 JJuLr   r0   r@   rA   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   rF          r~      zunsupported family)

get_structr   r   r   	get_bytesrj   ipv4	inet_ntoaipv6r   )
r   r0   r@   r   srcr   addrlenprefixpadaddrs
             r   rD   zECSOption.from_wire_parser&  s     $..v6Udiic	*+!!'*Q;g+C88%%fw}&<=Dq[w,C88%%fw}&<=D1224e$$r   rT   r=   )r   r   r    rb   rc   r   r   r4   r?   staticmethodr/   r   r   rd   r;   r-   r   r   rD   rv   rw   s   @r   ry   ry      s    +-6 -6Xc] -6S -6^I I 41 41 41 41lHSM Xe_  %*c/*%4E%	% %r   ry   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y)EDECoder   rF   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._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NXDOMAIN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)ri   r4   r   r+   r   r2   r   rN   rc   r   r   )r3   r   r   rn   s      r   r4   zEDEOption.__init__^  sH     	(LL&	JtS$9:;;	r   r6   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wordr3   s     r   	<genexpr>z$EDEOption.to_text.<locals>.<genexpr>q  s1        3 33Es   *-_z ()z: )r   r   r?   joinr   r   )r3   outputdescs   `  r   r?   zEDEOption.to_textm  s    		{#99??499-D88  JJsO D 4&l"F99 499+&&Fr   r5   c                     t        j                  d| j                        }| j                  || j                  j	                  d      z  }|r|j                  |       y |S )Nz!Hutf8)r   r   r   r   encoderp   r   s      r   r;   zEDEOption.to_wirez  sP    D$)),99 TYY%%f--EJJuLr   r0   r@   rA   c                     t         j                  |j                               }|j                         }|r|d   dk(  r|d d }|j	                  d      }nd } | ||      S )NrG   r   r   )r   r2   
get_uint16ru   decode)r   r0   r@   r   r   btexts         r   rD   zEDEOption.from_wire_parser  sb     ||F--/0##%Bx1}CRyKK'EE4r   r=   )r   r   r    rb   r   r   r   rc   r   r4   r?   r   rd   r;   r-   r   r/   rD   rv   rw   s   @r   r   r   Y  s    +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                 N    t         |   t        j                         || _        y r=   )ri   r4   r   r!   r  )r3   r  rn   s     r   r4   zNSIDOption.__init__  s    )	r   r5   r6   c                 V    |r|j                  | j                         y | j                  S r=   )rp   r  r:   s     r   r;   zNSIDOption.to_wire  rq   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)r3   r   s     r   r?   zNSIDOption.to_text  sO    :		::II$$&E$$TYY/668Eugr   r0   r@   c                 .     | |j                               S r=   rt   rC   s      r   rD   zNSIDOption.from_wire_parser  s     6'')**r   r=   r   r   r    rd   r4   r   r   r;   rc   r?   r-   r   r   rj   rI   Parserr/   rD   rv   rw   s   @r   r  r    so    U C 8E?   +*c/*+47HHOO+	+ +r   r  c                        e Zd Zde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 )CookieOptionclientserverc                 "   t         |   t        j                  j                  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)
ri   r4   rj   ednsr   r'   r  r  r   r   )r3   r  r  rn   s      r   r4   zCookieOption.__init__  s|    ,,334v;!<==v;!VqCK"4DTUU 5Er   r5   r6   c                     |rO|j                  | j                         t        | j                        dkD  r|j                  | j                         y | j                  | j                  z   S rT   )rp   r  r   r  r:   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  )r3   r  r  s      r   r?   zCookieOption.to_text  sc    !!$++.557t{{a%%dkk299;FF))r   r0   r@   c                 N     | |j                  d      |j                               S )Nr   )r   ru   rC   s      r   rD   zCookieOption.from_wire_parser  s%     6##A&(<(<(>??r   r=   r  rw   s   @r   r  r    s~    Vu Ve V-C -8E? -* * @*c/*@47HHOO@	@ @r   r  c                        e Zd Zdej                  j
                  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 )ReportChannelOptionagent_domainc                 N    t         |   t        j                         || _        y r=   )ri   r4   r   r,   r  )r3   r  rn   s     r   r4   zReportChannelOption.__init__  s    112(r   r5   r6   c                 8    | j                   j                  |      S r=   )r  r;   r:   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   r0   r@   c                 .     | |j                               S r=   )get_namerC   s      r   rD   z$ReportChannelOption.from_wire_parser  s     6??$%%r   r=   )r   r   r    rj   nameNamer4   r   r   rd   r;   rc   r?   r-   r   r   rI   r  r/   rD   rv   rw   s   @r   r  r    sw    )SXX]] )/C /8E? /> > &*c/*&47HHOO&	& &r   r  _type_to_classr0   r6   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$  getrf   )r0   r   s     r   get_option_classr'    s#     

U
#C
{Jr   r@   rA   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   r2   r'  rD   )r0   r@   r   s      r   option_from_wire_parserr)    s/     OOE"E
5
!Cv..r   rI   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)rj   rI   r  restrict_tor)  )r0   rI   r*  r+  r@   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$  )r/  r0   s     r   register_typer1  "  s     +N5r   )/rb   r  r   r   r   typingr   r   r   r   dns.enumrj   dns.inet	dns.rdatadns.wireenumIntEnumr   r/   rf   ry   r   r   r  r  r  r%   r+   r!   r'   r,   r$  __annotations__r'  rc   r)  rd   r   r.  r1  r"   r#   r$   r&   r(   r)   r*   r   r   r   <module>r:     s  $      - -    !! >R Rj2F 28F% F%Rchh @:  : z+ +6@6 @D&& &( NNINNIOOZ|1)Z_% 
J 
3 
/S!/+<//"6S!6).69<6DG66*+# +j +T + nnnnnnnn						  	


nn((r   