관리-도구
편집 파일: sha2_crypt.cpython-39.opt-1.pyc
a ����f�Wc(U����������������������@���s����d�Z�ddlZddlZe�e�ZddlmZmZm Z m Z �ddlmZ�ddl mZmZmZmZ�ddlm��mZ�ddgZdZd Zd ZdZdd d�Zed�Zed�Zed�ZG�dd��dejej ej!ej"�Z#G�dd��de#�Z$G�dd��de#�Z%dS�)z9passlib.handlers.sha2_crypt - SHA256-Crypt / SHA512-Crypt�����N)� safe_crypt� test_crypt� repeat_string� to_unicode)�h64)�byte_elem_value�u� uascii_to_str�unicode�sha512_crypt�sha256_crypt�����))r�����������������r���r���)r�������r���r����r���r���)����r���r���r���)r���r���r���r���r���)r���r���r���r���)r���r���r���r���r���) ����� ���r�������r�������r���������������� ���r�������r�������r�������������������������������������������������������� �����������)@�*���r���r���r����+���r���r���r����,����-���r���r���r����.���r ���r"���r����/����0���r'���r$���r&����1���r)���r+���r(����2����3���r.���r-���r����4���r/���� ���r����5����6����!���r���r����7����"����#���r����8����9����$���r!���r#����:����%����&���r%����;����<����'���r*���r,����=����(����)���r����>����?���Fc��������������������sJ��t�|�t�r|��d�}�t|�v�r0tj�|r*tnt��t |��}|�d�}t |�}|rZt j}t}n t j }t}||�|�|������}||�|��} | j} | t||���|}|r�| |d@�r�|n|���|dL�}q�| ���}|dk�r�t||�|�����|�} n<||��}|j}|d�}|�r||���|d8�}q�t|���|�} ||dt|d��������d|��}| | �}| |�}| |||| �|| �||�g����fdd �tD��}|}t|d �\}}|�r�|D�]&\}}|||||����������}�q�|d8�}�q�|�r8|d?�}|d|��D�]&\}}|||||����������}�q�|d@��r8||||�d������}t�||��d�S�)a���perform raw sha256-crypt / sha512-crypt this function provides a pure-python implementation of the internals for the SHA256-Crypt and SHA512-Crypt algorithms; it doesn't handle any of the parsing/validation of the hash strings themselves. :arg pwd: password chars/bytes to hash :arg salt: salt chars to use :arg rounds: linear rounds cost :arg use_512: use sha512-crypt instead of sha256-crypt mode :returns: encoded checksum chars zutf-8�asciir����`���r#���r���Nc��������������������s ���g�|�]\}}��|���|�f�qS���rR���)�.0�even�odd�ZpermsrR����?/usr/lib/python3.9/site-packages/passlib/handlers/sha2_crypt.py� <listcomp>���������z#_raw_sha2_crypt.<locals>.<listcomp>r0���)� isinstancer ����encode�_BNULL�uh�excZNullPasswordErrorr���r����len�hashlibZsha512�_512_transpose_mapZsha256�_256_transpose_map�digest�updater���r����_c_digest_offsets�divmodr���Zencode_transposed_bytes�decode)�pwd�salt�roundsZuse_512Zpwd_lenZsalt_lenZ hash_constZ transpose_mapZdbZa_ctxZa_ctx_update�i�daZdpZtmp_ctxZtmp_ctx_updateZdsZdp_dpZdp_ds�dataZdcZblocks�tailrT���rU����pairsrR���rV���rW����_raw_sha2_crypt8���s`����! $/ rp���zrounds=�$�0c�����������������������s����e�Zd�ZdZdZejZdZejZ dZ dZdZdZ dZdZd��fd d � Zdd��Zd d��Zedd���Zdd��ZdZdZedd���Zdd��Zedd���Zdd��Z���ZS�)�_SHA2_CommonzBclass containing common code shared by sha256_crypt & sha512_crypt)ri���rj����implicit_roundsZ salt_sizer#���i���i�ɚ;ZlinearFNc��������������������s8���t�t|��jf�i�|���|d�u�r.|�jo,|�jdk}||�_d�S�)N���)�superrs����__init__Zuse_defaultsrj���rt���)�selfrt����kwds�� __class__rR���rW���rw�����s����z_SHA2_Common.__init__c�����������������C���s���|�j�||�jd�u�d�S��N)Zrelaxed)Z _norm_salt�checksum)rx���ri���rR���rR���rW����_parse_salt��s����z_SHA2_Common._parse_saltc�����������������C���s���|�j�||�jd�u�d�S�r|���)Z_norm_roundsr}���)rx���rj���rR���rR���rW���� _parse_rounds#��s����z_SHA2_Common._parse_roundsc�����������������C���s����t�|dd�}|�j}|�|�s(tj�|���|dd����t�}|d��t�r�|� d�dd���}|�t �rx|t krxtj�|���t|�}d}nd}d}t |�d kr�|\}}n&t |�d kr�|d�}d�}ntj�|���|�|||p�d�|d�S�)NrP����hashr���r���r&���Fru���Tr���r���)rj���ri���r}���rt���)r����ident� startswithr]���r^���ZInvalidHashError�split�_UDOLLAR�_UROUNDS�pop�_UZEROZZeroPaddedRoundsError�intr_���ZMalformedHashError)�clsr����r�����partsrj���rt���ri���ZchkrR���rR���rW����from_string'��s2���� �z_SHA2_Common.from_stringc�����������������C���s^���|�j�dkr2|�jr2td�|�j|�j|�jp*td�f�}n$td�|�j|�j�|�j|�jpPtd�f�}t|�S�)Nru���z%s%s$%s��z%srounds=%d$%s$%s)rj���rt���r���r����ri���r}���r ���)rx���r����rR���rR���rW���� to_stringT��s������z_SHA2_Common.to_string)Zos_cryptZbuiltinc�����������������C���s"���t�|�j��r|��|�j��dS�dS�d�S�)NTF)r���� _test_hash�_set_calc_checksum_backend�_calc_checksum_os_crypt�r����rR���rR���rW����_load_backend_os_crypti��s���� z#_SHA2_Common._load_backend_os_cryptc�����������������C���sf���|�����}t||�}|d�u�r$|��|�S�|�j}|�|�j�rH||�d��tkrXtj� |�||��||�d���S�)Nr���) r����r����_calc_checksum_builtin� checksum_sizer����r����r����r]���r^���ZCryptBackendError)rx����secretZconfigr�����csrR���rR���rW���r����q��s���� z$_SHA2_Common._calc_checksum_os_cryptc�����������������C���s���|���|�j��dS�)NT)r����r����r����rR���rR���rW����_load_backend_builtin���s����z"_SHA2_Common._load_backend_builtinc�����������������C���s���t�||�j|�j|�j�S�)N)rp���ri���rj����_cdb_use_512)rx���r����rR���rR���rW���r�������s�����z#_SHA2_Common._calc_checksum_builtin)N)�__name__� __module__�__qualname__�__doc__Zsetting_kwdsr]���ZHASH64_CHARSZchecksum_charsZ max_salt_sizeZ salt_charsZ min_roundsZ max_roundsZrounds_costr����Z_rounds_prefixrt���rw���r~���r����classmethodr����r����Zbackendsr����r����r����r����r����� __classcell__rR���rR���rz���rW���rs�������s2��� , rs���c�������������������@���s(���e�Zd�ZdZd�Zed�ZdZdZdZ dS�)r���aK��This class implements the SHA256-Crypt password hash, and follows the :ref:`password-hash-api`. It supports a variable-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 0-16 characters, drawn from the regexp range ``[./0-9A-Za-z]``. :type rounds: int :param rounds: Optional number of rounds to use. Defaults to 535000, must be between 1000 and 999999999, inclusive. .. note:: per the official specification, when the rounds parameter is set to 5000, it may be omitted from the hash string. :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 .. commented out, currently only supported by :meth:`hash`, and not via :meth:`using`: :type implicit_rounds: bool :param implicit_rounds: this is an internal option which generally doesn't need to be touched. this flag determines whether the hash should omit the rounds parameter when encoding it to a string; this is only permitted by the spec for rounds=5000, and the flag is ignored otherwise. the spec requires the two different encodings be preserved as they are, instead of normalizing them. z$5$r1���i�)�)�testz?$5$rounds=1000$test$QmQADEXMG8POI5WDsaeho0P36yK3Tcrgboabng6bkb/N) r����r����r����r�����namer���r����r�����default_roundsr����rR���rR���rR���rW���r������s���.c�������������������@���s,���e�Zd�ZdZd�Zed�ZdZdZdZ dZ dS�)r���aK��This class implements the SHA512-Crypt password hash, and follows the :ref:`password-hash-api`. It supports a variable-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 0-16 characters, drawn from the regexp range ``[./0-9A-Za-z]``. :type rounds: int :param rounds: Optional number of rounds to use. Defaults to 656000, must be between 1000 and 999999999, inclusive. .. note:: per the official specification, when the rounds parameter is set to 5000, it may be omitted from the hash string. :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 .. commented out, currently only supported by :meth:`hash`, and not via :meth:`using`: :type implicit_rounds: bool :param implicit_rounds: this is an internal option which generally doesn't need to be touched. this flag determines whether the hash should omit the rounds parameter when encoding it to a string; this is only permitted by the spec for rounds=5000, and the flag is ignored otherwise. the spec requires the two different encodings be preserved as they are, instead of normalizing them. z$6$�V���Ti� �)r����zj$6$rounds=1000$test$2M/Lx6MtobqjLjobw0Wmo4Q5OFx5nVLJvmgseatA6oMnyWeBdRDx4DU.1H3eGmse6pgsOgDisWBGI5c7TZauS0N)r����r����r����r����r����r���r����r����r����r����r����rR���rR���rR���rW���r������s���/)F)&r����r`���ZloggingZ getLoggerr�����logZ passlib.utilsr���r���r���r���Zpasslib.utils.binaryr���Zpasslib.utils.compatr���r���r ���r ���Zpasslib.utils.handlersZutils�handlersr]����__all__r\���re���rb���ra���rp���r����r����r����ZHasManyBackendsZ HasRoundsZHasSaltZGenericHandlerrs���r���r���rR���rR���rR���rW����<module>���s0���� �B��B