HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/dns/__pycache__/edns.cpython-310.pyc
o

!we�6�
@s�UdZddlZddlZddlZddlmZmZmZmZddl	Z
ddlZ
ddlZ
ddl
Z
Gdd�de
jj�ZGdd�d�ZGdd	�d	e�ZGd
d�de�ZGdd
�d
e
jj�ZGdd�de�ZejeejeiZeeefed<dedefdd�Zdeeefdddefdd�Zdeeefdedededef
dd�Zdededdfdd �Z ej!Z!ej"Z"ej#Z#ej$Z$ejZej%Z%ej&Z&ej'Z'ej(Z(ej)Z)ejZdS)!zEDNS Options�N)�Any�Dict�Optional�Unionc@sDeZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
edd
��ZdS)�
OptionType������	�
���
�cC�dS�Ni�����clsrr�A/home/arjun/projects/env/lib/python3.10/site-packages/dns/edns.py�_maximum7�zOptionType._maximumN)�__name__�
__module__�__qualname__�NSID�DAU�DHU�N3U�ECS�EXPIRE�COOKIE�	KEEPALIVE�PADDING�CHAIN�EDE�classmethodrrrrrrsrc@s�eZdZdZdeeeffdd�Zddee	dee
fdd	�Zeded
dddfdd
��Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�Optionz%Base class for all EDNS option types.�otypecCst�|�|_dS)z_Initialize an option.

        *otype*, a ``dns.edns.OptionType``, is the option type.
        N)r�maker*)�selfr*rrr�__init__@szOption.__init__N�file�returncC�t�)zUConvert an option to wire format.

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

        ��NotImplementedError�r,r.rrr�to_wireGszOption.to_wire�parser�dns.wire.ParsercCr0)aBuild 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``.
        r1�rr*r5rrr�from_wire_parserOszOption.from_wire_parsercCs,|��}|��}||krdS||krdSdS)z�Compare an EDNS option with another option of the same type.

        Returns < 0 if < *other*, 0 if == *other*, and > 0 if > *other*.
        r����)r4)r,�other�wire�owirerrr�_cmp\szOption._cmpcCs,t|t�sdS|j|jkrdS|�|�dkS)NFr��
isinstancer)r*r>�r,r;rrr�__eq__i�

z
Option.__eq__cCs,t|t�sdS|j|jkrdS|�|�dkS)NTrr?rArrr�__ne__prCz
Option.__ne__cCs(t|t�r|j|jkr
tS|�|�dkS�Nr�r@r)r*�NotImplementedr>rArrr�__lt__w�z
Option.__lt__cCs(t|t�r|j|jkr
tS|�|�dkSrErFrArrr�__le__|rIz
Option.__le__cCs(t|t�r|j|jkr
tS|�|�dkSrErFrArrr�__ge__�rIz
Option.__ge__cCs(t|t�r|j|jkr
tS|�|�dkSrErFrArrr�__gt__�rIz
Option.__gt__cCs|��S�N)�to_text�r,rrr�__str__�szOption.__str__rM)rrr�__doc__rr�strr-rr�bytesr4r(r8r>rBrDrHrJrKrLrPrrrrr)<s
r)cs�eZdZdZdeeefdeeeff�fdd�Zdde	e
de	efd	d
�Zdefdd�Ze
deeefd
ddefdd��Z�ZS)�
GenericOptionzwGeneric Option Class

    This class is used for EDNS option types for which we have no better
    implementation.
    r*�datacs"t��|�tjj�|d�|_dS)NT)�superr-�dns�rdata�Rdata�	_as_bytesrU)r,r*rU��	__class__rrr-�szGenericOption.__init__Nr.r/cCs|r
|�|j�dS|jSrM)�writerUr3rrrr4�szGenericOption.to_wirecCs
d|jS)Nz
Generic %d)r*rOrrrrN�s
zGenericOption.to_textr5r6cCs|||���SrM)�
get_remainingr7rrrr8�szGenericOption.from_wire_parserrM)rrrrQrrrRrSr-rrr4rNr(r)r8�
__classcell__rrr[rrT�s&
���rTcs�eZdZdZddedeedef�fdd�
Zd	efd
d�Ze	ded	e
fd
d��Zddeed	ee
fdd�Zedeeefddd	e
fdd��Z�ZS)�	ECSOptionz!EDNS Client Subnet (ECS, RFC7871)Nr�address�srclen�scopelenc	s`t��tj�tj�|�}|tjkr5d|_	|durd}tj
j�|�}tj
j�
|dd�}tj
j�
|dd�}n,|tjkr]d|_	|durCd}tj
j�|�}tj
j�
|dd�}tj
j�
|dd�}ntd	��|dusgJ�||_||_||_tj�||�}tt�|d
��}|d|�|_|d}|dkr�t�dt|jd
d��dd|>@�}|jdd
�||_dSdS)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.
        �N�8r�r9�� zBad address family� @r�Br:�)rVr-rr!rW�inet�af_for_address�socket�AF_INET6�familyrXrY�_as_ipv6_address�_as_int�AF_INET�_as_ipv4_address�
ValueErrorrarbrc�	inet_pton�int�math�ceil�addrdata�struct�pack�ord)	r,rarbrc�afrz�nbytes�nbits�lastr[rrr-�s:

&�zECSOption.__init__r/cCsd�|j|j|j�S)NzECS {}/{} scope/{})�formatrarbrcrOrrrrN�szECSOption.to_text�textc
Csd}|��}d}t|�dkr|d}nt|�dkr+|d|kr&td�|���|d}ntd�|���|�d�}|dkrE|�d�\}}d}n|dkrR|�d�\}}}ntd�|���zt|�}Wntyotd	d
�|���wzt|�}	Wnty�tdd�|���wt||	|�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!Nr9rrdzcould not parse ECS from "{}"�/�0zinvalid scope z"{}": scope must be an integerzinvalid srclen z"{}": srclen must be an integer)�split�lenrur��countrwr`)
r��optional_prefix�tokens�ecs_text�	n_slashesra�tsrclen�tscope�scoperbrrr�	from_text�s@


����zECSOption.from_textr.cCs2t�d|j|j|j�|j}|r|�|�dS|S)N�!HBB)r{r|rprbrcrzr]�r,r.�valuerrrr4s�
zECSOption.to_wirer*r5r6c
Cs�|�d�\}}}tt�|d��}|�|�}|dkr)d|}tj�|d|�}	n|dkr<d|}tj�|d|�}	nt	d��||	||�S)	Nr�rir9��rd�zunsupported family)
�
get_structrwrxry�	get_bytesrW�ipv4�	inet_ntoa�ipv6ru)
rr*r5rp�srcr��addrlen�prefix�pad�addrrrrr8$s
zECSOption.from_wire_parserrErM)rrrrQrRrrwr-rN�staticmethodr)r�rrSr4r(rrr8r_rrr[rr`�s /8

���r`c@s|eZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZdZdZdZedd��ZdS)�EDECoderr9rdrr�rr	r
rrr
rrr�rr��������rgcCrrrrrrrrRrzEDECode._maximumN)rrr�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(rrrrrr�7s8r�cs�eZdZdZddeeefdeef�fdd�
Zdefdd	�Z	dd
ee
deefdd�Ze
d
eeefdddefdd��Z�ZS)�	EDEOptionz!Extended DNS Error (EDE, RFC8914)N�coder�cs>t��tj�t�|�|_|durt|t�st	d��||_
dS)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.
        Nztext must be string or None)rVr-rr'r�r+r�r@rRrur�)r,r�r�r[rrr-Zs

zEDEOption.__init__r/cCs*d|j��}|jdur|d|j��7}|S)NzEDE z: )r�r�)r,�outputrrrrNis
zEDEOption.to_textr.cCs>t�d|j�}|jdur||j�d�7}|r|�|�dS|S)Nz!H�utf8)r{r|r�r��encoder]r�rrrr4os

zEDEOption.to_wirer*r5r6cCsLt�|���}|��}|r|ddkr|dd�}|�d�}nd}|||�S)Nr:rr�)r�r+�
get_uint16r^�decode)rr*r5r�r��btextrrrr8zs
zEDEOption.from_wire_parserrM)rrrrQrr�rRrr-rNrrSr4r(rr)r8r_rrr[rr�Ws$
���r��_type_to_classr*r/cCst�|�}|durt}|S)z�Return the class for the specified option type.

    The GenericOption class is used if a more specific class is not
    known.
    N)r��getrT)r*rrrr�get_option_class�s
r�r5r6cCst�|�}t|�}|�||�S)aBuild 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``.
    )rr+r�r8)r*r5rrrr�option_from_wire_parser�s
r�r<�current�olencCsFtj�||�}|�|��
t||�Wd�S1swYdS)arBuild 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)rWr<�Parser�restrict_tor�)r*r<r�r�r5rrr�option_from_wire�s$�r��implementationcCs|t|<dS)z�Register 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*rrr�
register_type�sr�)*rQrxrnr{�typingrrrr�dns.enumrW�dns.inet�	dns.rdata�dns.wire�enum�IntEnumrr)rTr`r�r�r!r'r��__annotations__r�rRr�rSrwr�r�rrrr r"r#r$r%r&rrrr�<module>sdS 5�
��
�
����
�