%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.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�rcCspt|�dksJ�t�|�}t|t�r.|�d�}t|t�s<J�t|vrPtj	�
t��t|�}t
|d|d�}t�|�S)z pure-python backed for des_crypt��utf-8r�)�lenr�decode_int12�
isinstancer�encode�bytes�_BNULL�uh�exc�NullPasswordErrorrrr
r�encode_int64)r�salt�
salt_value�	key_value�resultrrr�_raw_des_crypt+s


r1cCsLt|�}d}t|�}||krH|d}t|||��}t||�|A}|}q|S)z,convert secret to DES key used by bsdi_cryptr)rr#r
)rr/�idx�end�nextZ	tmp_valuerrr�_bsdi_secret_to_keyIsr5cCs`t�|�}t|t�r|�d�}t|t�s,J�t|vr@tj�	t
��t|�}t|d||�}t
�|�S)z"pure-python backend for bsdi_cryptr!r)r�decode_int24r%rr&r'r(r)r*r+rr5r
rr,)r�roundsr-r.r/r0rrr�_raw_bsdi_cryptUs


r8c@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�r rzU
        ^
        (?P<salt>[./a-z0-9]{2})
        (?P<chk>[./a-z0-9]{11})?
        $cCs6t|dd�}|dd�|dd�}}|||p0dd�S)N�ascii�hashr �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�rErrrr�_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�
r )rr-�_calc_checksum_builtin�
startswithr#r)r*�CryptBackendError)rErr<rrrrO�s
z!des_crypt._calc_checksum_os_cryptcCs|�|j�dS�NT�rNrSrPrrr�_load_backend_builtin�szdes_crypt._load_backend_builtincCst||j�d���d�S�Nr;)r1r-r&�decoderIrrrrS�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�classmethodrArFrJ�backendsrQrOrXrSrrrrrps,$

�



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-r7r:�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<r7r-r@)r7r-r>)
rrl�matchr)r*�InvalidHashError�grouprr6r&)r?r<�mr7r-r@rrrrA4s�zbsdi_crypt.from_stringcCs,td�t�|j��d�|j|jf}t|�S)Nz_%s%s%sr;)r	rZencode_int24r7rZr-r>r
rDrrrrFAs�zbsdi_crypt.to_stringTcs2tt|�jfi|��}|jd@s.tdtjj�|S)NrpzHbsdi_crypt rounds should be odd, as even rounds may reveal weak DES keys)�superr�using�default_roundsrr)r*ZPasslibSecurityWarning)r?�kwds�subcls��	__class__rrrvNs
�zbsdi_crypt.usingcstt|���}|dBS)Nrp)rur�_generate_rounds)r?r7rzrrr|Wszbsdi_crypt._generate_roundscs$|jd@sdStt|�jfi|��S)NrpT)r7rur�_calc_needs_update)rErxrzrrr}es
zbsdi_crypt._calc_needs_updaterKcCs"tdd�r|�|j�dSdSdS)NrLz_/...lLDAxARksGCHin.TFrMrPrrrrQts
z!bsdi_crypt._load_backend_os_cryptcCs^|��}t||�}|dur$|�|�S|�|dd��rBt|�dkrRtj�|||��|dd�S)N�	����)rFrrSrTr#r)r*rU)rErZconfigr<rrrrO|s

z"bsdi_crypt._calc_checksum_os_cryptcCs|�|j�dSrVrWrPrrrrX�sz bsdi_crypt._load_backend_builtincCst||j|j�d���d�SrY)r8r7r-r&rZrIrrrrS�sz!bsdi_crypt._calc_checksum_builtin)$r[r\r]r^r_r`rcr)rarbrdrerfrwZ
min_roundsZ
max_roundsZrounds_costrhrir	rjrkrlrmrArFZ_avoid_even_roundsrvr|r}rnrQrOrXrS�
__classcell__rrrzrr�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-r zX
        ^
        (?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=�rrlrqr)r*rrrs�r?r<rtr-r@rrrrA�szbigcrypt.from_stringcCstd�|j|jf}t|�SrBrCrDrrrrF�szbigcrypt.to_stringFcs0tt|�j||d�}t|�dr,tj�|��|S)N)�relaxedr:)rur�_norm_checksumr#r)r*rr)rEr>r�rzrrr��szbigcrypt._norm_checksumcCspt|t�r|�d�}t||j�d��}d}t|�}||krf|d}|t|||�|dd��7}|}q2|�d�S)Nr!r;rr�i����)r%rr&r1r-r#rZ)rErr@r2r3r4rrrrJ�s

zbigcrypt._calc_checksum)F)r[r\r]r^r_r`r)rarbrdrerfrhrir	rjrkrlrmrArFr�rJr�rrrzrr�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
    r9�r �zU
        ^
        (?P<salt>[./a-z0-9]{2})
        (?P<chk>[./a-z0-9]{22})?
        $cCsDt|dd�}|j�|�}|s(tj�|��|�dd�\}}|||d�Sr�r�r�rrrrA+szcrypt16.from_stringcCstd�|j|jf}t|�SrBrCrDrrrrF4szcrypt16.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 saltrrrr��)r%rr&rGrHrr$r-�
ValueErrorrrr
rr,rZ)rErr.Zkey1Zresult1Zkey2Zresult2r@rrrrJ;s


zcrypt16._calc_checksumN)r[r\r]r^r_r`rcr)rarbrdrerfrgrhrir	rjrkrlrmrArFrJrrrrr�s$

�
r)*r^rhZloggingZ	getLoggerr[�log�warningsrZ
passlib.utilsrrrZpasslib.utils.binaryrrZpasslib.utils.compatrr	r
rrZpasslib.crypto.desr
Zpasslib.utils.handlersZutils�handlersr)�__all__r(rr1r5r8Z
TruncateMixinZHasManyBackendsZHasSaltZGenericHandlerrZ	HasRoundsrrrrrrr�<module>s(
$S

Zerion Mini Shell 1.0