%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.9/site-packages/passlib/handlers/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.9/site-packages/passlib/handlers/__pycache__/des_crypt.cpython-39.opt-1.pyc

a

f�Wc_W�@s$dZddlZddlZe�e�ZddlmZddlm	Z	m
Z
mZddlm
Z
mZddlmZmZmZmZmZddlmZddlmmZgd�Zd	Zd
d�Zdd
�Zdd�Zdd�Z Gdd�dej!ej"ej#ej$�Z%Gdd�dej"ej&ej#ej$�Z'Gdd�dej#ej$�Z(Gdd�dej!ej#ej$�Z)dS)zFpasslib.handlers.des_crypt - traditional unix (DES) crypt and variants�N)�warn)�
safe_crypt�
test_crypt�
to_unicode)�h64�h64big)�byte_elem_value�u�
uascii_to_str�unicode�suppress_cause)�des_encrypt_int_block)�	des_crypt�
bsdi_crypt�bigcrypt�crypt16�cCstdd�t|dd��D��S)z�convert secret to 64-bit DES key.

    this only uses the first 8 bytes of the secret,
    and discards the high 8th bit of each byte at that.
    a null parity bit is inserted after every 7th bit of the output.
    css*|]"\}}t|�d@d|d>VqdS)��9�N)r)�.0�i�c�r�>/usr/lib/python3.9/site-packages/passlib/handlers/des_crypt.py�	<genexpr>(s�z'_crypt_secret_to_key.<locals>.<genexpr>Nr)�sum�	enumerate)�secretrrr�_crypt_secret_to_keys�rcCsRt�|�}t|t�r|�d�}t|vr2tj�t	��t
|�}t|d|d�}t�
|�S)z pure-python backed for des_crypt�utf-8r�)r�decode_int12�
isinstancer�encode�_BNULL�uh�exc�NullPasswordErrorrrr
r�encode_int64)r�salt�
salt_value�	key_value�resultrrr�_raw_des_crypt+s



r.cCsLt|�}d}t|�}||krH|d}t|||��}t||�|A}|}q|S)z,convert secret to DES key used by bsdi_cryptr)r�lenr
)rr,�idx�end�nextZ	tmp_valuerrr�_bsdi_secret_to_keyIsr3cCsRt�|�}t|t�r|�d�}t|vr2tj�t	��t
|�}t|d||�}t�
|�S)z"pure-python backend for bsdi_cryptr r)r�decode_int24r#rr$r%r&r'r(rr3r
rr))r�roundsr*r+r,r-rrr�_raw_bsdi_cryptUs


r6c@s�eZdZdZdZdZejZdZ	dZ
ZejZdZ
e�ed�ejejB�Zedd��Zd	d
�Zdd�Zd
Zedd��Zdd�Zedd��Zdd�ZdS)ra�This class implements the des-crypt password hash, and follows the :ref:`password-hash-api`.

    It supports a fixed-length salt.

    The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:

    :type salt: str
    :param salt:
        Optional salt string.
        If not specified, one will be autogenerated (this is recommended).
        If specified, it must be 2 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

    :param bool truncate_error:
        By default, des_crypt will silently truncate passwords larger than 8 bytes.
        Setting ``truncate_error=True`` will cause :meth:`~passlib.ifc.PasswordHash.hash`
        to raise a :exc:`~passlib.exc.PasswordTruncateError` instead.

        .. versionadded:: 1.7

    :type relaxed: bool
    :param relaxed:
        By default, providing an invalid value for one of the other
        keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
        and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
        will be issued instead. Correctable errors include
        ``salt`` strings that are too long.

        .. versionadded:: 1.6
    �r*Ztruncate_error��rzU
        ^
        (?P<salt>[./a-z0-9]{2})
        (?P<chk>[./a-z0-9]{11})?
        $cCs6t|dd�}|dd�|dd�}}|||p0dd�S)N�ascii�hashr9�r*�checksum)r)�clsr;r*�chkrrr�from_string�szdes_crypt.from_stringcCstd�|j|jf}t|�S�Nz%s%s�r	r*r=r
��selfr;rrr�	to_string�szdes_crypt.to_stringcCs|jr|�|�|�|�S)N)�use_defaults�_check_truncate_policyZ_calc_checksum_backend�rDrrrr�_calc_checksum�s
zdes_crypt._calc_checksum�Zos_cryptZbuiltincCs"tdd�r|�|j�dSdSdS)N�testZ
abgOeLfPimXQoTF�r�_set_calc_checksum_backend�_calc_checksum_os_crypt�r>rrr�_load_backend_os_crypt�s
z des_crypt._load_backend_os_cryptcCsTt||j�}|dur|�|�S|�|j�r6t|�dkrHtj�||j|��|dd�S)N�
r9)rr*�_calc_checksum_builtin�
startswithr/r&r'�CryptBackendError)rDrr;rrrrN�s
z!des_crypt._calc_checksum_os_cryptcCs|�|j�dS�NT�rMrRrOrrr�_load_backend_builtin�szdes_crypt._load_backend_builtincCst||j�d���d�S�Nr:)r.r*r$�decoderHrrrrR�sz des_crypt._calc_checksum_builtinN)�__name__�
__module__�__qualname__�__doc__�name�setting_kwdsr&�HASH64_CHARS�checksum_chars�
checksum_size�
min_salt_size�
max_salt_size�
salt_chars�
truncate_size�re�compiler	�X�I�_hash_regex�classmethodr@rErI�backendsrPrNrWrRrrrrrps,$

�



rcs�eZdZdZdZdZdZejZ	dZ
ZejZdZ
dZdZdZe�ed	�ejejB�Zed
d��Zdd
�ZdZe�fdd��Ze�fdd��Z�fdd�ZdZedd��Zdd�Z edd��Z!dd�Z"�Z#S)ra
This class implements the BSDi-Crypt password hash, and follows the :ref:`password-hash-api`.

    It supports a fixed-length salt, and a variable number of rounds.

    The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:

    :type salt: str
    :param salt:
        Optional salt string.
        If not specified, one will be autogenerated (this is recommended).
        If specified, it must be 4 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 5001, must be between 1 and 16777215, inclusive.

    :type relaxed: bool
    :param relaxed:
        By default, providing an invalid value for one of the other
        keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
        and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
        will be issued instead. Correctable errors include ``rounds``
        that are too small or too large, and ``salt`` strings that are too long.

        .. versionadded:: 1.6

    .. versionchanged:: 1.6
        :meth:`hash` will now issue a warning if an even number of rounds is used
        (see :ref:`bsdi-crypt-security-issues` regarding weak DES keys).
    )r*r5r8�i��i���Zlinearz�
        ^
        _
        (?P<rounds>[./a-z0-9]{4})
        (?P<salt>[./a-z0-9]{4})
        (?P<chk>[./a-z0-9]{11})?
        $cCsVt|dd�}|j�|�}|s(tj�|��|�ddd�\}}}|t�|�	d��||d�S)Nr:r;r5r*r?)r5r*r=)
rrk�matchr&r'�InvalidHashError�grouprr4r$)r>r;�mr5r*r?rrrr@4s�zbsdi_crypt.from_stringcCs,td�t�|j��d�|j|jf}t|�S)Nz_%s%s%sr:)r	rZencode_int24r5rYr*r=r
rCrrrrEAs�zbsdi_crypt.to_stringTcs2tt|�jfi|��}|jd@s.tdtjj�|S)NrozHbsdi_crypt rounds should be odd, as even rounds may reveal weak DES keys)�superr�using�default_roundsrr&r'ZPasslibSecurityWarning)r>�kwds�subcls��	__class__rrruNs
�zbsdi_crypt.usingcstt|���}|dBS)Nro)rtr�_generate_rounds)r>r5ryrrr{Wszbsdi_crypt._generate_roundscs$|jd@sdStt|�jfi|��S)NroT)r5rtr�_calc_needs_update)rDrwryrrr|es
zbsdi_crypt._calc_needs_updaterJcCs"tdd�r|�|j�dSdSdS)NrKz_/...lLDAxARksGCHin.TFrLrOrrrrPts
z!bsdi_crypt._load_backend_os_cryptcCs^|��}t||�}|dur$|�|�S|�|dd��rBt|�dkrRtj�|||��|dd�S)N�	����)rErrRrSr/r&r'rT)rDrZconfigr;rrrrN|s

z"bsdi_crypt._calc_checksum_os_cryptcCs|�|j�dSrUrVrOrrrrW�sz bsdi_crypt._load_backend_builtincCst||j|j�d���d�SrX)r6r5r*r$rYrHrrrrR�sz!bsdi_crypt._calc_checksum_builtin)$rZr[r\r]r^r_rbr&r`rarcrdrervZ
min_roundsZ
max_roundsZrounds_costrgrhr	rirjrkrlr@rEZ_avoid_even_roundsrur{r|rmrPrNrWrR�
__classcell__rrryrr�s<#

�




rcsreZdZdZdZdZejZdZ	Z
ejZe�
ed�ejejB�Zedd��Zdd�Zd�fd
d�	Zdd
�Z�ZS)ragThis class implements the BigCrypt password hash, and follows the :ref:`password-hash-api`.

    It supports a fixed-length salt.

    The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:

    :type salt: str
    :param salt:
        Optional salt string.
        If not specified, one will be autogenerated (this is recommended).
        If specified, it must be 22 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

    :type relaxed: bool
    :param relaxed:
        By default, providing an invalid value for one of the other
        keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
        and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
        will be issued instead. Correctable errors include
        ``salt`` strings that are too long.

        .. versionadded:: 1.6
    )r*r9zX
        ^
        (?P<salt>[./a-z0-9]{2})
        (?P<chk>([./a-z0-9]{11})+)?
        $cCsDt|dd�}|j�|�}|s(tj�|��|�dd�\}}|||d�S�Nr:r;r*r?r<�rrkrpr&r'rqrr�r>r;rsr*r?rrrr@�szbigcrypt.from_stringcCstd�|j|jf}t|�SrArBrCrrrrE�szbigcrypt.to_stringFcs0tt|�j||d�}t|�dr,tj�|��|S)N)�relaxedr8)rtr�_norm_checksumr/r&r'rq)rDr=r�ryrrr��szbigcrypt._norm_checksumcCspt|t�r|�d�}t||j�d��}d}t|�}||krf|d}|t|||�|dd��7}|}q2|�d�S)Nr r:rri����)r#rr$r.r*r/rY)rDrr?r0r1r2rrrrI�s

zbigcrypt._calc_checksum)F)rZr[r\r]r^r_r&r`rarcrdrergrhr	rirjrkrlr@rEr�rIr�rrryrr�s

�
	rc@sheZdZdZdZdZdZejZ	dZ
ZejZdZ
e�ed�ejejB�Zedd��Zd	d
�Zdd�Zd
S)ra�This class implements the crypt16 password hash, and follows the :ref:`password-hash-api`.

    It supports a fixed-length salt.

    The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:

    :type salt: str
    :param salt:
        Optional salt string.
        If not specified, one will be autogenerated (this is recommended).
        If specified, it must be 2 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

    :param bool truncate_error:
        By default, crypt16 will silently truncate passwords larger than 16 bytes.
        Setting ``truncate_error=True`` will cause :meth:`~passlib.ifc.PasswordHash.hash`
        to raise a :exc:`~passlib.exc.PasswordTruncateError` instead.

        .. versionadded:: 1.7

    :type relaxed: bool
    :param relaxed:
        By default, providing an invalid value for one of the other
        keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
        and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
        will be issued instead. Correctable errors include
        ``salt`` strings that are too long.

        .. versionadded:: 1.6
    r7�r9�zU
        ^
        (?P<salt>[./a-z0-9]{2})
        (?P<chk>[./a-z0-9]{22})?
        $cCsDt|dd�}|j�|�}|s(tj�|��|�dd�\}}|||d�Sr�r�r�rrrr@+szcrypt16.from_stringcCstd�|j|jf}t|�SrArBrCrrrrE4szcrypt16.to_stringcCs�t|t�r|�d�}|jr$|�|�zt�|j�d��}WntyXt	td���Yn0t
|�}t|d|d�}t
|dd��}t|d|d�}t�
|�t�
|�}|�d�S)	Nr r:zinvalid chars in saltrr~rr��)r#rr$rFrGrr"r*�
ValueErrorrrr
rr)rY)rDrr+Zkey1Zresult1Zkey2Zresult2r?rrrrI;s


zcrypt16._calc_checksumN)rZr[r\r]r^r_rbr&r`rarcrdrerfrgrhr	rirjrkrlr@rErIrrrrr�s$

�
r)*r]rgZloggingZ	getLoggerrZ�log�warningsrZ
passlib.utilsrrrZpasslib.utils.binaryrrZpasslib.utils.compatrr	r
rrZpasslib.crypto.desr
Zpasslib.utils.handlersZutils�handlersr&�__all__r%rr.r3r6Z
TruncateMixinZHasManyBackendsZHasSaltZGenericHandlerrZ	HasRoundsrrrrrrr�<module>s(
$S

Zerion Mini Shell 1.0