File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/pycrypto.cpython-310.pyc
o
�N�g� � @ sv d Z ddlZddlZddlZddlZddlZddlZddlm Z m
Z
z.zddlmZ
W n! eyL zddlm
Z
W n eyI ddlm
Z
Y nw Y nw dZW n ey[ dZY nw zddlZdZW n
eefyq dZY nw zddlZdZW n ey� dZY nw e�e�Z dd d
�Zer�dd� ejD �Zni Zg d
�Zddd�Zddd�Zddd�Z dS )z7
Use pycrypto to generate random passwords on the fly.
� N)�CommandExecutionError�SaltInvocationError)�
rand_bytes)�get_random_bytesTF� c
C sD |pd}|r t j}|s.|r|t j7 }|r|t j7 }|r |t j7 }|r'|t j7 }|r.|t j7 }z\t| �} d} t| �| k r�t ry|ryd}
t
jj�
� rId}
z
t
jjjtd�|
d�}W n ty` Y qIw | t�t
jjjdt�|�� d�|
d�d|�7 } n | t�� �|�7 } t| �| k s;| W S ty� } zt�d � tt|���d}~ww )
z%
Generate a secure password.
� NzUTF-8T� )�encodingz[^�]z#Failed to generate secure passsword)�string� printable�ascii_lowercase�ascii_uppercase�digits�punctuation�
whitespace�int�len�
HAS_RANDOM�salt�utils�platformZ
is_windowsZstringutilsZto_strr �UnicodeDecodeError�re�sub�escape�random�SystemRandom�choice� Exception�log� exceptionr �str)
�lengthZ
use_random�charsZ lowercaseZ uppercaser r r r Zpwr �char�exc� r'