Ë
    8ø»jº
  ã                  óÈ   — d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dlm	Z	 d dl
mZ e	rd dlmZ ej                  ej                  z   Zdd„Zdd„Zdd d	œ	 	 	 	 	 	 	 	 	 dd
„Zy)é    )ÚannotationsN)Úurlsafe_b64encode)ÚTYPE_CHECKING)Ú
to_seconds)Ú	timedeltac                óº   — | dk(  r	t         d   S g }| dkD  r-t        | d«      \  } }|j                  t         |   «       | dkD  rŒ-dj                  t	        |«      «      S )z‰Encode an integer to a base62 string.

    Args:
        num: The number to encode.

    Returns:
        The base62-encoded string.
    r   é>   Ú )Ú_BASE62_CHARSETÚdivmodÚappendÚjoinÚreversed)ÚnumÚpartsÚ	remainders      úQ/var/www/html/GAP/venv/lib/python3.12/site-packages/apify_client/_utils/crypto.pyÚencode_base62r      sb   € ð ˆa‚xÜ˜qÑ!Ð!ð €EØ
�Š'Ü  R›‰ˆˆYØ�‰”_ YÑ/Ô0ð �‹'ð
 �7‰7”8˜E“?Ó#Ð#ó    c                óØ   — t        j                  | j                  d«      |j                  d«      t        j                  «      j                  «       dd }t        |d«      }t        |«      S )aR  Generate an HMAC-SHA256 signature and encode it using base62.

    The HMAC signature is truncated to 30 characters and then encoded in base62 to reduce the signature length.

    Args:
        secret_key: The secret key used for signing.
        message: The message to be signed.

    Returns:
        The base62-encoded signature.
    úutf-8Né   é   )ÚhmacÚnewÚencodeÚhashlibÚsha256Ú	hexdigestÚintr   )Ú
secret_keyÚmessageÚ	signatureÚdecimal_signatures       r   Úcreate_hmac_signaturer%   (   sY   € ô —‘˜×*Ñ*¨7Ó3°W·^±^ÀGÓ5LÌgÏnÉnÓ]×gÑgÓiÐjmÐkmÐn€Iä˜I rÓ*ÐäÐ*Ó+Ð+r   )Ú
expires_inÚversionc               ó
  — |�8t        t        j                  «       dz  «      t        t        |«      dz  «      z   nd}|› d|› d| › �}t        ||«      }t	        |› d|› d|› �j                  «       «      }|j                  d«      S )aµ  Create a secure signature for a storage resource like a dataset or key-value store.

    This signature is used to generate a signed URL for authenticated access, which can be expiring or permanent.
    The signature is created using HMAC with the provided secret key and includes the resource ID, expiration time,
    and version.

    Args:
        resource_id: The unique identifier of the storage resource.
        url_signing_secret_key: The secret key for signing the URL.
        expires_in: Optional expiration duration; if None, the signature never expires.
        version: The signature version number (default: 0).

    Returns:
        The base64url-encoded signature string.
    iè  r   ú.r   )r    Útimer   r%   r   r   Údecode)Úresource_idÚurl_signing_secret_keyr&   r'   Ú
expires_atÚmessage_to_signÚhmac_sigÚbase64url_encoded_payloads           r   Ú create_storage_content_signaturer2   ;   s�   € ð, R\ÐQg””T—Y‘Y“[ 4Ñ'Ó(¬3¬z¸*Ó/EÈÑ/LÓ+MÒMÐmn€Jà ˜	  : ,¨a°¨}Ð=€OÜ$Ð%;¸_ÓM€Hä 1°W°I¸Q¸z¸lÈ!ÈHÈ:Ð2V×2]Ñ2]Ó2_Ó `ÐØ$×+Ñ+¨GÓ4Ð4r   )r   r    ÚreturnÚstr)r!   r4   r"   r4   r3   r4   )
r,   r4   r-   r4   r&   ztimedelta | Noner'   r    r3   r4   )Ú
__future__r   r   r   Ústringr*   Úbase64r   Útypingr   Úapify_client._utils.timer   Údatetimer   ÚdigitsÚascii_lettersr   r   r%   r2   © r   r   ú<module>r>      s|   ðÝ "ã Û Û Û Ý $Ý  å /áÝ"à—-‘- &×"6Ñ"6Ñ6€ó$ó,,ð. $(Øñ5Øð5àð5ð !ð	5ð
 ð5ð 	ô5r   