U
    ÌZj2  ã                   @   sÞ   U d dl Z d dlZd dlZd dlZd dlZd dlZejr8dZdZ	e
dd„ ejjejjfD ƒƒZeje ed< eedœdd	„Zeeeejeef d
œdd„Zdeeeedœdd„Zeeedœdd„Zeeeje dœdd„ZdS )é    NZ>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789i ÷ c                 c   s"   | ]}|d k	r|dkr|V  qd S )Nú/© ©Ú.0Úsepr   r   úT/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/werkzeug/security.pyÚ	<genexpr>   s      r   Ú_os_alt_seps)ÚlengthÚreturnc                 C   s(   | dkrt dƒ‚d dd„ t| ƒD ƒ¡S )zAGenerate a random string of SALT_CHARS with specified ``length``.r   zSalt length must be positiveÚ c                 s   s   | ]}t  t¡V  qd S ©N)ÚsecretsÚchoiceÚ
SALT_CHARS)r   Ú_r   r   r   r      s     zgen_salt.<locals>.<genexpr>)Ú
ValueErrorÚjoinÚrange)r
   r   r   r   Úgen_salt   s    r   )ÚmethodÚsaltÚpasswordr   c                 C   sÔ   | dkr|| fS |  d¡}|  d¡}|  d¡r¦|s:tdƒ‚| dd…  d¡}t|ƒdkr`td	ƒ‚| d
¡} |r~t|d
 pzd
ƒnt}t 	| |||¡ 
¡ d| › d|› �fS |rÀt ||| ¡ ¡ | fS t | |¡ ¡ | fS )z�Internal password hash helper.  Supports plaintext without salt,
    unsalted and salted passwords.  In case salted passwords are used
    hmac is used.
    Úplainzutf-8zpbkdf2:zSalt is required for PBKDF2é   Nú:)é   é   z&Invalid number of arguments for PBKDF2r   )ÚencodeÚ
startswithr   ÚsplitÚlenÚpopÚintÚDEFAULT_PBKDF2_ITERATIONSÚhashlibÚpbkdf2_hmacÚhexÚhmacÚnewÚ	hexdigest)r   r   r   ÚargsZ
iterationsr   r   r   Ú_hash_internal   s$    



þr,   úpbkdf2:sha256é   )r   r   Úsalt_lengthr   c                 C   s8   |dkrt |ƒnd}t||| ƒ\}}|› d|› d|› �S )aô  Hash a password with the given method and salt with a string of
    the given length. The format of the string returned includes the method
    that was used so that :func:`check_password_hash` can check the hash.

    The format for the hashed string looks like this::

        method$salt$hash

    This method can **not** generate unsalted passwords but it is possible
    to set param method='plain' in order to enforce plaintext passwords.
    If a salt is used, hmac is used internally to salt the password.

    If PBKDF2 is wanted it can be enabled by setting the method to
    ``pbkdf2:method:iterations`` where iterations is optional::

        pbkdf2:sha256:80000$salt$hash
        pbkdf2:sha256$salt$hash

    :param password: the password to hash.
    :param method: the hash method to use (one that hashlib supports). Can
                   optionally be in the format ``pbkdf2:method:iterations``
                   to enable PBKDF2.
    :param salt_length: the length of the salt in letters.
    r   r   ú$)r   r,   )r   r   r/   r   ÚhZactual_methodr   r   r   Úgenerate_password_hash<   s    r2   )Úpwhashr   r   c                 C   s<   |   d¡dk rdS |  dd¡\}}}t t|||ƒd |¡S )aÉ  Check a password against a given salted and hashed password value.
    In order to support unsalted legacy passwords this method supports
    plain text passwords, md5 and sha1 hashes (both salted and unsalted).

    Returns `True` if the password matched, `False` otherwise.

    :param pwhash: a hashed string like returned by
                   :func:`generate_password_hash`.
    :param password: the plaintext password to compare against the hash.
    r0   r   Fr   )Úcountr    r(   Úcompare_digestr,   )r3   r   r   r   Úhashvalr   r   r   Úcheck_password_hash\   s    r7   )Ú	directoryÚ	pathnamesr   c                    sx   | sd} | g}|D ]Z‰ ˆ dkr(t  ˆ ¡‰ t‡ fdd„tD ƒƒs\tj ˆ ¡s\ˆ dks\ˆ  d¡rb dS | ˆ ¡ qt j	|Ž S )a2  Safely join zero or more untrusted path components to a base
    directory to avoid escaping the base directory.

    :param directory: The trusted base directory.
    :param pathnames: The untrusted path components relative to the
        base directory.
    :return: A safe path, otherwise ``None``.
    Ú.r   c                 3   s   | ]}|ˆ kV  qd S r   r   r   ©Úfilenamer   r   r   ƒ   s     zsafe_join.<locals>.<genexpr>z..z../N)
Ú	posixpathÚnormpathÚanyr	   ÚosÚpathÚisabsr   Úappendr   )r8   r9   Úpartsr   r;   r   Ú	safe_joinn   s"    	
ÿ
þýürE   )r-   r.   )r%   r(   r@   r=   r   ÚtypingÚtÚTYPE_CHECKINGr   r$   ÚlistrA   r   Úaltsepr	   ÚListÚstrÚ__annotations__r#   r   ÚTupler,   r2   Úboolr7   ÚOptionalrE   r   r   r   r   Ú<module>   s0    ÿ"   ÿ  þ 