ó
    ÌÅLgö+  ã                   óˆ   • S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSr	Sr
SrSr\R                  S 5       r " S S5      rg)	z*Help for building DNS wire format messagesé    Né   é   é   c              #   óž  #   • U R                  SU-  5        U R                  5       nS v •  U R                  5       nX2-
  nUS:”  aI   U R                  X!-
  5         U R                  UR                  US5      5         U R                  U5        g g ! [         a    [
        R                  R                  ef = f! U R                  U5        f = f7f)Nó    r   Úbig)ÚwriteÚtellÚseekÚto_bytesÚOverflowErrorÚdnsÚ	exceptionÚ	FormError)ÚoutputÚlength_lengthÚstartÚendÚlengths        Ú./usr/lib/python3/dist-packages/dns/renderer.pyÚprefixed_lengthr   #   s¯   é € à
‡L�L�˜-Ñ'Ô(Ø�K‰K‹M€EÛ	Ø
�+‰+‹-€CØ‰[€FØ�ƒzð	Ø�K‰K˜Ñ-Ô.ð.Ø—‘˜VŸ_™_¨]¸EÓBÕCð �K‰K˜Õð øô
 !ó .Ü—m‘m×-Ñ-Ð-ð.ûð �K‰K˜Õüs0   ‚ACÁB7 Á!B Á<CÂ%B4Â4B7 Â7C
Ã
Cc                   ó`  • \ rS rSrSrSS jrS rS r\R                  S 5       r
\R                  S 5       r\R                  R                  4S	 jrS
 rS rSS jrSS jr\R(                  R*                  4S jr\R(                  R*                  4S jrS rS rS rS\SS4S jrSS jrSrg)ÚRendereré5   a&  Helper class for building DNS wire-format messages.

Most applications can use the higher-level L{dns.message.Message}
class and its to_wire() method to generate wire-format messages.
This class is for those applications which need finer control
over the generation of messages.

Typical use::

    r = dns.renderer.Renderer(id=1, flags=0x80, max_size=512)
    r.add_question(qname, qtype, qclass)
    r.add_rrset(dns.renderer.ANSWER, rrset_1)
    r.add_rrset(dns.renderer.ANSWER, rrset_2)
    r.add_rrset(dns.renderer.AUTHORITY, ns_rrset)
    r.add_rrset(dns.renderer.ADDITIONAL, ad_rrset_1)
    r.add_rrset(dns.renderer.ADDITIONAL, ad_rrset_2)
    r.add_edns(0, 0, 4096)
    r.write_header()
    r.add_tsig(keyname, secret, 300, 1, 0, '', request_mac)
    wire = r.get_wire()

If padding is going to be used, then the OPT record MUST be
written after everything else in the additional section except for
the TSIG (if any).

output, an io.BytesIO, where rendering is written

id: the message id

flags: the message flags

max_size: the maximum size of the message

origin: the origin to use when rendering relative names

compress: the compression table

section: an int, the section currently being rendered

counts: list of the number of RRs in each section

mac: the MAC of the rendered message (if TSIG was used)
Nc                 ó>  • [         R                  " 5       U l        Uc  [        R                  " SS5      U l        OXl        X l        X0l        X@l        0 U l	        [        U l        / SQU l        U R                  R                  S5        SU l        SU l        SU l        g)zInitialize a new renderer.Nr   éÿÿ  )r   r   r   r   s               Ú F)ÚioÚBytesIOr   ÚrandomÚrandintÚidÚflagsÚmax_sizeÚoriginÚcompressÚQUESTIONÚsectionÚcountsr	   ÚmacÚreservedÚ
was_padded)Úselfr"   r#   r$   r%   s        r   Ú__init__ÚRenderer.__init__b   sx   € ô —j’j“lˆŒØ‰:Ü—n’n Q¨Ó.ˆD�GàŒGØŒ
Ø ŒØŒØˆŒÜˆŒÚ"ˆŒØ�‰×Ñ˜,Ô'ØˆŒØˆŒØˆ�ó    c                 ó  • U R                   R                  U5        U R                   R                  5         / nU R                  R	                  5        H  u  p4XA:¼  d  M  UR                  U5        M     U H  nU R                  U	 M     g)z�Truncate the output buffer at offset *where*, and remove any
compression table entries that pointed beyond the truncation
point.
N)r   r   Útruncater&   ÚitemsÚappend)r-   ÚwhereÚkeys_to_deleteÚkÚvs        r   Ú	_rollbackÚRenderer._rollbacku   so   € ð 	�‰×Ñ˜ÔØ�‰×ÑÔØˆØ—M‘M×'Ñ'Ö)‰DˆAØ�zØ×%Ñ% aÖ(ñ *ó  ˆAØ—‘˜aÒ ò  r0   c                 ó†   • U R                   U:w  a1  U R                   U:”  a  [        R                  R                  eXl         gg)zôSet the renderer's current section.

Sections must be rendered order: QUESTION, ANSWER, AUTHORITY,
ADDITIONAL.  Sections may be empty.

Raises dns.exception.FormError if an attempt was made to set
a section value less than the current section.
N)r(   r   r   r   )r-   r(   s     r   Ú_set_sectionÚRenderer._set_section„   s6   € ð �<‰<˜7Ó"Ø�|‰|˜gÓ%Ü—m‘m×-Ñ-Ð-Ø"�Lð #r0   c              #   óî   #   • U R                   R                  5       nUv •  U R                   R                  5       U R                  :”  a+  U R                  U5        [        R
                  R                  eg 7f©N)r   r
   r$   r9   r   r   ÚTooBig)r-   r   s     r   Ú_track_sizeÚRenderer._track_size“   sV   é € à—‘× Ñ Ó"ˆØŠØ�;‰;×ÑÓ §¡Ó-Ø�N‰N˜5Ô!Ü—-‘-×&Ñ&Ð&ð .ùs   ‚A3A5c              #   óö   #   • U R                   R                  5       n U R                   R                  U5        S v •  U R                   R                  U5        g ! U R                   R                  U5        f = f7fr?   )r   r
   r   )r-   r5   Úcurrents      r   Ú_temporarily_seek_toÚRenderer._temporarily_seek_to›   sU   é € à—+‘+×"Ñ"Ó$ˆð	&Ø�K‰K×Ñ˜UÔ#Ûà�K‰K×Ñ˜WÕ%øˆD�K‰K×Ñ˜WÕ%üs   ‚A9žA ½A9ÁA6Á6A9c                 óz  • U R                  [        5        U R                  5          UR                  U R                  U R
                  U R                  5        U R                  R                  [        R                  " SX#5      5        SSS5        U R                  [        ==   S-  ss'   g! , (       d  f       N*= f)zAdd a question to the message.z!HHNr   )r<   r'   rA   Úto_wirer   r&   r%   r	   ÚstructÚpackr)   )r-   ÚqnameÚrdtypeÚrdclasss       r   Úadd_questionÚRenderer.add_question¤   s{   € ð 	×Ñœ(Ô#Ø×ÑÕØ�M‰M˜$Ÿ+™+ t§}¡}°d·k±kÔBØ�K‰K×ÑœfŸkšk¨%°ÓAÔB÷  ð 	�‰”HÓ Ñ"Ô÷  Õús   ¦A"B,Â,
B:c                 ó  • U R                  U5        U R                  5          UR                  " U R                  U R                  U R
                  40 UD6nSSS5        U R                  U==   W-  ss'   g! , (       d  f       N&= f)zrAdd the rrset to the specified section.

Any keyword arguments are passed on to the rdataset's to_wire()
routine.
N©r<   rA   rH   r   r&   r%   r)   )r-   r(   ÚrrsetÚkwÚns        r   Ú	add_rrsetÚRenderer.add_rrset­   sc   € ð 	×Ñ˜'Ô"Ø×ÑÕØ—’˜dŸk™k¨4¯=©=¸$¿+¹+ÑLÈÑLˆA÷  à�‰�GÓ Ñ!Ô÷  Õúó   ¢4A6Á6
Bc                 ó  • U R                  U5        U R                  5          UR                  " X R                  U R                  U R
                  40 UD6nSSS5        U R                  U==   W-  ss'   g! , (       d  f       N&= f)z¡Add the rdataset to the specified section, using the specified
name as the owner name.

Any keyword arguments are passed on to the rdataset's to_wire()
routine.
NrQ   )r-   r(   ÚnameÚrdatasetrS   rT   s         r   Úadd_rdatasetÚRenderer.add_rdataset¹   sf   € ð 	×Ñ˜'Ô"Ø×ÑÕØ× Ò  §{¡{°D·M±MÀ4Ç;Á;ÑUÐRTÑUˆA÷  à�‰�GÓ Ñ!Ô÷  ÕúrW   c                 ó  • U(       aï  UR                   nUS:¼  d   eUS   nU R                  R                  5       U-   U-   nXr-  nU(       a  SX(-
  -  nOSn[        UR                  5      n	U	R                  [        R                  R                  [        R                  R                  R                  U5      5        [        R                  R                  R                  XVR                  U	5      nSU l        U R!                  ["        U5        g)a-  Add *opt* to the additional section, applying padding if desired.  The
padding will take the specified precomputed OPT size and TSIG size into
account.

Note that we don't have reliable way of knowing how big a GSS-TSIG digest
might be, so we we might not get an even multiple of the pad in that case.é   r   r   r0   TN)Úttlr   r
   ÚlistÚoptionsr4   r   ÚednsÚGenericOptionÚ
OptionTypeÚPADDINGÚmessageÚMessageÚ	_make_optrM   r,   rU   Ú
ADDITIONAL)
r-   ÚoptÚpadÚopt_sizeÚ	tsig_sizer_   Ú	opt_rdataÚsize_without_paddingÚ	remainderra   s
             r   Úadd_optÚRenderer.add_optÆ   sÒ   € ö Ø—'‘'ˆCØ˜r“>Ð!�>Ø˜A™ˆIØ#'§;¡;×#3Ñ#3Ó#5¸Ñ#@À9Ñ#LÐ Ø,Ñ2ˆIÞØ ¡Ñ1‘à�Ü˜9×,Ñ,Ó-ˆGØ�N‰Nœ3Ÿ8™8×1Ñ1´#·(±(×2EÑ2E×2MÑ2MÈsÓSÔTÜ—+‘+×%Ñ%×/Ñ/°×5FÑ5FÈÓPˆCØ"ˆDŒOØ�‰”z 3Õ'r0   c                 ó’   • US-  nX!S-  -  n[         R                  R                  R                  X#U5      nU R	                  U5        g)z&Add an EDNS OPT record to the message.l   ÿ~ é   N)r   rf   rg   rh   rq   )r-   rb   Ú	ednsflagsÚpayloadra   rj   s         r   Úadd_ednsÚRenderer.add_ednsÝ   sB   € ð 	�ZÑˆ	Ø˜R‘ZÑˆ	Ü�k‰k×!Ñ!×+Ñ+¨IÀÓHˆØ�‰�SÕr0   c	           
      óÔ  • U R                   R                  5       n	[        U[        R                  R
                  5      (       a  Un
O [        R                  R                  XU5      n
[        R                  R                  R                  XSUSXEU5      n[        R                  R                  XšUS   [        [        R                  " 5       5      U5      u  p¼U R                  X±5        g)z$Add a TSIG signature to the message.r   r0   N©r   ÚgetvalueÚ
isinstancer   ÚtsigÚKeyrf   rg   Ú
_make_tsigÚsignÚintÚtimeÚ_write_tsig)r-   ÚkeynameÚsecretÚfudger"   Ú
tsig_errorÚ
other_dataÚrequest_macÚ	algorithmÚsÚkeyr}   Ú_s                r   Úadd_tsigÚRenderer.add_tsigæ   s¤   € ð �K‰K× Ñ Ó"ˆä�fœcŸh™hŸl™l×+Ñ+Ø‰Cä—(‘(—,‘,˜w°	Ó:ˆCÜ�{‰{×"Ñ"×-Ñ-Ø  5¨#¨r¸zó
ˆô —H‘H—M‘M !¨$¨q©'´3´t·y²y³{Ó3CÀ[ÓQ‰	ˆØ×Ñ˜Õ'r0   c
           
      óØ  • U R                   R                  5       n
[        U[        R                  R
                  5      (       a  UnO [        R                  R                  X#U	5      n[        R                  R                  R                  X)SUSXVU5      n[        R                  R                  X«US   [        [        R                  " 5       5      X�S5      u  pÁU R                  XÂ5        U$ )aQ  Add a TSIG signature to the message. Unlike add_tsig(), this can be
used for a series of consecutive DNS envelopes, e.g. for a zone
transfer over TCP [RFC2845, 4.4].

For the first message in the sequence, give ctx=None. For each
subsequent message, give the ctx that was returned from the
add_multi_tsig() call for the previous message.r   r0   Trz   )r-   Úctxr„   r…   r†   r"   r‡   rˆ   r‰   rŠ   r‹   rŒ   r}   s                r   Úadd_multi_tsigÚRenderer.add_multi_tsigÿ   s°   € ð( �K‰K× Ñ Ó"ˆä�fœcŸh™hŸl™l×+Ñ+Ø‰Cä—(‘(—,‘,˜w°	Ó:ˆCÜ�{‰{×"Ñ"×-Ñ-Ø  5¨#¨r¸zó
ˆô —h‘h—m‘mØ�D˜‘GœS¤§¢£Ó-¨{Àó
‰ˆð 	×Ñ˜Ô'Øˆ
r0   c           	      óv  • U R                   (       a  S nOU R                  nU R                  [        5        U R	                  5          UR                  U R                  X0R                  5        U R                  R                  [        R                  " S[        R                  R                  [        R                  R                  S5      5        [!        U R                  S5         UR                  U R                  5        S S S 5        S S S 5        U R"                  [        ==   S-  ss'   U R%                  S5         U R                  R                  [        R                  " SU R"                  [           5      5        S S S 5        g ! , (       d  f       N�= f! , (       d  f       N–= f! , (       d  f       g = f)Nz!HHIr   r   r   é
   z!H)r,   r&   r<   ri   rA   rH   r   r%   r	   rI   rJ   r   Ú	rdatatypeÚTSIGÚ
rdataclassÚANYr   r)   rE   )r-   r}   r„   r&   s       r   rƒ   ÚRenderer._write_tsig"  s  € Ø�?�?Ø‰Hà—}‘}ˆHØ×Ñœ*Ô%Ø×ÑÕØ�O‰O˜DŸK™K¨·;±;Ô?Ø�K‰K×ÑÜ—’˜F¤C§M¡M×$6Ñ$6¼¿¹×8JÑ8JÈAÓNôô ! §¡¨aÕ0Ø—‘˜TŸ[™[Ô)÷ 1÷  ð 	�‰”JÓ 1Ñ$ÓØ×&Ñ& rÕ*Ø�K‰K×ÑœfŸkšk¨$°·±¼JÑ0GÓHÔI÷ +Ð*÷	 1Õ0ú÷  Õú÷ +Õ*ús2   ÁBFÃ%FÄFÄ=AF*Æ
F	ÆFÆ
F'Æ*
F8c                 óT  • U R                  S5         U R                  R                  [        R                  " SU R
                  U R                  U R                  S   U R                  S   U R                  S   U R                  S   5      5        SSS5        g! , (       d  f       g= f)zžWrite the DNS message header.

Writing the DNS message header is done after all sections
have been rendered, but before the optional TSIG signature
is added.
r   z!HHHHHHr   r   r   N)rE   r   r	   rI   rJ   r"   r#   r)   ©r-   s    r   Úwrite_headerÚRenderer.write_header4  sy   € ð ×&Ñ& qÕ)Ø�K‰K×ÑÜ—’ØØ—G‘GØ—J‘JØ—K‘K ‘NØ—K‘K ‘NØ—K‘K ‘NØ—K‘K ‘Nóô
÷ *×)Ö)ús   ’A>BÂ
B'c                 ó6   • U R                   R                  5       $ )zReturn the wire format message.)r   r{   rœ   s    r   Úget_wireÚRenderer.get_wireI  s   € ð �{‰{×#Ñ#Ó%Ð%r0   ÚsizeÚreturnc                 ó®   • US:  a  [        S5      eXR                  :”  a  [        S5      eU =R                  U-  sl        U =R                  U-  sl        g)zReserve *size* bytes.r   z$reserved amount must be non-negativez)cannot reserve more than the maximum sizeN)Ú
ValueErrorr$   r+   )r-   r¢   s     r   ÚreserveÚRenderer.reserveN  sG   € à�!‹8ÜÐCÓDÐDØ—-‘-ÓÜÐHÓIÐIØ�Š˜Ñ�Ø�Š˜ÑŽr0   c                 óP   • U =R                   U R                  -  sl         SU l        g)zRelease the reserved bytes.r   N)r$   r+   rœ   s    r   Úrelease_reservedÚRenderer.release_reservedW  s   € à�Š˜Ÿ™Ñ&�Øˆ�r0   )r&   r)   r#   r"   r*   r$   r%   r   r+   r(   r,   )Nr   r   N)r   r   r   r?   )r£   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r.   r9   r<   Ú
contextlibÚcontextmanagerrA   rE   r   r˜   ÚINrN   rU   r[   rq   rw   r}   Údefault_algorithmrŽ   r’   rƒ   r�   r    r�   r¦   r©   Ú__static_attributes__© r0   r   r   r   5   sÅ   † ñ*ôX ò&!ò#ð ×Ññ'ó ð'ð ×Ññ&ó ð&ð 36·.±.×2CÑ2Cô #ò
"ò"ô(ô.ð$ —(‘(×,Ñ,ô(ðF —(‘(×,Ñ,ô!òFJò$ò*&ð
˜Cð  Dô ÷r0   r   )r¯   r°   r   r    rI   r‚   Údns.exceptionr   Údns.tsigr'   ÚANSWERÚ	AUTHORITYri   r±   r   r   rµ   r0   r   Ú<module>rº      sY   ðñ$ 1ã Û 	Û Û Û ã Û à€Ø	
€Ø€	Ø€
ð ×Ññó ð÷"eò er0   