o
    ê}”e®  ã                   @  sœ   U d dl mZ d dlZd dlZd dlZd dlZd dlZdZdZe	dd„ ej
ejjfD ƒƒZded< d#dd„Zd$dd„Z	d%d&dd„Zd'dd„Zd(d!d"„ZdS ))é    )ÚannotationsNZ>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789iÀ'	 c                 c  s$   � | ]}|d ur|dkr|V  qd S )Nú/© ©Ú.0Úsepr   r   úZ/Users/abhinavbhinder/Documents/map/venv/lib/python3.10/site-packages/werkzeug/security.pyÚ	<genexpr>   s   € ÿÿ
ÿr	   z	list[str]Ú_os_alt_sepsÚlengthÚintÚreturnÚstrc                 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 at least 1.Ú 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Úpasswordútuple[str, str]c                 C  s<  |   d¡^} }| d¡}| d¡}| dkrU|sd}d}d}nz
tt|ƒ\}}}W n ty4   tdƒd ‚w d| | | }tj||||||d	� ¡ d
|› d|› d|› �fS | dkr–t|ƒ}|dkrfd}	t	}
n|dkrq|d }	t	}
n|dkr€|d }	t|d ƒ}
ntdƒ‚t 
|	|||
¡ ¡ d|	› d|
› �fS td| › d�ƒ‚)Nú:zutf-8Úscrypti €  é   é   z'scrypt' takes 3 arguments.é„   )r   ÚnÚrÚpÚmaxmemzscrypt:Zpbkdf2r   Úsha256é   z'pbkdf2' takes 2 arguments.zpbkdf2:zInvalid hash method 'z'.)ÚsplitÚencodeÚmapr   r   Úhashlibr   ÚhexÚlenÚDEFAULT_PBKDF2_ITERATIONSÚpbkdf2_hmac)r   r   r   Úargsr"   r#   r$   r%   Zlen_argsÚ	hash_nameZ
iterationsr   r   r   Ú_hash_internal   sB   


ÿþþr2   r   é   Úsalt_lengthc                 C  s,   t |ƒ}t||| ƒ\}}|› d|› d|› �S )aá  Securely hash a password for storage. A password can be compared to a stored hash
    using :func:`check_password_hash`.

    The following methods are supported:

    -   ``scrypt``, the default. The parameters are ``n``, ``r``, and ``p``, the default
        is ``scrypt:32768:8:1``. See :func:`hashlib.scrypt`.
    -   ``pbkdf2``, less secure. The parameters are ``hash_method`` and ``iterations``,
        the default is ``pbkdf2:sha256:600000``. See :func:`hashlib.pbkdf2_hmac`.

    Default parameters may be updated to reflect current guidelines, and methods may be
    deprecated and removed if they are no longer considered secure. To migrate old
    hashes, you may generate a new hash when checking an old hash, or you may contact
    users with a link to reset their password.

    :param password: The plaintext password.
    :param method: The key derivation function and parameters.
    :param salt_length: The number of characters to generate for the salt.

    .. versionchanged:: 2.3
        Scrypt support was added.

    .. versionchanged:: 2.3
        The default iterations for pbkdf2 was increased to 600,000.

    .. versionchanged:: 2.3
        All plain hashes are deprecated and will not be supported in Werkzeug 3.0.
    ú$)r   r2   )r   r   r4   r   ÚhZactual_methodr   r   r   Úgenerate_password_hashE   s   r7   ÚpwhashÚboolc                 C  sD   z|   dd¡\}}}W n
 ty   Y dS w t t|||ƒd |¡S )aA  Securely check that the given stored password hash, previously generated using
    :func:`generate_password_hash`, matches the given password.

    Methods may be deprecated and removed if they are no longer considered secure. To
    migrate old hashes, you may generate a new hash when checking an old hash, or you
    may contact users with a link to reset their password.

    :param pwhash: The hashed password.
    :param password: The plaintext password.

    .. versionchanged:: 2.3
        All plain hashes are deprecated and will not be supported in Werkzeug 3.0.
    r5   r'   Fr   )r(   r   ÚhmacÚcompare_digestr2   )r8   r   r   r   Zhashvalr   r   r   Úcheck_password_hashi   s   ÿr<   Ú	directoryÚ	pathnamesú
str | Nonec                   sx   | sd} | g}|D ]-‰ ˆ dkrt  ˆ ¡‰ t‡ fdd„tD ƒƒs.tj ˆ ¡s.ˆ dks.ˆ  d¡r1 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   � | ]}|ˆ v V  qd S r   r   r   ©Úfilenamer   r   r	   ”   s   € zsafe_join.<locals>.<genexpr>z..z../N)
Ú	posixpathÚnormpathÚanyr
   ÚosÚpathÚisabsÚ
startswithÚappendr   )r=   r>   Úpartsr   rA   r   Ú	safe_join   s"   	
ÿ
þýü
rL   )r   r   r   r   )r   r   r   r   r   r   r   r   )r   r3   )r   r   r   r   r4   r   r   r   )r8   r   r   r   r   r9   )r=   r   r>   r   r   r?   )Ú
__future__r   r+   r:   rF   rC   r   r   r.   Úlistr   rG   Úaltsepr
   Ú__annotations__r   r2   r7   r<   rL   r   r   r   r   Ú<module>   s"    ÿ

-ÿ
$