
    g                        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Jr  SSKJ	r	J
r
JrJrJrJrJrJ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SKrSSKrSSKrSSKrSSKJrJrJ r   SSKJ!r!J"r"J#r#J$r$  SSK%J&r&  SSK'J(r(  SS	K)J*r*  SS
K+J,r,  SSK-J.r.J/r/  SSK0J1r1  SSK2J3r3J4r4  SSK5J6r6  \S   r7\S   r8\	\Rr                  Rt                  \Rv                  Rx                  /S4   r=S\>S\4S jr?S\\\@4   S\>4S jrAS\\\>\B\@4   S\@4S jrCS\\*\&4   S\@4S jrD " S S5      rE " S S\E5      rF\F" \R                  \R                  \R                  \R                  1\R                  \R                  \R                  1\R                  \R                  \R                  1\R                  15      rN\F" \O" 5       \O" 5       \O" 5       \O" 5       5      rP\NrQ   SaS\\R                  R                  \>4   S\R                  R                  S\\\>4   S \\R                  R                     S!\\E   S"\VS\,4S# jjrW SbS\\R                  R                  \>4   S\R                  R                  S\\\>4   S \\R                  R                     S\(4
S$ jjrXS%\
\R                  R                  \\R                  R                  \R                  R                  4   4   S&\3S\\\*      4S' jr]S(\\Rv                  Rx                  \\R                  R                  \R                  R                  4   4   S\\R                  R                  \R                  R                  4   4S) jr^S*\_S+\_S\*SS4S, jr`   ScS(\\Rv                  Rx                  \\R                  R                  \R                  R                  4   4   S&\3S%\
\R                  R                  \\R                  R                  \R                  R                  4   4   S \\R                  R                     S-\\B   S!\\E   SS4S. jjra   ScS(\\Rv                  Rx                  \\R                  R                  \R                  R                  4   4   S/\\Rv                  Rx                  \\R                  R                  \R                  R                  4   4   S%\
\R                  R                  \\R                  R                  \R                  R                  4   4   S \\R                  R                     S-\\B   S!\\E   SS4S0 jjrb       SdS(\\Rv                  Rx                  \\R                  R                  \R                  R                  4   4   S2\8S3\R                  R                  S4\*S5\\\\>\@\B4      S6\\\\>\@\B4      S7\\@   S8\VS!\\E   S \\R                  R                     S9\VS\34S: jjrc SbS(\\Rv                  Rx                  \\R                  R                  \R                  R                  4   4   S&\3S \\R                  R                     S\_4S; jjrd\6R                  S<4S=\7S\\@\>4   S>\@S?\@S\*4
S@ jjrf\6R                  S<4S=\7S\\@\>4   S>\@S?\@S\&4
SA jjrgSB\\R                  R                  \>4   SC\\\>\_4      SD\@S\\@\>4   S\>4
SE jrh SbS(\\Rv                  Rx                  \\R                  R                  \R                  R                  4   4   SF\\\\>4      S \\R                  R                     S\R                  R                  4SG jjriSH\R                  R                  S\R                  R                  4SI jrj SbS\\R                  R                  \>4   SH\R                  R                  S\\\>4   S \\R                  R                     S\R                  R                  4
SJ jjrkSH\R                  R                  S\R                  R                  4SK jrl      SeSL\Rr                  Rt                  S(\Rv                  Rx                  S3\R                  R                  SM\\\8\*4      SN\\\8\*4      S5\\\\>\@\B4      S6\\\\>\@\B4      S7\\@   S!\\E   S \\R                  R                     S9\VSS4SO jjrm           SfSP\R                  R                  SL\\Rr                  Rt                     S%\\\\8\*4         SQ\VSR\\@   S5\\\\>\@\B4      S6\\\\>\@\B4      S7\\@   SS\\1   ST\\=   S!\\E   S9\VSS4SU jjrp SbSP\R                  R                  SL\Rr                  Rt                  ST\\=   SS4SV jjrqSW rr\R                  R                  SX5      (       aA  SSYKuJvrv  SSZKwJxrx  SS[KwJyry  SS\KwJzrz  SS]KwJ{r{  SS^KwJ|r|  SS_K}J~r~Jr  SS`KJrJr  \br\ar\cr\fr\grS1rO\rr\rr\rr\rr\rrSr\R                  rG\GR                  r\R                  rH\GR                  r\GR                  r\R                  rI\GR                  r\GR                  r\GR                  r\R                  rJ\GR                  r\GR                   r\GR"                  r\GR$                  r\GR&                  r\GR(                  r\GR*                  rg)gz.Common DNSSEC-related functions and constants.    N)datetime)CallableDictListOptionalSetTupleUnioncast)	AlgorithmDSDigest	NSEC3Hash)AlgorithmKeyMismatchDeniedByPolicyUnsupportedAlgorithmValidationFailure)CDNSKEY)CDS)DNSKEY)DS)NSECBitmap)
NSEC3PARAM)RRSIGsigtime_to_posixtime)Flag)GenericPublicKeyzrsa.RSAPublicKeyzec.EllipticCurvePublicKeyzed25519.Ed25519PublicKeyzed448.Ed448PublicKey)GenericPrivateKeyzrsa.RSAPrivateKeyzec.EllipticCurvePrivateKeyzed25519.Ed25519PrivateKeyzed448.Ed448PrivateKeytextreturnc                 .    [         R                  " U 5      $ )zConvert text into a DNSSEC algorithm value.

*text*, a ``str``, the text to convert to into an algorithm value.

Returns an ``int``.
)r   	from_text)r   s    C/home/matz/Project1/venv/lib/python3.13/site-packages/dns/dnssec.pyalgorithm_from_textr$   L   s     t$$    valuec                 .    [         R                  " U 5      $ )zConvert a DNSSEC algorithm value to text

*value*, a ``dns.dnssec.Algorithm``.

Returns a ``str``, the name of a DNSSEC algorithm.
)r   to_textr&   s    r#   algorithm_to_textr*   W   s     U##r%   c                 "   [        U [        5      (       a  [        U R                  5       5      $ [        U [        5      (       a  [        U 5      $ [        U [        5      (       a  [        U 5      $ [        U [        5      (       a  U $ [        S5      e)z%Convert various format to a timestampzUnsupported timestamp type)
isinstancer   int	timestampstrr   float	TypeErrorr)   s    r#   to_timestampr2   b   sn    %""5??$%%	E3		#E**	E5	!	!5z	E3		455r%   keyc                 d   U R                  5       nUc   eU R                  [        R                  :X  a  US   S-  US   -   $ Sn[	        [        U5      S-  5       H  nX!SU-     S-  USU-  S-      -   -  nM     [        U5      S-  S:w  a  X![        U5      S-
     S-  -  nX"S-	  S-  -  nUS-  $ )	zReturn the key id (a 16-bit number) for the specified key.

*key*, a ``dns.rdtypes.ANY.DNSKEY.DNSKEY``

Returns an ``int`` between 0 and 65535
   r            i  )to_wire	algorithmr   RSAMD5rangelen)r3   rdatatotalis       r#   key_idrC   p   s     KKME
}}	(((b	Q%)++s5zQ'AAEla'5Q+;;;E (u:>Q3u:>*a//E2+''v~r%   c                   b    \ rS rSrS rS\S\4S jrS\S\4S jrS\	S\4S jr
S\	S\4S jrS	rg
)Policy   c                     g N )selfs    r#   __init__Policy.__init__   s    r%   _r    c                     gNFrI   rJ   rM   s     r#   
ok_to_signPolicy.ok_to_sign       r%   c                     grO   rI   rP   s     r#   ok_to_validatePolicy.ok_to_validate   rS   r%   c                     grO   rI   rP   s     r#   ok_to_create_dsPolicy.ok_to_create_ds   rS   r%   c                     grO   rI   rP   s     r#   ok_to_validate_dsPolicy.ok_to_validate_ds   rS   r%   rI   N)__name__
__module____qualname____firstlineno__rK   r   boolrQ   rU   r   rX   r[   __static_attributes__rI   r%   r#   rE   rE      sS    F t  4  d 8  r%   rE   c                   p   ^  \ rS rSrU 4S jrS\S\4S jrS\S\4S jrS\	S\4S jr
S\	S\4S	 jrS
rU =r$ )
SimpleDeny   c                 R   > [         TU ]  5         Xl        X l        X0l        X@l        g rH   )superrK   
_deny_sign_deny_validate_deny_create_ds_deny_validate_ds)rJ   	deny_signdeny_validatedeny_create_dsdeny_validate_ds	__class__s        r#   rK   SimpleDeny.__init__   s%    #+-!1r%   r3   r    c                 4    UR                   U R                  ;  $ rH   )r<   rh   rJ   r3   s     r#   rQ   SimpleDeny.ok_to_sign   s    }}DOO33r%   c                 4    UR                   U R                  ;  $ rH   )r<   ri   rs   s     r#   rU   SimpleDeny.ok_to_validate   s    }}D$7$777r%   r<   c                     XR                   ;  $ rH   )rj   rJ   r<   s     r#   rX   SimpleDeny.ok_to_create_ds   s     4 444r%   c                     XR                   ;  $ rH   )rk   rx   s     r#   r[   SimpleDeny.ok_to_validate_ds   s     6 666r%   )rj   rh   ri   rk   )r]   r^   r_   r`   rK   r   ra   rQ   rU   r   rX   r[   rb   __classcell__)rp   s   @r#   rd   rd      sY    24f 4 48& 8T 85 5d 578 7 7 7r%   rd   Fnamer<   originpolicy
validatingc           	         Uc  [         n [        U[        5      (       a  [        UR	                  5          nU(       a  UR                  nOUR                  nU" U5      (       d  [        e[        U[        [        45      (       d  [        S5      eU[        R                  :X  a  [        R                  " 5       nOcU[        R                   :X  a  [        R"                  " 5       nO9U[        R$                  :X  a  [        R&                  " 5       nO[        SU S35      e[        U [        5      (       a  [(        R*                  R-                  X5      n U R/                  5       R1                  5       nUR1                  US9n	Ub  U	c   eUR3                  U5        UR3                  U	5        UR5                  5       n
[6        R8                  " S[;        U5      UR<                  U5      U
-   n[(        R>                  RA                  [(        RB                  RD                  [(        RF                  RH                  US[K        U5      5      n[M        [H        U5      $ ! [
         a    [        SU S35      ef = f)aO  Create a DS record for a DNSSEC key.

*name*, a ``dns.name.Name`` or ``str``, the owner name of the DS record.

*key*, a ``dns.rdtypes.ANY.DNSKEY.DNSKEY`` or ``dns.rdtypes.ANY.DNSKEY.CDNSKEY``,
the key the DS is about.

*algorithm*, a ``str`` or ``int`` specifying the hash algorithm.
The currently supported hashes are "SHA1", "SHA256", and "SHA384". Case
does not matter for these strings.

*origin*, a ``dns.name.Name`` or ``None``.  If *key* is a relative name,
then it will be made absolute using the specified origin.

*policy*, a ``dns.dnssec.Policy`` or ``None``.  If ``None``, the default policy,
``dns.dnssec.default_policy`` is used; this policy defaults to that of RFC 8624.

*validating*, a ``bool``.  If ``True``, then policy is checked in
validating mode, i.e. "Is it ok to validate using this digest algorithm?".
Otherwise the policy is checked in creating mode, i.e. "Is it ok to create a DS with
this digest algorithm?".

Raises ``UnsupportedAlgorithm`` if the algorithm is unknown.

Raises ``DeniedByPolicy`` if the algorithm is denied by policy.

Returns a ``dns.rdtypes.ANY.DS.DS``
unsupported algorithm ""zkey is not a DNSKEY/CDNSKEYr~   z!HBBr   )'default_policyr,   r/   r   upper	Exceptionr   r[   rX   r   r   r   
ValueErrorSHA1hashlibsha1SHA256sha256SHA384sha384dnsr}   r"   canonicalizer;   updatedigeststructpackrC   r<   r@   	from_wire
rdataclassIN	rdatatyper   r?   r   )r}   r3   r<   r~   r   r   checkdshashwirekwirer   dsrdatadss                r#   make_dsr      s   J ~Ki%% !23I ((&&cFG,--677HMM!	hoo	%!	hoo	%!"%<YKq#IJJ$xx!!$/&&(DKKvK&E 111
MM$
MM%]]_Fkk&&+s}}iH6QG			3==++WaW
B B<A  K"%<YKq#IJJKs   ,I I-c           	          [        XX#5      n[        UR                  [        R                  R                  UR
                  UR                  UR                  UR                  S9$ )aq  Create a CDS record for a DNSSEC key.

*name*, a ``dns.name.Name`` or ``str``, the owner name of the DS record.

*key*, a ``dns.rdtypes.ANY.DNSKEY.DNSKEY`` or ``dns.rdtypes.ANY.DNSKEY.CDNSKEY``,
the key the DS is about.

*algorithm*, a ``str`` or ``int`` specifying the hash algorithm.
The currently supported hashes are "SHA1", "SHA256", and "SHA384". Case
does not matter for these strings.

*origin*, a ``dns.name.Name`` or ``None``.  If *key* is a relative name,
then it will be made absolute using the specified origin.

Raises ``UnsupportedAlgorithm`` if the algorithm is unknown.

Returns a ``dns.rdtypes.ANY.DS.CDS``
rdclassrdtypekey_tagr<   digest_typer   )	r   r   r   r   r   r   r<   r   r   )r}   r3   r<   r~   r   s        r#   make_cdsr     sM    2 
I	.B

}}  

,,NNyy r%   keysrrsigc                 \   U R                  UR                  5      n[        U[        R                  R
                  5      (       aC  UR                  [        R                  R                  [        R                  R                  5      nOUnUc  g U Vs/ s H  nUR                  UR                  :X  d  M  [        U5      UR                  :X  d  M:  UR                  [        R                   -  [        R                   :X  d  Mk  UR"                  S:X  d  M}  [%        [        U5      PM     sn$ s  snf )N   )getsignerr,   r   nodeNodeget_rdatasetr   r   r   r   r<   rC   r   flagsr   ZONEprotocolr   )r   r   r&   rdatasetrds        r#   _find_candidate_keysr   *  s     HHU\\"E%''%%cnn&7&79M9MN B<<5??* 	 2J%--' 	 XX		!dii/	 	
 KK1 	VR  s   D)4D)-D) D)D)rrsetc                 \    [        U [        5      (       a
  U S   U S   4$ U R                  U 4$ )Nr   r9   )r,   tupler}   )r   s    r#   _get_rrname_rdatasetr   >  s3     %Qxq!!zz5  r%   sigdatac                     [        U5      R                  n UR                  U5      nUR                  X5        g ! [         a    [	        S5      ef = f)Nzinvalid public key)get_algorithm_cls_from_dnskey
public_clsfrom_dnskeyr   r   verify)r   r   r3   r   
public_keys        r#   _validate_signaturer   G  sT    .s3>>J6++C0
 c   6 4556s	   : Anowc                    Uc  [         n[        X!5      nUc  [        S5      eUc  [        R                  " 5       nUR                  U:  a  [        S5      eUR
                  U:  a  [        S5      e[        XU5      nU H2  nUR                  U5      (       d  M   [        UR                  Xx5          g   [        S5      e! [        [        4 a     MT  f = f)a~  Validate an RRset against a single signature rdata, throwing an
exception if validation is not successful.

*rrset*, the RRset to validate.  This can be a
``dns.rrset.RRset`` or a (``dns.name.Name``, ``dns.rdataset.Rdataset``)
tuple.

*rrsig*, a ``dns.rdata.Rdata``, the signature to validate.

*keys*, the key dictionary, used to find the DNSKEY associated
with a given name.  The dictionary is keyed by a
``dns.name.Name``, and has ``dns.node.Node`` or
``dns.rdataset.Rdataset`` values.

*origin*, a ``dns.name.Name`` or ``None``, the origin to use for relative
names.

*now*, a ``float`` or ``None``, the time, in seconds since the epoch, to
use as the current time when validating.  If ``None``, the actual current
time is used.

*policy*, a ``dns.dnssec.Policy`` or ``None``.  If ``None``, the default policy,
``dns.dnssec.default_policy`` is used; this policy defaults to that of RFC 8624.

Raises ``ValidationFailure`` if the signature is expired, not yet valid,
the public key is invalid, the algorithm is unknown, the verification
fails, etc.

Raises ``UnsupportedAlgorithm`` if the algorithm is recognized by
dnspython but not implemented.
Nzunknown keyexpiredznot yet validzverify failure)r   r   r   time
expiration	inception_make_rrsig_signature_datarU   r   	signatureInvalidSignature)	r   r   r   r~   r   r   candidate_keysr   candidate_keys	            r#   _validate_rrsigr   Q  s    P ~)$6N..
{iik#	**00%eF;D ($$]33	E ( ,
--	 !"34 		s   C  CCrrsigsetc           	      n   Uc  [         n[        U[        5      (       a8  [        R                  R                  U[        R                  R                  5      n[        U [        5      (       a  U S   nOU R                  n[        U[        5      (       a  US   nUS   nOUR                  nUnUR                  U5      nUR                  U5      nXg:w  a  [        S5      eU H1  n	[        U	[        5      (       d  [        S5      e [        X	X#XE5          g   [        S5      e! [        [        4 a     MS  f = f)aa  Validate an RRset against a signature RRset, throwing an exception
if none of the signatures validate.

*rrset*, the RRset to validate.  This can be a
``dns.rrset.RRset`` or a (``dns.name.Name``, ``dns.rdataset.Rdataset``)
tuple.

*rrsigset*, the signature RRset.  This can be a
``dns.rrset.RRset`` or a (``dns.name.Name``, ``dns.rdataset.Rdataset``)
tuple.

*keys*, the key dictionary, used to find the DNSKEY associated
with a given name.  The dictionary is keyed by a
``dns.name.Name``, and has ``dns.node.Node`` or
``dns.rdataset.Rdataset`` values.

*origin*, a ``dns.name.Name``, the origin to use for relative names;
defaults to None.

*now*, an ``int`` or ``None``, the time, in seconds since the epoch, to
use as the current time when validating.  If ``None``, the actual current
time is used.

*policy*, a ``dns.dnssec.Policy`` or ``None``.  If ``None``, the default policy,
``dns.dnssec.default_policy`` is used; this policy defaults to that of RFC 8624.

Raises ``ValidationFailure`` if the signature is expired, not yet valid,
the public key is invalid, the algorithm is unknown, the verification
fails, etc.
Nr   r9   zowner names do not matchzexpected an RRSIGzno RRSIGs validated)r   r,   r/   r   r}   r"   rootr   choose_relativityr   r   r   r   )
r   r   r   r~   r   r   rrname	rrsignamerrsigrdatasetr   s
             r#   	_validater     s   N ~&###FCHHMM:%q(E""QK	 MM	 %%f-F++F3I :;;%''#$788	E$D  1
22 "#78 		s   D  D43D4Tprivate_keyr   dnskeyr   r   lifetimer   deterministicc                    Uc  [         nUR                  U5      (       d  [        e[        U [        5      (       a3  U S   R
                  nU S   R                  nU S   nU S   R                  nO0U R
                  nU R                  nU R                  nU R                  nUb  [        U5      nO[        [        R                  " 5       5      nUb  [        U5      nOUb  X-   nO[        S5      eU	b  UR                  U	5      n[        U5      S-
  nUR                  5       (       a  US-  n[!        U["        R$                  R                   UUR&                  UUUU[)        U5      USS9n["        R*                  R-                  U UU	5      n[        U[.        5      (       a  UnO [1        U5      nU" US9nUR7                  UXz5      n[9        [         UR;                  US95      $ ! [2         a    [5        S5      ef = f)	a  Sign RRset using private key.

*rrset*, the RRset to validate.  This can be a
``dns.rrset.RRset`` or a (``dns.name.Name``, ``dns.rdataset.Rdataset``)
tuple.

*private_key*, the private key to use for signing, a
``cryptography.hazmat.primitives.asymmetric`` private key class applicable
for DNSSEC.

*signer*, a ``dns.name.Name``, the Signer's name.

*dnskey*, a ``DNSKEY`` matching ``private_key``.

*inception*, a ``datetime``, ``str``, ``int``, ``float`` or ``None``, the
signature inception time.  If ``None``, the current time is used.  If a ``str``, the
format is "YYYYMMDDHHMMSS" or alternatively the number of seconds since the UNIX
epoch in text form; this is the same the RRSIG rdata's text form.
Values of type `int` or `float` are interpreted as seconds since the UNIX epoch.

*expiration*, a ``datetime``, ``str``, ``int``, ``float`` or ``None``, the signature
expiration time.  If ``None``, the expiration time will be the inception time plus
the value of the *lifetime* parameter.  See the description of *inception* above
for how the various parameter types are interpreted.

*lifetime*, an ``int`` or ``None``, the signature lifetime in seconds.  This
parameter is only meaningful if *expiration* is ``None``.

*verify*, a ``bool``.  If set to ``True``, the signer will verify signatures
after they are created; the default is ``False``.

*policy*, a ``dns.dnssec.Policy`` or ``None``.  If ``None``, the default policy,
``dns.dnssec.default_policy`` is used; this policy defaults to that of RFC 8624.

*origin*, a ``dns.name.Name`` or ``None``.  If ``None``, the default, then all
names in the rrset (including its owner name) must be absolute; otherwise the
specified origin will be used to make names absolute when signing.

*deterministic*, a ``bool``. If ``True``, the default, use deterministic
(reproducible) signatures when supported by the algorithm used for signing.
Currently, this only affects ECDSA.

Raises ``DeniedByPolicy`` if the signature is denied by policy.
r9   r   z(expiration or lifetime must be specifiedr%   )r   r   type_coveredr<   labelsoriginal_ttlr   r   r   r   r   r3   zUnsupported key algorithm)r   )r   rQ   r   r,   r   r   r   ttlr}   r2   r-   r   r   derelativizer?   is_wildr   r   r   r<   rC   dnssecr   r   r   r   r1   signr   replace)r   r   r   r   r   r   r   r   r   r~   r   r   r   r   r   rrsig_inceptionrrsig_expirationr   rrsig_templater   signing_keyprivate_clsr   s                          r#   _signr     s   t ~V$$%(""qqQx||--yy&y1diik*'
3		*5CDD $$V,[1_F ~~!}}""""!#!vN ::00OD +011!	97?K%+6K   v=I~--	-BCC $ 	9788	9s   !G! !G7c                    [        U[        5      (       a8  [        R                  R	                  U[        R                  R
                  5      nUR                  nUR                  5       (       d  Uc  [        S5      eUR                  U5      n[        U 5      u  pESnUR                  US9nUc   eXgSS -  nXaR                  R                  U5      -  nUR                  5       (       d  Uc  [        S5      eUR                  U5      n[        U5      nUR                  5       (       a  UR                  US-
  :w  a  [        S5      eUS-
  UR                  :  a  [        S	5      eUR                  US-
  :  aA  UR!                  UR                  S-   5      S   n	[        R                  R	                  S
U	5      nUR                  5       n
["        R$                  " SUR&                  UR(                  UR*                  5      nU Vs/ s H  oR                  U5      PM     nn[-        U5       H3  nXj-  nXk-  n["        R$                  " S[        U5      5      nXn-  nXl-  nM5     U$ s  snf )a  Create signature rdata.

*rrset*, the RRset to sign/validate.  This can be a
``dns.rrset.RRset`` or a (``dns.name.Name``, ``dns.rdataset.Rdataset``)
tuple.

*rrsig*, a ``dns.rdata.Rdata``, the signature to validate, or the
signature template used when signing.

*origin*, a ``dns.name.Name`` or ``None``, the origin to use for relative
names.

Raises ``UnsupportedAlgorithm`` if the algorithm is recognized by
dnspython but not implemented.
Nz,relative RR name without an origin specifiedr%   r      r8   z&wild owner name has wrong label lengthr9   z#owner name longer than RRSIG labels*z!HHIz!H)r,   r/   r   r}   r"   r   r   is_absoluter   r   r   r;   to_digestabler?   r   r   splitr   r   r   r   r   sorted)r   r   r~   r   r   r   r   r   name_lensuffix	rrnamebufrrfixedr@   rdatasrrlens                  r#   r   r   _  s   * &###FCHHMM:\\F>#$RSS$$V, ,E2FD==='D"IDLL&&v..D >#$RSS$$V,6{H~~ELLHqL8 HII!|ell" EFF	1	$ellQ./2##C0$$&Ikk&(//83C3CUEWEWXG7?@xe!!&)xF@D#e*-   K As   I$r   r   r   r   c                     [         R                  " U5      n[        U [        5      (       a  U R	                  X#S9$ [        U5      R                  nU" U S9R	                  X#S9$ )aT  Convert a public key to DNSKEY Rdata

*public_key*, a ``PublicKey`` (``GenericPublicKey`` or
``cryptography.hazmat.primitives.asymmetric``) to convert.

*algorithm*, a ``str`` or ``int`` specifying the DNSKEY algorithm.

*flags*: DNSKEY flags field as an integer.

*protocol*: DNSKEY protocol field as an integer.

Raises ``ValueError`` if the specified key algorithm parameters are not
unsupported, ``TypeError`` if the key type is unsupported,
`UnsupportedAlgorithm` if the algorithm is unknown and
`AlgorithmKeyMismatch` if the algorithm does not match the key type.

Return DNSKEY ``Rdata``.
)r   r   r   )r   maker,   r   	to_dnskeyget_algorithm_clsr   )r   r<   r   r   r   s        r#   _make_dnskeyr     s_    2 y)I *.//##%#CC&y1<<
j)33%3SSr%   c           	          [        XX#5      n[        UR                  [        R                  R                  UR
                  UR                  UR                  UR                  S9$ )ae  Convert a public key to CDNSKEY Rdata

*public_key*, the public key to convert, a
``cryptography.hazmat.primitives.asymmetric`` public key class applicable
for DNSSEC.

*algorithm*, a ``str`` or ``int`` specifying the DNSKEY algorithm.

*flags*: DNSKEY flags field as an integer.

*protocol*: DNSKEY protocol field as an integer.

Raises ``ValueError`` if the specified key algorithm parameters are not
unsupported, ``TypeError`` if the key type is unsupported,
`UnsupportedAlgorithm` if the algorithm is unknown and
`AlgorithmKeyMismatch` if the algorithm does not match the key type.

Return CDNSKEY ``Rdata``.
r   r   r   r   r<   r3   )	r   r   r   r   r   r   r   r<   r3   )r   r<   r   r   r   s        r#   _make_cdnskeyr    sO    4 *AF}}$$ll""JJ r%   domainsalt
iterationsc                    [         R                  SS5      n [        U[         5      (       a  [        UR	                  5          nU[        R                  :w  a  [        S5      eUc  SnOJ[        U[         5      (       a3  [        U5      S-  S:X  a  [        R                  U5      nO[        S5      eUn[        U [        R                  R                  5      (       d  [        R                  R                  U 5      n U R                  5       R!                  5       nUc   e["        R$                  " Xe-   5      R'                  5       n[)        U5       H)  n["        R$                  " Xu-   5      R'                  5       nM+     [*        R,                  " U5      R/                  S5      n	U	R1                  U5      n	U	$ ! [
         a    [        S5      ef = f)	a  
Calculate the NSEC3 hash, according to
https://tools.ietf.org/html/rfc5155#section-5

*domain*, a ``dns.name.Name`` or ``str``, the name to hash.

*salt*, a ``str``, ``bytes``, or ``None``, the hash salt.  If a
string, it is decoded as a hex string.

*iterations*, an ``int``, the number of iterations.

*algorithm*, a ``str`` or ``int``, the hash algorithm.
The only defined algorithm is SHA1.

Returns a ``str``, the encoded NSEC3 hash.
 ABCDEFGHIJKLMNOPQRSTUVWXYZ234567 0123456789ABCDEFGHIJKLMNOPQRSTUVz-Wrong hash algorithm (only SHA1 is supported)r%   r8   r   zInvalid salt lengthzutf-8)r/   	maketransr,   r   r   r   r   r   r?   bytesfromhexr   r}   Namer"   r   r;   r   r   r   r>   base64	b32encodedecode	translate)
r  r  r  r<   b32_conversionsalt_encodeddomain_encodedr   rM   outputs
             r#   
nsec3_hashr    s|   . ]]*,NNJi%%!)//"34I INN"HII|	D#		t9q=A ==.L233fchhmm,,##F+((*224N%%%\\.78??AF:f34;;=  f%,,W5Fn-FM9  JHIIJs   ,F4 4G

algorithmsc           	         [        U 5      u  p4UR                  [        R                  R                  [        R                  R
                  [        R                  R                  4;  a  [        S5      e[        5       nU HA  n [        U[        5      (       a  [        UR                  5          nUR                  U5        MC     UR                  [        R                  R                  :X  a{  / n[!        U5       H&  nUR"                  U;   d  M  UR%                  U5        M(     ['        U5      S:X  a  [        S5      e[        R(                  R+                  UR,                  U5      $ / nU H  nUR/                  [1        X4Xb5      5        M      [        R(                  R+                  UR,                  U5      $ ! [         a    [        SU S35      ef = f)a  Create a DS record from DNSKEY/CDNSKEY/CDS.

*rrset*, the RRset to create DS Rdataset for.  This can be a
``dns.rrset.RRset`` or a (``dns.name.Name``, ``dns.rdataset.Rdataset``)
tuple.

*algorithms*, a set of ``str`` or ``int`` specifying the hash algorithms.
The currently supported hashes are "SHA1", "SHA256", and "SHA384". Case
does not matter for these strings. If the RRset is a CDS, only digest
algorithms matching algorithms are accepted.

*origin*, a ``dns.name.Name`` or ``None``.  If `key` is a relative name,
then it will be made absolute using the specified origin.

Raises ``UnsupportedAlgorithm`` if any of the algorithms are unknown and
``ValueError`` if the given RRset is not usable.

Returns a ``dns.rdataset.Rdataset``
zrrset not a DNSKEY/CDNSKEY/CDSr   r   r   zno acceptable CDS rdata found)r   r   r   r   r   r   r   r   setr,   r/   r   r   r   r   addcds_rdataset_to_ds_rdatasetr   appendr?   r   from_rdata_listr   extenddnskey_rdataset_to_cds_rdataset)	r   r  r~   r   r   _algorithmsr<   resr@   s	            r#   make_ds_rdatasetr   (  sz   2 ,E2F 
 9::%K		O)S))$Y__%67	 		"   #--+++0:E  K/

5! ; s8q=<==||++HLL#>>
C 	

26YWX !<<''c::!  	O&)@1'MNN	Os   ,F88Gr   c                    U R                   [        R                  R                  :w  a  [	        S5      e/ nU  Hj  nUR                  [        UR                  [        R                  R                  UR                  UR                  UR                  UR                  S95        Ml     [        R                  R                  U R                  U5      $ )zCreate a CDS record from DS.

*rdataset*, a ``dns.rdataset.Rdataset``, to create DS Rdataset for.

Raises ``ValueError`` if the rdataset is not CDS.

Returns a ``dns.rdataset.Rdataset``
zrdataset not a CDSr   )r   r   r   r   r   r  r   r   r   r<   r   r   r   r  r   r   r  r@   s      r#   r  r  b  s     #--+++-..
C

}}''//!--||		
  <<''c::r%   c           	      <   UR                   [        R                  R                  [        R                  R                  4;  a  [        S5      e/ nU H  nUR                  [        XX#5      5        M      [        R                  R                  UR                  U5      $ )a  Create a CDS record from DNSKEY/CDNSKEY.

*name*, a ``dns.name.Name`` or ``str``, the owner name of the CDS record.

*rdataset*, a ``dns.rdataset.Rdataset``, to create DS Rdataset for.

*algorithm*, a ``str`` or ``int`` specifying the hash algorithm.
The currently supported hashes are "SHA1", "SHA256", and "SHA384". Case
does not matter for these strings.

*origin*, a ``dns.name.Name`` or ``None``.  If `key` is a relative name,
then it will be made absolute using the specified origin.

Raises ``UnsupportedAlgorithm`` if the algorithm is unknown or
``ValueError`` if the rdataset is not DNSKEY/CDNSKEY.

Returns a ``dns.rdataset.Rdataset``
zrdataset not a DNSKEY/CDNSKEY)r   r   r   r   r   r   r  r   r   r  r   )r}   r   r<   r~   r  r@   s         r#   r  r    sr    2 s}}33S]]5J5JKK899
C

8D;< <<''c::r%   c                    U R                   [        R                  R                  :w  a  [	        S5      e/ nU  H\  nUR                  [        U R                  U R                   UR                  UR                  UR                  UR                  S95        M^     [        R                  R                  U R                  U5      $ )zCreate a CDNSKEY record from DNSKEY.

*rdataset*, a ``dns.rdataset.Rdataset``, to create CDNSKEY Rdataset for.

Returns a ``dns.rdataset.Rdataset``
zrdataset not a DNSKEYr   )r   r   r   r   r   r  r   r   r   r   r<   r3   r   r  r   r"  s      r#   #dnskey_rdataset_to_cdnskey_rdatasetr%    s     #--...011
C

 ((kk//II		
  <<''c::r%   txnkskszsksc                    UR                   [        [        R                  R                  R
                  [        R                  R                  R                  [        R                  R                  R                  /5      ;   a  UnOUnU HR  u  p[        R                  R                  UUUUUUUUU	U
S9
nU R                  UR                  UR                  U5        MT     g)zDefault RRset signer)
r   r   r   r   r   r   r   r   r~   r   N)r   r  r   r   	RdataTyper   r   r   r   r   r  r}   r   )r&  r   r   r'  r(  r   r   r   r   r~   r   r   r   r   r   s                  r#   default_rrset_signerr+    s     ||sMM##**MM##''MM##++	
  #

#!'   
 	

EIIu-  $r%   zone
add_dnskey
dnskey_ttlnsec3rrset_signerc                    / n/ nU(       ae  U HL  nUS   R                   [        R                  -  (       a  UR                  U5        M;  UR                  U5        MN     U(       d  UnU(       d  UnO/ nU(       a  [        R
                  " U5      nOU R                  5       nU R                  c  [        S5      eU nU(       a  Uc  UR                  U R                  [        R                  R                  5      nU(       a  UR                  nO@UR                  U R                  [        R                  R                  5      nUR                  nU H#  u  nnUR                  U R                  UU5        M%     U(       a  [!        S5      eU	=(       d5    ["        R$                  " [&        U R                  UUUUUU
U R                  US9
n[)        U UU5      sSSS5        $ ! , (       d  f       g= f)a  Sign zone.

*zone*, a ``dns.zone.Zone``, the zone to sign.

*txn*, a ``dns.transaction.Transaction``, an optional transaction to use for
signing.

*keys*, a list of (``PrivateKey``, ``DNSKEY``) tuples, to use for signing. KSK/ZSK
roles are assigned automatically if the SEP flag is used, otherwise all RRsets are
signed by all keys.

*add_dnskey*, a ``bool``.  If ``True``, the default, all specified DNSKEYs are
automatically added to the zone on signing.

*dnskey_ttl*, a``int``, specifies the TTL for DNSKEY RRs. If not specified the TTL
of the existing DNSKEY RRset used or the TTL of the SOA RRset.

*inception*, a ``datetime``, ``str``, ``int``, ``float`` or ``None``, the signature
inception time.  If ``None``, the current time is used.  If a ``str``, the format is
"YYYYMMDDHHMMSS" or alternatively the number of seconds since the UNIX epoch in text
form; this is the same the RRSIG rdata's text form. Values of type `int` or `float`
are interpreted as seconds since the UNIX epoch.

*expiration*, a ``datetime``, ``str``, ``int``, ``float`` or ``None``, the signature
expiration time.  If ``None``, the expiration time will be the inception time plus
the value of the *lifetime* parameter.  See the description of *inception* above for
how the various parameter types are interpreted.

*lifetime*, an ``int`` or ``None``, the signature lifetime in seconds.  This
parameter is only meaningful if *expiration* is ``None``.

*nsec3*, a ``NSEC3PARAM`` Rdata, configures signing using NSEC3. Not yet
implemented.

*rrset_signer*, a ``Callable``, an optional function for signing RRsets. The
function requires two arguments: transaction and RRset. If the not specified,
``dns.dnssec.default_rrset_signer`` will be used.

*deterministic*, a ``bool``. If ``True``, the default, use deterministic
(reproducible) signatures when supported by the algorithm used for signing.
Currently, this only affects ECDSA.

Returns ``None``.
r9   Nzno zone originz&Signing with NSEC3 not yet implemented)	r   r'  r(  r   r   r   r   r~   r   )r   r   SEPr  
contextlibnullcontextwriterr~   r   r   r   r   r   r   SOAr  NotImplementedError	functoolspartialr+  _sign_zone_nsec)r,  r&  r   r-  r.  r   r   r   r/  r0  r   r   r'  r(  r3   cm_txnr   soarM   _rrset_signers                        r#   	sign_zoner?    s}   v DD C1v||dhh&C C 	 
 DD
0:0F0Fs0K[[]{{)**	t!$++s}}/C/CD!'J((4;;0A0ABC!$J!	6j&9 " %&NOO( I,=,=${{#%!{{+-M #4}=7 
s   ;DG
G+c                 `    S
S[         R                  R                  S[         R                  R                  S[
        [         R                  R                     S[         R                  R                  S[        S[
        [           SS4S	 jjnU R                  5       R                  nSnSn[        UR                  5       5       GH?  nU(       a  UR                  U5      (       a  M#  UR                  U[         R                   R"                  5      (       a  XpR$                  :w  a  UnOSnU(       a  UR'                  U5      nU(       a  UR(                   H  n	U	R*                  [         R                   R,                  :X  a  M-  U(       a*  U	R*                  [         R                   R.                  :w  a  M^  [         R0                  R2                  " XyR4                  /U	Q76 n
U" X5        M     Ub  U" XXpR6                  XB5        UnGMB     U(       a   U" XU R$                  U R6                  XB5        gg)zNSEC zone signerNr&  r}   next_securer   r   r0  r    c                 p   [        [        R                  R                  R                  [        R                  R                  R
                  /5      nU R                  U5      nU(       a  U(       a  [        UR                   Vs/ s H  oR                  PM     sn5      U-  n	[        R                  " [        U	5      5      n
[        R                  R                  UU[        U[        R                  R                  R
                  UU
S95      nU R                  U5        U(       a	  U" X5        ggggs  snf )zNSEC zone signer helper)r   r   nextwindowsN)r  r   r   r*  r   r   get_node	rdatasetsr   r   from_rdtypeslistr   
from_rdatar  )r&  r}   rA  r   r   r0  mandatory_typesr   r   typesrD  r   s               r#   _txn_add_nsec&_sign_zone_nsec.<locals>._txn_add_nsec_  s     ]]$$**CMM,C,C,H,HI
 ||D!KT^^D^__^DEW  ))$u+6GII((#==2277$#		E GGENS( !  4Ds   D3rH   )r   transactionTransactionr}   r  r   r   
RdataClassr-   RRsetSignerget_soaminimumr   iterate_namesis_subdomainr   r   NSr~   rE  rF  r   r   r   r   rI  r   r   )r,  r&  r0  rL  	rrsig_ttl
delegationlast_securer}   r   r   r   s              r#   r:  r:  X  s    /3)__(()hhmm) chhmm,) **	)
 ) {+) 
)@ &&IJKs((*+$++J77WWT3==++,,1DJ J<<%D $H#--*=*== #3==;K;K(K  #		 4 4T<< S( S$S0 !/ "#D,,	X9 ,< dkk4<<	
 r%   c                      [        S5      e)Nz.DNSSEC validation requires python cryptography)ImportError)argskwargss     r#   
_need_pycar^    s    
8 r%   r   )r   )dsa)ec)ed448)rsa)ed25519)r   r   )r   r   )NNFrH   )NNN)NNNFNNT)NNNNNT)NNTNNNNNNNT)__doc__r  r3  r8  r   r   r   r   typingr   r   r   r   r   r	   r
   r   dns._featuresr   dns.exceptiondns.namedns.node	dns.rdatadns.rdataclassdns.rdatasetdns.rdatatype	dns.rrsetdns.transactiondns.zonedns.dnssectypesr   r   r   r   r   r   r   dns.rdtypes.ANY.CDNSKEYr   dns.rdtypes.ANY.CDSr   dns.rdtypes.ANY.DNSKEYr   dns.rdtypes.ANY.DSr   dns.rdtypes.ANY.NSECr   r   dns.rdtypes.ANY.NSEC3PARAMr   dns.rdtypes.ANY.RRSIGr   r   dns.rdtypes.dnskeybaser   	PublicKey
PrivateKeyrN  rO  r   RRsetrQ  r/   r$   r-   r*   r0   r2   rC   rE   rd   r=   DSADSANSEC3SHA1ECCGOSTNULLr   GOSTrfc_8624_policyr  allow_all_policyr   r}   r  r@   Rdatara   r   r   r   Rdatasetr   r   r   r   r	  r   r   r   r   r   r   r   r  r  r   r  r  r%  r+  r,  Zoner?  r:  r^  	_featureshavecryptography.exceptionsr   )cryptography.hazmat.primitives.asymmetricr_  r`  ra  rb  rc  dns.dnssecalgsr   r   dns.dnssecalgs.baser   r   validatevalidate_rrsigr   make_dnskeymake_cdnskey
_have_pycaDHECCRSASHA1RSASHA1NSEC3SHA1	RSASHA256	RSASHA512ECDSAP256SHA256ECDSAP384SHA384ED25519ED448INDIRECT
PRIVATEDNS
PRIVATEOIDrI   r%   r#   <module>r     s  $ 5        J J J            : :  , # ) ! - 1 = '	 
 33SYY__EtKL%c %i %$U9c>2 $s $6hUC78 6S 6fgo& 3 , "7 7* y}}i&<&<i>O>OPy}}i&<&<=]]HMM8==1]]O	 ceSUCE359  ! '+#J
s"
#J	J Xs]#J SXX]]#	J
 VJ J Jb '+	!
s"
#!	! Xs]#! SXX]]#	!
 	!H
sxx}}eCLL$9$9388==$HII
JSXd6l(!%s||7L7L(L"MMN!
388==#,,///0!!U !% !f ! ! '+#C.%s||7L7L(L"MMNC.C. sxx}}eCHHMM3<<3H3H$HII
JC. SXX]]#	C.
 
%C. VC. 
C.T '+#F3%s||7L7L(L"MMNF3CIIOOU388==#,,:O:O+O%PPQF3 sxx}}eCHHMM3<<3H3H$HII
JF3 SXX]]#	F3
 
%F3 VF3 
F3\ =A=A"#&*|D%s||7L7L(L"MMN|D|D HHMM|D 	|D
 hS%789|D xc589:|D sm|D |D V|D SXX]]#|D |D |DD '+@%s||7L7L(L"MMN@@ SXX]]#@ 	@L 	 T TS#X T  T 	 T
  TL 	##S#X# # 	#
 #L:#((--$%:
5e$
%: : S#X	:
 	:@ '+7;%s||7L7L(L"MMN7;E(C-()7; SXX]]#7; 	\\	7;t;ll##;\\;B '+	;
s"
#;ll##; Xs]#; SXX]]#	;
 	\\;B;ll##;\\;B =A=A"#&*'.		$	$'.99??'. HHMM'. uZ'(
)	'.
 uZ'(
)'. hS%789'. xc589:'. sm'. V'. SXX]]#'. '. 
'.X 266: $<@=A""&*.#p>
((--p>	#//--	.p> 4j&012
3p> 	p>
 p> hS%789p> xc589:p> smp> Jp> ;'p> Vp> p> 
p>l +/L

((--L
		$	$L
 ;'L
 
	L
^ ==h8=<?= HH$NDK LJHNDKLJ 
		\\mmmm


%%-- 		


++++


!!
!!
r%   