HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ns3133907 6.8.0-86-generic #87-Ubuntu SMP PREEMPT_DYNAMIC Mon Sep 22 18:03:36 UTC 2025 x86_64
User: cssnetorguk (1024)
PHP: 8.2.28
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/pymacaroons/__pycache__/utils.cpython-312.pyc
�

�%�Y����ddlZddlmZddlZddlZddlmZmZd�Zd�Z	dd�Z
d�Zd�Zd	�Z
d
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zy)�N)�sha256)�	text_type�binary_typec��|�yt|t�r|jd�St|t�r|St	d���N�utf-8z!Must be a string or bytes object.)�
isinstancer�encoder�	TypeError��string_or_bytess �3/usr/lib/python3/dist-packages/pymacaroons/utils.py�convert_to_bytesr	sB������/�9�-��%�%�g�.�.�	�O�[�	1����;�<�<�c��|�yt|t�r|St|t�r|jd�St	d��r)r	rr�decoderrs r�convert_to_stringrsB������/�9�-���	�O�[�	1��%�%�g�.�.��;�<�<rc��|�d}t|�}t|�}||kDrt|d|�S||krt|d||z
zz�S|S)N� �)�	bytearray�len�bytes)�byte_string�size�
byte_array�lengths    r�truncate_or_padrs^���|����;�'�J�
��_�F�
��}��Z���&�'�'�	�$���Z�%��f��"5�5�6�6��rc��td|�S)Nsmacaroons-key-generator)�hmac_digest)�keys r�generate_derived_keyr",s���1�3�7�7rc�V�tj||t��j�S)N)�msg�	digestmod)�hmac�newr�digest)r!�datas  rr r 0s%���8�8�����
�f�h�	rc�D�t||�}tj|�S�N)r �binascii�hexlify)r!r)�digs   r�hmac_hexr/8s��
�c�4�
 �C����C� � rc�0�t|�}t||�Sr+)r"r/)r!�
identifier�derived_keys   r�create_initial_signaturer3=s��&�s�+�K��K��,�,rc�P�t||�}t||�}t|||z�Sr+)r r/)r!�data1�data2�hash1�hash2s     r�hmac_concatr9Bs+����U�#�E���U�#�E��C����'�'rc��t||�Sr+)r/)�	signature�	predicates  r�sign_first_party_caveatr=Hs���I�y�)�)rc��t|||�Sr+)r9)r;�verification_id�	caveat_ids   r�sign_third_party_caveatrALs���y�/�9�=�=rc��t|�t|�k7ryd}t||�D]\}}|t|�t|�zz}�!|dk(S)aE
    Returns True if the two strings are equal, False otherwise.

    The time taken is independent of the number of characters that match.

    For the sake of simplicity, this function executes in constant time only
    when the two strings have the same length. It short-circuits when they
    have different lengths.
    Fr)r�zip�ord)�val1�val2�result�x�ys     r�equalsrJPsU���4�y�C��I���
�F��D�$��"���1��#�a�&�3�q�6�/�!��"��Q�;�rc�,�|dt|�dzzzS)z�Add padding to base64 encoded bytes.

    Padding can be removed when sending the messages.

    @param b bytes to be padded.
    @return a padded bytes.
    �=�)r��bs r�add_base64_paddingrPbs��
�t��A��w��{�#�#�#rc��	t|�Sr+)�raw_urlsafe_b64decode�base64�	b64decoderP��ss r�
raw_b64decoderWms��
�$�Q�'�'rc�\�tjt|jd���S)ztBase64 decode with added padding and conversion to bytes.

    @param s string decode
    @return bytes decoded
    r)rS�urlsafe_b64decoderPr
rUs rrRrRts$���#�#�$6�q�x�x��7H�$I�J�Jrc�J�tj|�jd�S)z^Base64 encode with padding removed.

    @param s string decode
    @return bytes decoded
    rL)rS�urlsafe_b64encode�rstriprNs r�raw_urlsafe_b64encoder]}s ���#�#�A�&�-�-�d�3�3rr+)rS�hashlibrr&r,�sixrrrrrr"r r/r3r9r=rArJrPrWrRr]�rr�<module>ras`��
����&�=�=�
�8��!�
-�
(�*�>��$$�7�K�4r