a fWc@sdZddlZeeZddlmZmZddlm Z ddl m Z m Z m Z ddlmZddlmmZgZdZGdd d ejejejejZdS) zpasslib.handlers.sha1_crypt N) safe_crypt test_crypt)h64)uunicodeirange) compile_hmacc@seZdZdZdZdZedZdZe j Z dZ dZ e j ZdZdZd Zd Zed d ZdddZdZeddZddZeddZddZgdZdS) sha1_crypta&This class implements the SHA1-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, an 8 character one will be autogenerated (this is recommended). If specified, it must be 0-64 characters, drawn from the regexp range ``[./0-9A-Za-z]``. :type salt_size: int :param salt_size: Optional number of bytes to use when autogenerating new salts. Defaults to 8 bytes, but can be any value between 0 and 64. :type rounds: int :param rounds: Optional number of rounds to use. Defaults to 480000, must be between 1 and 4294967295, 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 )saltZ salt_sizeroundsz$sha1$@iSlZlinearcCs&tj||j|d\}}}||||dS)N)Zhandler)r r checksum)uhZ parse_mc3ident)clshashr r chkr?/usr/lib/python3.9/site-packages/passlib/handlers/sha1_crypt.py from_stringSszsha1_crypt.from_stringFcCs$|rdn|j}t|j|j|j|S)N)rrZ render_mc3rr r )selfconfigrrrr to_stringXszsha1_crypt.to_string)Zos_cryptZbuiltincCs"tddr||jdSdSdS)Ntestz-$sha1$1$Wq3GL2Vp$C8U25GvfHS8qGHimExLaiSFlGkAeTF)r_set_calc_checksum_backend_calc_checksum_os_cryptrrrr_load_backend_os_cryptds  z!sha1_crypt._load_backend_os_cryptcCsb|jdd}t||}|dur(||S||rFt|t|dkrVtj||||ddS)NT)ri)rr_calc_checksum_builtin startswithlenrexcZCryptBackendError)rsecretrrrrrrms   z"sha1_crypt._calc_checksum_os_cryptcCs||jdS)NT)rr#r rrr_load_backend_builtin{s z sha1_crypt._load_backend_builtincCszt|tr|d}t|vr(tj||j}td|j |fd}t d|}t |D] }||}qXt ||jdS)Nzutf-8z %s$sha1$%sasciiZsha1) isinstancerencode_BNULLrr&ZNullPasswordErrorr rr rrrZencode_transposed_bytes _chk_offsetsdecode)rr'r resultZ keyed_hmac_rrrr#s      z!sha1_crypt._calc_checksum_builtin)rrr  rN)F)__name__ __module__ __qualname____doc__nameZ setting_kwdsrrZ checksum_sizerZ HASH64_CHARSZchecksum_charsZdefault_salt_sizeZ max_salt_sizeZ salt_charsZdefault_roundsZ min_roundsZ max_roundsZ rounds_cost classmethodrrZbackendsr!rr(r#r-rrrrr s0%    r )rEZloggingZ getLoggerrBlogZ passlib.utilsrrZpasslib.utils.binaryrZpasslib.utils.compatrrrZpasslib.crypto.digestrZpasslib.utils.handlersZutilshandlersr__all__r,ZHasManyBackendsZ HasRoundsZHasSaltZGenericHandlerr rrrrs