U
    d                     @  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 dlZdZdZ	e
dd ejejjfD Zded< d	d
dddZd
d
d
ddddZdd
d
d	d
dddZd
d
ddddZd
d
ddddZdS )     )annotationsNZ>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789i'	 c                 c  s"   | ]}|d k	r|dkr|V  qd S )N/ .0sepr   r   5/tmp/pip-unpacked-wheel-m99gisyz/werkzeug/security.py	<genexpr>   s      r	   z	list[str]_os_alt_sepsintstr)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 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   ztuple[str, str])methodsaltpasswordr   c                 C  s  | dkrt jddd || fS | d^} }|d}|d}| dkr|sZd}d	}d
}n4ztt|\}}}W n tk
r   tdd Y nX d| | | }tj||||||d	 d| d| d| fS | dkrVt
|}|dkrd}	t}
n@|d
kr
|d }	t}
n(|dkr*|d }	t|d
 }
ntdt|	|||
	 d|	 d|
 fS t jd|  ddd t|||  | fS d S )NplainznThe 'plain' password method is deprecated and will be removed in Werkzeug 3.0. Migrate to the 'scrypt' method.   )
stacklevel:zutf-8scrypti         z'scrypt' takes 3 arguments.   )r   nrpmaxmemzscrypt:pbkdf2r   sha256   z'pbkdf2' takes 2 arguments.zpbkdf2:zThe 'zd' password method is deprecated and will be removed in Werkzeug 3.0. Migrate to the 'scrypt' method.)warningswarnsplitencodemapr   r   hashlibr    hexlenDEFAULT_PBKDF2_ITERATIONSpbkdf2_hmachmacnew	hexdigest)r   r   r   argsr$   r%   r&   r'   Zlen_args	hash_nameZ
iterationsr   r   r   _hash_internal   sT    





r:   r(      )r   r   salt_lengthr   c                 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``, more secure but not available on PyPy. The parameters are ``n``,
        ``r``, and ``p``, the default is ``scrypt:32768:8:1``. See
        :func:`hashlib.scrypt`.
    -   ``pbkdf2``, the default. 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   r:   )r   r   r<   r   hZactual_methodr   r   r   generate_password_hashS   s     r?   bool)pwhashr   r   c                 C  sF   z|  dd\}}}W n tk
r,   Y dS X 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.
    r=   r*   Fr   )r-   r   r5   compare_digestr:   )rA   r   r   r   Zhashvalr   r   r   check_password_hashx   s
    rC   z
str | None)	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isabs
startswithappendr   )rD   rE   partsr   rG   r   	safe_join   s"    	

rR   )r(   r;   )
__future__r   r0   r5   rL   rI   r   r+   r   r3   listr   rM   altsepr
   __annotations__r   r:   r?   rC   rR   r   r   r   r   <module>   s&    :   %