
    Ii                         S SK Jr  S SKJrJr  S SK Jr  S\S\S\4S jr	S\S	\
S\4S
 jrS\S	\
S\4S jrS\S\4S jrS\S\S\4S jrg)    N)ffilib)ensureinp1inp2returnc                 *   [        [        U [        5      [        R                  S9  [        [        U[        5      [        R                  S9  [        [        U 5      [        U5      5      n[        R                  " SU5      n[        R                  " SU5      n[        R                  " X0[        U 5      5        [        R                  " XA[        U5      5        [        U 5      [        U5      :H  n[        R                  " X4U5      S:H  nU=(       a    U$ )z9
Compare contents of two memory regions in constant time
raisingzchar []r   )r   
isinstancebytesexc	TypeErrormaxlenr   newmemmover   sodium_memcmp)r   r   lnbuf1buf2eqLeqCs          9/venv/lib/python3.13/site-packages/nacl/bindings/utils.pyr   r      s     :dE"CMM:
:dE"CMM:	SYD		"B779b!D779b!DKKCI&KKCI&
d)s4y
 C


D
+q
0C;3    s	blocksizec                    [        [        U [        5      [        R                  S9  [        [        U[
        5      [        R                  S9  US::  a  [        R                  e[        U 5      nX!-   n[        R                  " SU5      n[        R                  " SS5      n[        R                  " X@U5        [        R                  " XTX!U5      n[        US:H  S[        R                  S9  [        R                  " XES   5      SS $ )z
Pad the input bytearray ``s`` to a multiple of ``blocksize``
using the ISO/IEC 7816-4 algorithm

:param s: input bytes string
:type s: bytes
:param blocksize:
:type blocksize: int
:return: padded string
:rtype: bytes
r
   r   unsigned char []	size_t []   zPadding failureN)r   r   r   r   r   int
ValueErrorr   r   r   r   r   
sodium_padCryptoErrorbuffer)r   r   s_lenm_lenbufp_lenrcs          r   r$   r$   )   s     :a7
:i%s}}=A~nnFEE
''$e
,CGGK#EKK	Ee	<B
27%s?::c8$Q''r   c                 T   [        [        U [        5      [        R                  S9  [        [        U[
        5      [        R                  S9  [        U 5      n[        R                  " SS5      n[        R                  " X0X!5      nUS:w  a  [        R                  " S5      eU SUS    $ )z
Remove ISO/IEC 7816-4 padding from the input byte array ``s``

:param s: input bytes string
:type s: bytes
:param blocksize:
:type blocksize: int
:return: unpadded string
:rtype: bytes
r
   r    r!   r   zUnpadding failureN)r   r   r   r   r   r"   r   r   r   r   sodium_unpadr%   )r   r   r'   u_lenr+   s        r   r-   r-   C   s     :a7
:i%s}}=FEGGK#E			%E	5B	Qwoo122ZuQx=r   inpc                    [        [        U [        5      [        R                  S9  [        U 5      n[        R                  " SU5      n[        R                  " X U5        [        R                  " X!5        [        R                  " X!5      SS $ )aC  
Increment the value of a byte-sequence interpreted
as the little-endian representation of a unsigned big integer.

:param inp: input bytes buffer
:type inp: bytes
:return: a byte-sequence representing, as a little-endian
         unsigned big integer, the value ``to_int(inp)``
         incremented by one.
:rtype: bytes

r
   r   N)r   r   r   r   r   r   r   r   r   r   sodium_incrementr&   )r/   r   r)   s      r   r1   r1   X   sc     :c5!3==9	SB
''$b
)CKK"!::cq!!r   abc                    [        [        U [        5      [        R                  S9  [        [        U[        5      [        R                  S9  [        U 5      n[        [        U5      U:H  [        R                  S9  [        R                  " SU5      n[        R                  " SU5      n[        R                  " X0U5        [        R                  " XAU5        [        R                  " X4U5        [        R                  " X25      SS $ )a  
Given a couple of *same-sized* byte sequences, interpreted as the
little-endian representation of two unsigned integers, compute
the modular addition of the represented values, in constant time for
a given common length of the byte sequences.

:param a: input bytes buffer
:type a: bytes
:param b: input bytes buffer
:type b: bytes
:return: a byte-sequence representing, as a little-endian big integer,
         the integer value of ``(to_int(a) + to_int(b)) mod 2^(8*len(a))``
:rtype: bytes
r
   r   N)r   r   r   r   r   r   r   r   r   r   
sodium_addr&   )r2   r3   r   buf_abuf_bs        r   r5   r5   q   s     :a7
:a7	QB
3q6R</GG&+EGG&+EKK"KK"NN5$::e ##r   )nacl.exceptions
exceptionsr   nacl._sodiumr   r   r   r   boolr   r"   r$   r-   r1   r5    r   r   <module>r=      s     ! " U t *(% (C (E (4E c e *"% "E "2$% $E $e $r   