
    nh+                        U d dl mZmZmZmZ d dlmZ d dlm	Z	m
Z
 d dlmZ  e
j                         Zeed<    e
j"                         Zeed<    e
j&                         Zeed<    e
j*                         Zeed<    e
j.                         Zeed	<    e
j2                         Zeed
<    e
j6                         Zeed<    e
j:                         Zeed<    e
j>                         Z eed<   de!fdZ" G d d      Z#de#de!de!fdZ$defde#de!dee!   dede!f
dZ%de#de!de!ddfdZ&	 dde#de!dee!   dee!ef   fdZ'de#ddfdZ(y)     )
ByteStringOptionalTuplecast)
exceptions)ffilib)ensure,crypto_secretstream_xchacha20poly1305_ABYTES1crypto_secretstream_xchacha20poly1305_HEADERBYTES.crypto_secretstream_xchacha20poly1305_KEYBYTES6crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX0crypto_secretstream_xchacha20poly1305_STATEBYTES1crypto_secretstream_xchacha20poly1305_TAG_MESSAGE.crypto_secretstream_xchacha20poly1305_TAG_PUSH/crypto_secretstream_xchacha20poly1305_TAG_REKEY/crypto_secretstream_xchacha20poly1305_TAG_FINALreturnc                      t        j                  dt              } t        j                  |        t        j
                  |       dd S )zd
    Generate a key for use with
    :func:`.crypto_secretstream_xchacha20poly1305_init_push`.

    unsigned char[]N)r   newr   r	   ,crypto_secretstream_xchacha20poly1305_keygenbuffer)keybufs    s/var/www/pru.catia.catastroantioquia-mas.com/tasa/lib/python3.12/site-packages/nacl/bindings/crypto_secretstream.pyr   r   4   s<     WW6F 44V<::fa      c                        e Zd ZdZg dZddZy)+crypto_secretstream_xchacha20poly1305_statezN
    An object wrapping the crypto_secretstream_xchacha20poly1305 state.

    )statebufrawbuftagbufNc                 ^    t        j                  dt              | _        d| _        d| _        y)z Initialize a clean state object.r   N)r   r   r   r   r    r!   )selfs    r   __init__z4crypto_secretstream_xchacha20poly1305_state.__init__J   s(    $'GG<%

 -1,0r   )r   N)__name__
__module____qualname____doc__	__slots__r$    r   r   r   r   B   s    
 1I1r   r   statekeyc                    t        t        | t              dt        j                         t        t        |t
              dt        j                         t        t        |      t        k(  dt        j                         t        j                  dt              }t        j                  | j                  ||      }t        |dk(  dt        j                         t        j                   |      dd S )	a\  
    Initialize a crypto_secretstream_xchacha20poly1305 encryption buffer.

    :param state: a secretstream state object
    :type state: crypto_secretstream_xchacha20poly1305_state
    :param key: must be
                :data:`.crypto_secretstream_xchacha20poly1305_KEYBYTES` long
    :type key: bytes
    :return: header
    :rtype: bytes

    BState must be a crypto_secretstream_xchacha20poly1305_state objectraisingKey must be a bytes sequenceInvalid key lengthzunsigned char []r   Unexpected failureN)r
   
isinstancer   exc	TypeErrorbyteslenr   
ValueErrorr   r   r   r	   /crypto_secretstream_xchacha20poly1305_init_pushr   RuntimeErrorr   )r+   r,   	headerbufrcs       r   r:   r:   U   s     5EFL
 3&
 CBB 9I
 
	<	<	3
B 27(#2B2BC::i ##r   Nmadtagc           
      V   t        t        | t              dt        j                         t        t        |t
              dt        j                         t        t        |      t        k  dt        j                         t        |du xs t        |t
              dt        j                         t        |      t        z   }| j                  t        | j                        |k  rt        j                  d|      | _
        |t        j                  }d}nt        |      }t        j                  | j                   | j                  t        j                  |t        |      |||      }t        |dk(  d	t        j"                         t        j$                  | j                  |      dd S )
a  
    Add an encrypted message to the secret stream.

    :param state: a secretstream state object
    :type state: crypto_secretstream_xchacha20poly1305_state
    :param m: the message to encrypt, the maximum length of an individual
              message is
              :data:`.crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX`.
    :type m: bytes
    :param ad: additional data to include in the authentication tag
    :type ad: bytes or None
    :param tag: the message tag, usually
                :data:`.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE` or
                :data:`.crypto_secretstream_xchacha20poly1305_TAG_FINAL`.
    :type tag: int
    :return: ciphertext
    :rtype: bytes

    r.   r/   zMessage is not byteszMessage is too longN%Additional data must be bytes or Noner   r   r3   )r
   r4   r   r5   r6   r7   r8   r   r9   r   r    r   r   NULLr	   *crypto_secretstream_xchacha20poly1305_pushr   r;   r   )r+   r>   r?   r@   clenadlenr=   s          r   rD   rD      sF   2 5EFL
 :a!7O
AHH
 
d
+jU+/ q6@@D||s5<<047ww0$7	zXXB		7	7	A
	
B 27(#2B2BC::ellD)!,,r   headerc                 |   t        t        | t              dt        j                         t        t        |t
              dt        j                         t        t        |      t        k(  dt        j                         t        t        |t
              dt        j                         t        t        |      t        k(  dt        j                         | j                  t        j                  d      | _
        t        j                  | j                  ||      }t        |d	k(  d
t        j                          y)a  
    Initialize a crypto_secretstream_xchacha20poly1305 decryption buffer.

    :param state: a secretstream state object
    :type state: crypto_secretstream_xchacha20poly1305_state
    :param header: must be
                :data:`.crypto_secretstream_xchacha20poly1305_HEADERBYTES` long
    :type header: bytes
    :param key: must be
                :data:`.crypto_secretstream_xchacha20poly1305_KEYBYTES` long
    :type key: bytes

    r.   r/   zHeader must be a bytes sequencezInvalid header lengthr1   r2   Nzunsigned char *r   r3   )r
   r4   r   r5   r6   r7   r8   r   r9   r   r!   r   r   r	   /crypto_secretstream_xchacha20poly1305_init_pullr   r;   )r+   rG   r,   r=   s       r   rI   rI      s    $ 5EFL
 65!)
 FHH
 3&
 CBB ||ww01		<	<
B 27(#2B2BCr   cc           
      l   t        t        | t              dt        j                         t        | j
                  dudt        j                         t        t        |t              dt        j                         t        t        |      t        k\  dt        j                         t        t        |      t        t        z   k  dt        j                         t        |du xs t        |t              dt        j                         t        |      t        z
  }| j                  t        | j                        |k  rt        j                  d	|      | _        |t        j                  }d
}nt        |      }t        j                   | j"                  | j                  t        j                  | j
                  |t        |      ||      }t        |d
k(  dt        j$                         t        j&                  | j                  |      dd t)        t+        t        | j
                        d
         fS )aM  
    Read a decrypted message from the secret stream.

    :param state: a secretstream state object
    :type state: crypto_secretstream_xchacha20poly1305_state
    :param c: the ciphertext to decrypt, the maximum length of an individual
              ciphertext is
              :data:`.crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX` +
              :data:`.crypto_secretstream_xchacha20poly1305_ABYTES`.
    :type c: bytes
    :param ad: additional data to include in the authentication tag
    :type ad: bytes or None
    :return: (message, tag)
    :rtype: (bytes, int)

    r.   r/   NzOState must be initialized using crypto_secretstream_xchacha20poly1305_init_pullzCiphertext is not byteszCiphertext is too shortzCiphertext is too longrB   r   r   r3   )r
   r4   r   r5   r6   r!   r9   r7   r8   r   r   r    r   r   rC   r	   *crypto_secretstream_xchacha20poly1305_pullr   r;   r   intr   )r+   rJ   r?   mlenrF   r=   s         r   rL   rL      s   * 5EFL
 D >  1e!
 A>>!
 AB:;	

 	! 
d
+jU+/ q6@@D||s5<<047ww0$7	zXXB		7	7	A
	
B 27(#2B2BC 	

5<<&q)D%a() r   c                     t        t        | t              dt        j                         t        j                  | j                         y)a  
    Explicitly change the encryption key in the stream.

    Normally the stream is re-keyed as needed or an explicit ``tag`` of
    :data:`.crypto_secretstream_xchacha20poly1305_TAG_REKEY` is added to a
    message to ensure forward secrecy, but this method can be used instead
    if the re-keying is controlled without adding the tag.

    :param state: a secretstream state object
    :type state: crypto_secretstream_xchacha20poly1305_state

    r.   r/   N)r
   r4   r   r5   r6   r	   +crypto_secretstream_xchacha20poly1305_rekeyr   )r+   s    r   rP   rP   Q  s5     5EFL
 33ENNCr   )N))typingr   r   r   r   naclr   r5   nacl._sodiumr   r	   nacl.exceptionsr
   ,crypto_secretstream_xchacha20poly1305_abytesr   rM   __annotations__1crypto_secretstream_xchacha20poly1305_headerbytesr   .crypto_secretstream_xchacha20poly1305_keybytesr   6crypto_secretstream_xchacha20poly1305_messagebytes_maxr   0crypto_secretstream_xchacha20poly1305_statebytesr   1crypto_secretstream_xchacha20poly1305_tag_messager   .crypto_secretstream_xchacha20poly1305_tag_pushr   /crypto_secretstream_xchacha20poly1305_tag_rekeyr   /crypto_secretstream_xchacha20poly1305_tag_finalr   r7   r   r   r:   rD   rI   rL   rP   r*   r   r   <module>r_      s   5 4 " ! " 5C446 -c  :C99; 23  7C668 /  ?C>>@ 7  9C88: 1#  :C99; 23  7C668 /  8C779 0  8C779 0 
!e !1 1&)$6)$=B)$
)$^ @	@-6@-@- 	@- 
	@-
 @-F2D62D2D 
2D 
	2Dp U6UU 	U 5#:	UpD6D	Dr   