U mf;@sUdZddlZddlZddlZddlZddlmZmZmZm Z ddl Z ddl Z ddl Z ddlZ Gddde jjZGdddZGdd d eZGd d d eZGd d d e jjZGdddeZGdddeZejeejeejeiZeeefed<eedddZe eefdedddZe eefe e!e!edddZ"eeddddZ#ejZej$Z$ej%Z%ej&Z&ejZej'Z'ej(Z(ej)Z)ej*Z*ej+Z+ejZdS) z EDNS OptionsN)AnyDictOptionalUnionc@sDeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z ed d ZdS) OptionType cCsdSNiclsrr6/opt/hc_python/lib/python3.8/site-packages/dns/edns.py_maximum8szOptionType._maximumN)__name__ __module__ __qualname__NSIDDAUDHUN3UECSEXPIRECOOKIE KEEPALIVEPADDINGCHAINEDE classmethodrrrrrr src@seZdZdZeeefdddZd ee ee dddZ ed d d Z e ed dd ddZddZddZddZddZddZddZddZddZdS)!Optionz%Base class for all EDNS option types.otypecCst||_dS)z_Initialize an option. *otype*, a ``dns.edns.OptionType``, is the option type. N)rmaker))selfr)rrr__init__@szOption.__init__NfilereturncCstdS)zUConvert an option to wire format. Returns a ``bytes`` or ``None``. NNotImplementedErrorr+r.rrrto_wireGszOption.to_wirer/cCstdSNr0r+rrrto_textOszOption.to_textdns.wire.Parserr)parserr/cCstdS)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``. Nr0rr)r:rrrfrom_wire_parserRs zOption.from_wire_parsercCs,|}|}||krdS||kr(dSdS)zCompare an EDNS option with another option of the same type. Returns < 0 if < *other*, 0 if == *other*, and > 0 if > *other*. r)r3)r+otherwireZowirerrr_cmp_sz Option._cmpcCs,t|tsdS|j|jkrdS||dkS)NFr isinstancer'r)rAr+r?rrr__eq__ls   z Option.__eq__cCs,t|tsdS|j|jkrdS||dkS)NTrrBrDrrr__ne__ss   z Option.__ne__cCs(t|tr|j|jkrtS||dkSNrrCr'r)NotImplementedrArDrrr__lt__zsz Option.__lt__cCs(t|tr|j|jkrtS||dkSrGrHrDrrr__le__sz Option.__le__cCs(t|tr|j|jkrtS||dkSrGrHrDrrr__ge__sz Option.__ge__cCs(t|tr|j|jkrtS||dkSrGrHrDrrr__gt__sz Option.__gt__cCs|Sr5)r7r6rrr__str__szOption.__str__)N)rrr__doc__rrstrr,rrbytesr3r7r&r<rArErFrJrKrLrMrNrrrrr'=s  r'cs~eZdZdZeeefeeefdfdd Zde e e edddZ ed d d Z e eeefd ed ddZZS) 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,dnsrdataRdataZ _as_bytesrS)r+r)rS __class__rrr,s zGenericOption.__init__Nr-cCs|r||jdS|jSdSr5)writerSr2rrrr3s zGenericOption.to_wirer4cCs d|jS)Nz Generic %dr(r6rrrr7szGenericOption.to_textr8r9cCs|||Sr5 get_remainingr;rrrr<szGenericOption.from_wire_parser)N)rrrrOrrrPrQr,rrr3r7r&r'r< __classcell__rrrXrrRs$ rRcseZdZdZdeeeedfdd Zeddd Ze ee d d d Z dee ee d ddZeeeefde dddZZS) ECSOptionz!EDNS Client Subnet (ECS, RFC7871)Nr)addresssrclenscopelenc s^ttjtj|}|tjkrjd|_ |dkr6d}tj j |}tj j |dd}tj j |dd}nX|tjkrd|_ |dkrd}tj j |}tj j |dd}tj j |dd}ntd |dk st||_||_||_tj||}tt|d }|d||_|d }|dkrZtd t|jd ddd |>@}|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. N8rr= zBad address family @r Br>)rTr,rrrUZinetZaf_for_addresssocketAF_INET6familyrVrWZ_as_ipv6_address_as_intAF_INETZ_as_ipv4_address ValueErrorAssertionErrorr_r`ra inet_ptonintmathceiladdrdatastructpackord) r+r_r`raafrunbytesnbitslastrXrrr,s8      &zECSOption.__init__r4cCsd|j|j|jS)NzECS {}/{} scope/{})formatr_r`rar6rrrr7szECSOption.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&tk rtd d |YnXz t|} Wn(tk rtd d |YnXt|| |S) aConvert 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)splitlenror}countrrr^) r~Zoptional_prefixtokensZecs_textZ n_slashesr_ZtsrclenZtscopescoper`rrr from_texts<          zECSOption.from_textr-cCs6td|j|j|j|j}|r.||dS|SdS)N!HBB)rvrwrlr`rarurZr+r.valuerrrr3s  zECSOption.to_wirer8r9c Cs|d\}}}tt|d}||}|dkrRd|}tj|d|} n.|dkrxd|}tj|d|} nt d|| ||S) Nrrgr=rbzunsupported family) Z get_structrrrsrt get_bytesrUZipv4 inet_ntoaZipv6ro) rr)r:rlsrcrZaddrlenprefixpadaddrrrrr<&s zECSOption.from_wire_parser)Nr)N)rrrrOrPrrrr,r7 staticmethodr'rrrQr3r&rrr<r]rrrXrr^s/8  r^c@s|eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZeddZdS)EDECoderr=rbrrrr r r r r rrrrrrecCsdSrrrrrrrTszEDECode._maximumN)rrrOTHERZUNSUPPORTED_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&rrrrrr9s6rcseZdZdZddddddhZdeeefeed fd d Z ed d dZ dee ee dddZ eeeefdedddZZS) EDEOptionz!Extended DNS Error (EDE, RFC8914)ZDNSKEYZDSZDNSSECZRRSIGsZNSECZNXDOMAINN)coder~cs>ttjt||_|dk r4t|ts4t 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%rr*rrCrPror~)r+rr~rXrrr,^s  zEDEOption.__init__r4csndj}jtkrPtj}dfdd|dD}|d|d7}jdk rj|dj7}|S) NzEDE  c3s$|]}|jkr|n|VqdSr5)_preserve_casetitle).0wordr6rr qsz$EDEOption.to_text.._z ()z: )rrr7joinrr~)r+outputdescrr6rr7ms    zEDEOption.to_textr-cCsBtd|j}|jdk r(||jd7}|r:||dS|SdS)Nz!Hutf8)rvrwrr~encoderZrrrrr3zs  zEDEOption.to_wirer8r9cCsLt|}|}|r>|ddkr2|dd}|d}nd}|||S)Nr>rr)rr*Z get_uint16r\decode)rr)r:rr~Zbtextrrrr<s   zEDEOption.from_wire_parser)N)N)rrrrOrrrrPrr,r7rrQr3r&rr'r<r]rrrXrrYs"   rcsheZdZedfdd ZdeeedddZedd d Z e e e efe jjed d d ZZS) NSIDOption)nsidcsttj||_dSr5)rTr,rrr)r+rrXrrr,szNSIDOption.__init__Nr-cCs|r||jdS|jSdSr5)rZrr2rrrr3s zNSIDOption.to_wirer4cCs:tdd|jDr |j}nt|j}d|S)Ncss|]}|dko|dkVqdS)rf~Nr)rcrrrrsz%NSIDOption.to_text..zNSID )allrrbinasciihexlify)r+rrrrr7s zNSIDOption.to_textr9cCs ||Sr5r[r;rrrr<szNSIDOption.from_wire_parser)N)rrrrQr,rrr3rPr7r&rrrUr@Parserr'r<r]rrrXrrs r_type_to_class)r)r/cCst|}|dkrt}|S)zReturn the class for the specified option type. The GenericOption class is used if a more specific class is not known. N)rgetrR)r)rrrrget_option_classs rr8r9cCst|}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*rr<)r)r:rrrroption_from_wire_parsers r)r)r@currentolenr/c Cs:tj||}||t||W5QRSQRXdS)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@rZ restrict_tor)r)r@rrr:rrroption_from_wires r)implementationr)r/cCs |t|<dS)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)rr)rrr register_typesr),rOrrsrjrvtypingrrrrZdns.enumrUZdns.inetZ dns.rdataZdns.wireenumIntEnumrr'rRr^rrrrr%rr__annotations__rrPrrQrrrrrrrr r!r"r#r$rrrrs^U  =