grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a àMÒeŸ;ã@sšUdZddlZddlZddlZddlZddlmZmZmZm Z ddl Z ddl Z ddl Z ddlZ Gdd„de jjƒZGdd„dƒZGdd „d eƒZGd d „d eƒZGd d „d e jjƒZGdd„deƒZGdd„deƒZejeejeejeiZeeefed<eedœdd„Ze eefdedœdd„Ze eefe e!e!edœdd„Z"eeddœdd„Z#ejZej$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 Z d Z d Z ed d „ƒZdS)Ú OptionTypeéééééé é é é é écCsdS©Niÿÿ©©Úclsrrú,/usr/lib/python3.9/site-packages/dns/edns.pyÚ_maximum8szOptionType._maximumN)Ú__name__Ú __module__Ú __qualname__ÚNSIDÚDAUÚDHUÚN3UÚECSÚEXPIREÚCOOKIEÚ KEEPALIVEÚPADDINGÚCHAINÚEDEÚ classmethodrrrrrr src@s¤eZdZdZeeefdœdd„Zd ee ee dœdd„Z ed œd d „Z e ed dd œdd„ƒZdd„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ÚreturncCst‚dS)zUConvert an option to wire format. Returns a ``bytes`` or ``None``. N©ÚNotImplementedError©r+r.rrrÚto_wireGszOption.to_wire©r/cCst‚dS©Nr0©r+rrrÚto_textOszOption.to_textúdns.wire.Parser©r)Úparserr/cCst‚dS)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``. Nr0©rr)r:rrrÚfrom_wire_parserRs zOption.from_wire_parsercCs,| ¡}| ¡}||krdS||kr(dSdS)z�Compare an EDNS option with another option of the same type. Returns < 0 if < *other*, 0 if == *other*, and > 0 if > *other*. rééÿÿÿÿ)r3)r+ÚotherÚwireZowirerrrÚ_cmp_sz Option._cmpcCs,t|tƒsdS|j|jkrdS| |¡dkS)NFr©Ú isinstancer'r)rA©r+r?rrrÚ__eq__ls   z Option.__eq__cCs,t|tƒsdS|j|jkrdS| |¡dkS)NTrrBrDrrrÚ__ne__ss   z Option.__ne__cCs(t|tƒr|j|jkrtS| |¡dkS©Nr©rCr'r)ÚNotImplementedrArDrrrÚ__lt__zsz Option.__lt__cCs(t|tƒr|j|jkrtS| |¡dkSrGrHrDrrrÚ__le__sz Option.__le__cCs(t|tƒr|j|jkrtS| |¡dkSrGrHrDrrrÚ__ge__„sz Option.__ge__cCs(t|tƒr|j|jkrtS| |¡dkSrGrHrDrrrÚ__gt__‰sz Option.__gt__cCs| ¡Sr5)r7r6rrrÚ__str__ŽszOption.__str__)N)rrrÚ__doc__rrÚstrr,rrÚbytesr3r7r&r<rArErFrJrKrLrMrNrrrrr'=s  r'cs~eZdZdZeeefeeefdœ‡fdd„ Zde e e edœdd„Z ed œd d „Z e eeefd ed œdd„ƒ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ÚRdataZ _as_bytesrS)r+r)rS©Ú __class__rrr,™s zGenericOption.__init__Nr-cCs|r| |j¡dS|jSdSr5)ÚwriterSr2rrrr3�s zGenericOption.to_wirer4cCs d|jS)Nz Generic %dr(r6rrrr7¤szGenericOption.to_textr8r9cCs||| ¡ƒSr5©Ú get_remainingr;rrrr<§szGenericOption.from_wire_parser)N)rrrrOrrrPrQr,rrr3r7r&r'r<Ú __classcell__rrrXrrR’s$ þrRcsŠeZdZdZdeeeedœ‡fdd„ Zedœdd „Ze ee d œd d „ƒZ dee ee d œdd„Zeeeefde dœdd„ƒZ‡ZS)Ú ECSOptionz!EDNS Client Subnet (ECS, RFC7871)Nr)ÚaddressÚsrclenÚscopelenc sRtƒ tj¡tj |¡}|tjkrjd|_ |dur6d}tj j   |¡}tj j   |dd¡}tj j   |dd¡}nX|tjkrºd|_ |dur†d}tj j  |¡}tj j   |dd¡}tj j   |dd¡}ntd ƒ‚||_||_||_tj ||¡}tt |d ¡ƒ}|d|…|_|d }|dk�rNt d t|jd d…ƒdd |>@¡}|jdd …||_dS)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é€r=éé zBad address familyç @r ÚBr>éÿ)rTr,rrrUZinetZaf_for_addressÚsocketZAF_INET6ÚfamilyrVrWZ_as_ipv6_addressÚ_as_intZAF_INETZ_as_ipv4_addressÚ ValueErrorr_r`raZ inet_ptonÚintÚmathÚceilÚaddrdataÚstructÚpackÚord) r+r_r`raÚafrqÚnbytesZnbitsZlastrXrrr,±s6     &zECSOption.__init__r4cCsd |j|j|j¡S)NzECS {}/{} scope/{})Úformatr_r`rar6rrrr7àszECSOption.to_text)Útextr/c Cs$d}| ¡}d}t|ƒdkr&|d}n>t|ƒdkrV|d|krLtd |¡ƒ‚|d}ntd |¡ƒ‚| d¡}|dkrŠ| d¡\}}d}n(|dkr¤| d¡\}}}ntd |¡ƒ‚z t|ƒ}Wn$tyâtd d  |¡ƒ‚Yn0z t|ƒ} Wn&t�ytd d  |¡ƒ‚Yn0t|| |ƒ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') rNr=rrbzcould not parse ECS from "{}"ú/Ú0zinvalid scope z"{}": scope must be an integerzinvalid srclen z"{}": srclen must be an integer)ÚsplitÚlenrmrwÚcountrnr^) rxZoptional_prefixÚtokensZecs_textZ n_slashesr_ZtsrclenZtscopeÚscoper`rrrÚ from_textãs<         ÿ   ÿ zECSOption.from_textr-cCs6t d|j|j|j¡|j}|r.| |¡dS|SdS)Nú!HBB)rrrsrkr`rarqrZ©r+r.Úvaluerrrr3s ÿ zECSOption.to_wirer8r9c CsŒ| d¡\}}}tt |d¡ƒ}| |¡}|dkrRd|}tj |d|¡} n.|dkrxd|}tj |d|¡} nt dƒ‚|| ||ƒS) Nr�rgr=éórbézunsupported family) Z get_structrnrorpZ get_bytesrUZipv4Z inet_ntoaZipv6rm) rr)r:rkÚsrcrZaddrlenÚprefixZpadZaddrrrrr<&s zECSOption.from_wire_parser)Nr)N)rrrrOrPrrnr,r7Ú staticmethodr'r€rrQr3r&rrr<r]rrrXrr^®s/8  þr^c@s|eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZedd„ƒZdS)ÚEDECoderr=rbrr„rr r r r r rrrérr†ééééééérecCsdSrrrrrrrTszEDECode._maximumN)rrrZOTHERZUNSUPPORTED_DNSKEY_ALGORITHMZUNSUPPORTED_DS_DIGEST_TYPEZ STALE_ANSWERZ FORGED_ANSWERZDNSSEC_INDETERMINATEZ DNSSEC_BOGUSZSIGNATURE_EXPIREDZSIGNATURE_NOT_YET_VALIDZDNSKEY_MISSINGZRRSIGS_MISSINGZNO_ZONE_KEY_BIT_SETZ NSEC_MISSINGZ CACHED_ERRORZ NOT_READYZBLOCKEDZCENSOREDZFILTEREDZ PROHIBITEDZSTALE_NXDOMAIN_ANSWERZNOT_AUTHORITATIVEZ NOT_SUPPORTEDZNO_REACHABLE_AUTHORITYZ NETWORK_ERRORZ INVALID_DATAr&rrrrrrŠ9s6rŠcs„eZdZdZhd£Zdeeefeedœ‡fdd„ Z edœdd „Z dee ee d œd d „Z eeeefd edœdd„ƒZ‡ZS)Ú EDEOptionz!Extended DNS Error (EDE, RFC8914)>ZDSZDNSKEYZNSECZDNSSECZNXDOMAINZRRSIGsN)Úcoderxcs>tƒ tj¡t |¡|_|dur4t|tƒs4t 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) rTr,rr%rŠr*r”rCrPrmrx)r+r”rxrXrrr,^s  zEDEOption.__init__r4csndˆj›�}ˆjtvrPt ˆj¡}d ‡fdd„| d¡Dƒ¡}|d|›d�7}ˆjdurj|dˆj›�7}|S) NzEDE ú c3s$|]}|ˆjvr|n| ¡VqdSr5)Ú_preserve_caseÚtitle)Ú.0Zwordr6rrÚ qsÿz$EDEOption.to_text..Ú_z (ú)z: )r”rŠr7Újoinr{rx)r+ÚoutputZdescrr6rr7ms   þ zEDEOption.to_textr-cCsBt d|j¡}|jdur(||j d¡7}|r:| |¡dS|SdS)Nz!HÚutf8)rrrsr”rxÚencoderZr‚rrrr3zs  zEDEOption.to_wirer8r9cCsLt | ¡¡}| ¡}|r>|ddkr2|dd…}| d¡}nd}|||ƒS)Nr>rrž)rŠr*Z get_uint16r\Údecode)rr)r:r”rxZbtextrrrr<…s   zEDEOption.from_wire_parser)N)N)rrrrOr–rrŠrPrr,r7rrQr3r&rr'r<r]rrrXrr“Ys"   þr“csheZdZedœ‡fdd„ Zdeeedœdd„Zedœd d „Z e e e efe jjed œd d „ƒZ‡ZS)Ú NSIDOption)Únsidcstƒ tj¡||_dSr5)rTr,rrr¢)r+r¢rXrrr,—szNSIDOption.__init__Nr-cCs|r| |j¡dS|jSdSr5)rZr¢r2rrrr3›s zNSIDOption.to_wirer4cCs:tdd„|jDƒƒr |j ¡}nt |j¡ ¡}d|›�S)Ncss|]}|dko|dkVqdS)rfé~Nr)r˜Úcrrrr™£óz%NSIDOption.to_text..zNSID )Úallr¢r ÚbinasciiZhexlify)r+rƒrrrr7¢s zNSIDOption.to_textr9cCs || ¡ƒSr5r[r;rrrr<ªszNSIDOption.from_wire_parser)N)rrrrQr,rrr3rPr7r&rrrUr@ÚParserr'r<r]rrrXrr¡–sþr¡Ú_type_to_class)r)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©ÚgetrR)r)rrrrÚget_option_class¸s r«r8r9cCst |¡}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«r<)r)r:rrrrÚoption_from_wire_parserÅs r¬)r)r@ÚcurrentÚolenr/cCsFtj ||¡}| |¡�t||ƒWdƒS1s80YdS)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)rUr@r¨Z restrict_tor¬)r)r@r­r®r:rrrÚoption_from_wireÖs r¯)Úimplementationr)r/cCs |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ësr±),rOr§rorjrrÚtypingrrrrZdns.enumrUZdns.inetZ dns.rdataZdns.wireÚenumÚIntEnumrr'rRr^rŠr“r¡rr%rr©Ú__annotations__r«rPr¬rQrnr¯r±rrrr r!r"r#r$rrrrÚsPU  =ý þ þ