HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/pymacaroons/__pycache__/utils.cpython-38.pyc
U

�%�Y��@s�ddlZddlmZddlZddlZddlmZmZdd�Zdd�Z	d"dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�ZdS)#�N)�sha256)�	text_type�binary_typecCs:|dkrdSt|t�r |�d�St|t�r.|Std��dS�N�utf-8z!Must be a string or bytes object.)�
isinstancer�encoder�	TypeError�Zstring_or_bytes�r�3/usr/lib/python3/dist-packages/pymacaroons/utils.py�convert_to_bytes	s


r
cCs:|dkrdSt|t�r|St|t�r.|�d�Std��dSr)rrr�decoder	r
rrr�convert_to_strings


rcCsX|dkrd}t|�}t|�}||kr4t|d|��S||krPt|d||�S|SdS)N� �)�	bytearray�len�bytes)Zbyte_string�sizeZ
byte_arrayZlengthrrr�truncate_or_padsrcCs
td|�S)Nsmacaroons-key-generator)�hmac_digest)�keyrrr�generate_derived_key,srcCstj||td���S)N)�msgZ	digestmod)�hmac�newrZdigest)r�datarrrr0s
�rcCst||�}t�|�S�N)r�binasciiZhexlify)rr�digrrr�hmac_hex8s
r!cCst|�}t||�Sr)rr!)rZ
identifierZderived_keyrrr�create_initial_signature=sr"cCs"t||�}t||�}t|||�Sr)rr!)rZdata1Zdata2Zhash1Zhash2rrr�hmac_concatBs

r#cCs
t||�Sr)r!)�	signatureZ	predicaterrr�sign_first_party_caveatHsr%cCst|||�Sr)r#)r$Zverification_idZ	caveat_idrrr�sign_third_party_caveatLsr&cCsHt|�t|�krdSd}t||�D]\}}|t|�t|�AO}q"|dkS)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)Zval1Zval2�result�x�yrrr�equalsPs
r,cCs|dt|�dS)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��brrr�add_base64_paddingbsr1cCs&dsd|krt|�St�t|��SdS)N�_�-)�raw_urlsafe_b64decode�base64Z	b64decoder1��srrr�
raw_b64decodemsr8cCst�t|�d���S)ztBase64 decode with added padding and conversion to bytes.

    @param s string decode
    @return bytes decoded
    r)r5Zurlsafe_b64decoder1rr6rrrr4tsr4cCst�|��d�S)z^Base64 encode with padding removed.

    @param s string decode
    @return bytes decoded
    r-)r5Zurlsafe_b64encode�rstripr/rrr�raw_urlsafe_b64encode}sr:)N)r5ZhashlibrrrZsixrrr
rrrrr!r"r#r%r&r,r1r8r4r:rrrr�<module>s&