U mfs @s~UdZddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z m Z m Z mZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZdZdZGdddejjZed fd d Zed fd d Z ed fddZ!dZ"ddZ#ddZ$ej%j&Z'ej%j%GdddZ(ej%j%Gddde(Z)iZ*e e ej+j,ej-j.fe fe/d<dZ0ddZ1d,eej+j,e2feej-j.e2feej3j4e2fe ej5j6e7e ej5j6e ej5j8e(dddZ9d-eej+j,e2feej-j.e2fej:j;e ej5j6e(d d!d"Ze>e ej5j6e(d#d$d%Z?Gd&d'd'ejjZ@d(ej+jAfe e>e2e7ej+j,dd)d*d+ZBdS)/z DNS rdata.N) import_module)AnyDictOptionalTupleUnion Tc@seZdZdZdS)NoRelativeRdataOrderingzAn attempt was made to do an ordered comparison of one or more rdata with relative names. The only reliable way of sorting rdata is to use non-relativized rdata. N)__name__ __module__ __qualname____doc__rr7/opt/hc_python/lib/python3.8/site-packages/dns/rdata.pyr 3sr  cs6s S|fddtdtDS)zXBreak a binary string into chunks of chunksize characters separated by a space. csg|]}||qSrr).0i chunksizedatarr Csz_wordbreak..r)decodejoinrangelen)rr separatorrrr _wordbreak;s rcKstt|||S)zConvert a binary string into its hex encoding, broken up into chunks of chunksize characters separated by a separator. )rbinasciihexlifyrrrkwrrr_hexifyJsr!cKstt|||S)zConvert a binary string into its base64 encoding, broken up into chunks of chunksize characters separated by a separator. )rbase64 b64encoderrrr _base64ifyRsr$s"\cCszt|tr|}t|ts$t|}d}|D]H}|tkrJ|dt|7}q,|dkrh|dkrh|t|7}q,|d|7}q,|S)z7Escape the characters in a quoted string which need it.\rz\%03d) isinstancestrencode bytearray __escapedchr)Zqstringtextcrrr _escapify_s  r0cCsFtt|dddD]$}||dkr|d|dSq|ddS)zDetermine the index of greatest byte that isn't all zeros, and return the bitmap that contains all the bytes less than that index. r)rr)whatrrrr_truncate_bitmaprs r4c @seZdZdZdddgZddZddZd d Zd d Ze j j d ddZ e d ddZd_ee jjeeeefedddZd`eeee jjee jjeedddZdaeeee jjee jjeedddZdbee jjdddd Zdcee jjedd!d"Zd#d$Zd%d&Zd'd(Zd)d*Z d+d,Z!d-d.Z"d/d0Z#d1d2Z$d3d4Z%d5d6Z&e'dde j(j)e j j e j*j+ee jjeee jjdd7d8d9Z,e'dee j(j)e j j e j-j.ee jjdd:d;d<Z/edd=d>d?Z0e'd@dAZ1e'dBdCZ2e'dfeeee eedDdEdFZ3e'dGdHZ4e'dIdJZ5e'dKdLZ6e'dMdNZ7e'dOdPZ8e'dgdQdRZ9e'dSdTZ:e'dUdVZ;e'dWdXZe'd]d^Z?dS)hRdataz#Base class for all DNS rdata types.rdclassrdtype rdcommentcCs"|||_|||_d|_dS)zInitialize an rdata. *rdclass*, an ``int`` is the rdataclass of the Rdata. *rdtype*, an ``int`` is the rdatatype of the Rdata. N)_as_rdataclassr6 _as_rdatatyper7r8)selfr6r7rrr__init__s  zRdata.__init__cCstjdd|jjDS)Ncss|]}t|dgVqdS) __slots__N)getattr)rclsrrr sz'Rdata._get_all_slots..) itertoolschain from_iterable __class____mro__r;rrr_get_all_slotss zRdata._get_all_slotscCs$i}|D]}t||||<q |SN)rGr>)r;stateslotrrr __getstate__s  zRdata.__getstate__cCs<|D]\}}t|||qt|ds8t|dddS)Nr8)itemsobject __setattr__hasattr)r;rIrJvalrrr __setstate__s zRdata.__setstate__)returncCstjjS)aReturn the type a Rdata covers. DNS SIG/RRSIG rdatas apply to a specific type; this type is returned by the covers() function. If the rdata type is not SIG or RRSIG, dns.rdatatype.NONE is returned. This is useful when creating rdatasets, allowing the rdataset to contain only RRSIGs of a particular type, e.g. RRSIG(NS). Returns a ``dns.rdatatype.RdataType``. )dns rdatatypeNONErFrrrcoverss z Rdata.coverscCs|d>|jBS)zReturn a 32-bit type value, the least significant 16 bits of which are the ordinary DNS type, and the upper 16 bits of which are the "covered" type, if any. Returns an ``int``. )rVr7rFrrrextended_rdatatypeszRdata.extended_rdatatypeNTorigin relativizer rRcKstdS)zEConvert an rdata to text format. Returns a ``str``. NNotImplementedErrorr;rZr[r rrrto_texts z Rdata.to_textF)filecompressrZ canonicalizerRcCstdSrHr\r;r`rarZrbrrr_to_wireszRdata._to_wirecCs8|r|||||St}||||||SdS)zSConvert an rdata to wire format. Returns a ``bytes`` or ``None``. N)rdioBytesIOgetvalue)r;r`rarZrbfrrrto_wires z Rdata.to_wirezdns.rdata.GenericRdata)rZrRcCstj|j|j|j|dS)zrCreates a dns.rdata.GenericRdata equivalent of this rdata. Returns a ``dns.rdata.GenericRdata``. )rZ)rSrdata GenericRdatar6r7rir;rZrrr to_generics  zRdata.to_genericcCs|j|ddS)zConvert rdata to a format suitable for digesting in hashes. This is also the DNSSEC canonical form. Returns a ``bytes``. T)rZrb)rirlrrr to_digestableszRdata.to_digestablecCsf|}|tjjkrd}ndtj|d}dtj|jdtj|j|dt|dS)Nr%()z) rVrSrTrUr_ rdataclassr6r7r))r;rVZctextrrr__repr__s(   zRdata.__repr__cCs|SrH)r_rFrrr__str__sz Rdata.__str__cCsz|}d}Wn.tjjk r>tr6|tjj}d}YnXz|}d}Wn.tjjk r~trv|tjj}d}YnXtr||kr|rdSdSn |s|rt||krdS||krdSdSdS)aCompare an rdata with another rdata of the same rdtype and rdclass. For rdata with only absolute names: Return < 0 if self < other in the DNSSEC ordering, 0 if self == other, and > 0 if self > other. For rdata with at least one relative names: The rdata sorts before any rdata with only absolute names. When compared with another relative rdata, all names are made absolute as if they were relative to the root, as the proper origin is not available. While this creates a stable ordering, it is NOT guaranteed to be the DNSSEC ordering. In the future, all ordering comparisons for rdata with relative names will be disallowed. FTr2r1rN)rnrSnameNeedAbsoluteNameOrOrigin_allow_relative_comparisonsrootr )r;otherour our_relativetheirtheir_relativerrr_cmps4  z Rdata._cmpcCst|tsdS|j|jks&|j|jkr*dSd}d}z |}Wn*tjjk rh|tjj}d}YnXz |}Wn*tjjk r|tjj}d}YnX||krdS||kS)NFT) r(r5r6r7rnrSrvrwry)r;rzr|r~r{r}rrr__eq__Fs&     z Rdata.__eq__cCs6t|tsdS|j|jks&|j|jkr*dS|| S)NT)r(r5r6r7rr;rzrrr__ne__[s  z Rdata.__ne__cCs4t|tr"|j|jks"|j|jkr&tS||dkSNrr(r5r6r7NotImplementedrrrrr__lt__bs  z Rdata.__lt__cCs4t|tr"|j|jks"|j|jkr&tS||dkSrrrrrr__le__ks  z Rdata.__le__cCs4t|tr"|j|jks"|j|jkr&tS||dkSrrrrrr__ge__ts  z Rdata.__ge__cCs4t|tr"|j|jks"|j|jkr&tS||dkSrrrrrr__gt__}s  z Rdata.__gt__cCst|tjjSrH)hashrnrSrvryrFrrr__hash__szRdata.__hash__)r6r7tokrZr[ relativize_torRcCstdSrHr\)r?r6r7rrZr[rrrr from_texts zRdata.from_textr6r7parserrZrRcCstdSrHr\r?r6r7rrZrrrfrom_wire_parserszRdata.from_wire_parser)kwargsrRc stjj}D]F}|dkr q||kr)rkeyrr;rrr@sz Rdata.replace..N) inspect signaturer< parametersAttributeErrorformatrDr rr8rMrN)r;rrrargsrdr8rrrreplaces0  z Rdata.replacecCstjj|SrH)rSrs RdataClassmaker?valuerrrr9szRdata._as_rdataclasscCstjj|SrH)rSrT RdataTyperrrrrr:szRdata._as_rdatatype)rr* max_lengthempty_okrRcCs||rt|tr|}n,t|tr,t|}nt|tr<|}ntd|dk r`t||kr`td|sxt|dkrxtd|S)Nz not bytesztoo longrzempty bytes not allowed)r(r)r*r+bytes ValueErrorr)r?rr*rrZbvaluerrr _as_bytess    zRdata._as_bytescCs0t|trtj|St|tjjs,td|S)Nz not a name)r(r)rSrvrNamerrrrr_as_names   zRdata._as_namecCs.t|tstd|dks"|dkr*td|S)Nnot an integerrz not a uint8r(intrrrrr _as_uint8s  zRdata._as_uint8cCs.t|tstd|dks"|dkr*td|S)Nrriz not a uint16rrrrr _as_uint16s  zRdata._as_uint16cCs.t|tstd|dks"|dkr*td|S)Nrrlz not a uint32rrrrr _as_uint32 s  zRdata._as_uint32cCs.t|tstd|dks"|dkr*td|S)Nrrlz not a uint48rrrrr _as_uint48s  zRdata._as_uint48cCsFt|tstd|dk r*||kr*td|dk rB||krBtd|S)Nrzvalue too smallzvalue too larger)r?rlowhighrrr_as_ints z Rdata._as_intcCs8t|trtj|St|tr,tj|StddS)Nznot an IPv4 address)r(r)rSZipv4rbr inet_ntoarrrrr_as_ipv4_address#s     zRdata._as_ipv4_addresscCs8t|trtj|St|tr,tj|StddS)Nznot an IPv6 address)r(r)rSZipv6rbrrrrrrr_as_ipv6_address,s     zRdata._as_ipv6_addresscCst|tr|StddS)Nz not a boolean)r(boolrrrrr_as_bool5s zRdata._as_boolcCs>t|tr||dtjjSt|tr2tj|StddS)Nrz not a TTL) r(rrrSttlZMAX_TTLr)rrrrrr_as_ttl<s    z Rdata._as_ttlcs<z |fWStk r6tfdd|DYSXdS)Nc3s|]}|VqdSrHr)rvas_valuerrr@Nsz"Rdata._as_tuple..) Exceptiontuple)r?rrrrr _as_tupleEs zRdata._as_tuplecCst|}t||SrH)listrandomshuffle)r?iterablerLrrr_processing_orderRs zRdata._processing_order)NT)NNF)NNNF)N)N)NTN)N)FNT)NN)@r r r r r=r<rGrKrQrSrTrrVrrXrrvrrrr)rr_Z CompressTyperrdrirmrnrtrurrrrrrrr classmethodrsr tokenizer TokenizerrwireParserrrr9r:rrrrrrrrrrrrrrrrrr5s               /         1             r5csreZdZdZdgZfddZdeejj e e e e fe ddd Zedd d Zdd dZedddZZS)rkzGeneric Rdata Class This class is used for rdata types for which we have no better implementation. It implements the DNS "unknown RRs" scheme. rcst||||_dSrH)superr<r)r;r6r7rrDrrr<cszGenericRdata.__init__NTrYcKsdt|jt|jf|S)Nz\# %d )rrr!r^rrrr_gszGenericRdata.to_textc Csj|}|r|jdkr&tjd|}|d} t | } t | |kr^tjd|||| S)N\#z$generic rdata does not start with \#Tz'generic rdata hex data has wrong length) r is_identifierrrS exception SyntaxErrorZget_intZ!concatenate_remaining_identifiersr*r unhexlifyr) r?r6r7rrZr[rtokenlengthhexrrrrros    zGenericRdata.from_textFcCs||jdSrH)writerrcrrrrd}szGenericRdata._to_wirecCs||||SrH)Z get_remainingrrrrrszGenericRdata.from_wire_parser)NT)NTN)NNF)N)r r r r r=r<rrSrvrrrr)rr_rrrdr __classcell__rrrrrkYs&     rk_rdata_classesz dns.rdtypesc Cst||f}|sttjj|f}|stj|}tj|}|dd}z.td t ||g}t ||}|t||f<Wnht k rz>td t d|g}t ||}|ttjj|f<|t||f<Wnt k rYnXYnX|st }|t||f<|S)N-_.ANY)rrrSrTrrsr_rrr_module_prefixr> ImportErrorrk)r6r7r?Z rdclass_text rdtype_textmodrrrget_rdata_classs2       r)r6r7rrZr[r idna_codecrRc Cs(t|trtjj||d}tjj|}tjj |}t ||}tj tj j d}|tkr|} || | r| jdkrt||||||} t||| jdt| j|}|} | | jkrtj d|dkr|||||||}|} | jdk rt|d| j|W5QRSQRXdS)a3Build an rdata object from text format. This function attempts to dynamically load a class which implements the specified rdata class and type. If there is no class-and-type-specific implementation, the GenericRdata class is used. Once a class is chosen, its from_text() class method is called with the parameters to this function. If *tok* is a ``str``, then a tokenizer is created and the string is used as its input. *rdclass*, a ``dns.rdataclass.RdataClass`` or ``str``, the rdataclass. *rdtype*, a ``dns.rdatatype.RdataType`` or ``str``, the rdatatype. *tok*, a ``dns.tokenizer.Tokenizer`` or a ``str``. *origin*, a ``dns.name.Name`` (or ``None``), the origin to use for relative names. *relativize*, a ``bool``. If true, name will be relativized. *relativize_to*, a ``dns.name.Name`` (or ``None``), the origin to use when relativizing names. If not set, the *origin* value will be used. *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA encoder/decoder to use if a tokenizer needs to be created. If ``None``, the default IDNA 2003 encoder/decoder is used. If a tokenizer is not created, then the codec associated with the tokenizer is the one that is used. Returns an instance of the chosen Rdata subclass. )rNrrz9compressed data in generic syntax form of known rdatatyper8)r(r)rSrrrsrrrTrrrExceptionWrapperrrkrZungetrrr from_wirerrriZget_eol_as_tokencommentrMrN) r6r7rrZr[rrr?rjrZgrdataZrwirerrrrsZ-     rrc Cs^tjj|}tjj|}t||}tjtjj | ||||W5QRSQRXdS)aBuild an rdata object from wire format This function attempts to dynamically load a class which implements the specified rdata class and type. If there is no class-and-type-specific implementation, the GenericRdata class is used. Once a class is chosen, its from_wire() class method is called with the parameters to this function. *rdclass*, a ``dns.rdataclass.RdataClass`` or ``str``, the rdataclass. *rdtype*, a ``dns.rdatatype.RdataType`` or ``str``, the rdatatype. *parser*, a ``dns.wire.Parser``, the parser, which should be restricted to the rdata length. *origin*, a ``dns.name.Name`` (or ``None``). If not ``None``, then names will be relativized to this origin. Returns an instance of the chosen Rdata subclass. N) rSrsrrrTrrrrZ FormErrorr)r6r7rrZr?rrrrs  r)r6r7rcurrentrdlenrZrRc Cs>tj||}||t||||W5QRSQRXdS)a1Build an rdata object from wire format This function attempts to dynamically load a class which implements the specified rdata class and type. If there is no class-and-type-specific implementation, the GenericRdata class is used. Once a class is chosen, its from_wire() class method is called with the parameters to this function. *rdclass*, an ``int``, the rdataclass. *rdtype*, an ``int``, the rdatatype. *wire*, a ``bytes``, the wire-format message. *current*, an ``int``, the offset in wire of the beginning of the rdata. *rdlen*, an ``int``, the length of the wire-format rdata *origin*, a ``dns.name.Name`` (or ``None``). If not ``None``, then names will be relativized to this origin. Returns an instance of the chosen Rdata subclass. N)rSrrZ restrict_tor)r6r7rrrrZrrrrr%s" rc@seZdZdZddhZdZdS)RdatatypeExistszDNS rdatatype already exists.r6r7zKThe rdata type with class {rdclass:d} and rdtype {rdtype:d} already exists.N)r r r r Z supp_kwargsfmtrrrrrLsrF)implementationr7r is_singletonr6rRcCsftjj|}t||}|tks,tj|r8t||dt|| ddt ||f<tj |||dS)aDynamically register a module to handle an rdatatype. *implementation*, a module implementing the type in the usual dnspython way. *rdtype*, an ``int``, the rdatatype to register. *rdtype_text*, a ``str``, the textual form of the rdatatype. *is_singleton*, a ``bool``, indicating if the type is a singleton (i.e. RRsets of the type can have only one member.) *rdclass*, the rdataclass of the type, or ``dns.rdataclass.ANY`` if it applies to all classes. rrrN) rSrTrrrrkZ is_metatyperr>rr register_type)rr7rrr6Z existing_clsrrrrVs   r)NTNN)N)N)Cr r"rrrerAr importlibrtypingrrrrrZ dns.exceptionrSZ dns.immutableZdns.ipv4Zdns.ipv6Zdns.nameZdns.rdataclassZ dns.rdatatypeZ dns.tokenizerZdns.ttlZdns.wireZ _chunksizerxrZ DNSExceptionr rr!r$r,r0r4Z immutableZconstifyZ _constifyr5rkrrsrrTr__annotations__rrr)rrrvrrZ IDNACodecrrrrrrrrINrrrrrs   Z,"     ^  *  '