
    XR_                         d Z ddlZ ej        e          ZddlmZmZ ddlm	Z	 ddl
mZmZmZ ddlmZ ddlmc mZ g ZdZ G d d	ej        ej        ej        ej                  ZdS )
zpasslib.handlers.sha1_crypt
    N)
safe_crypt
test_crypt)h64)uunicodeirange)compile_hmac    c                       e Zd ZdZd ZdZ ed          ZdZe	j
        ZdZdZe	j
        ZdZdZd	Zd
Zed             ZddZdZed             Zd Zed             Zd Zg dZdS )
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
    )salt	salt_sizeroundsz$sha1$      @   i S    l    linearc                 ^    t          j        || j        |           \  }}} | |||          S )N)handler)r   r   checksum)uh	parse_mc3ident)clshashr   r   chks        =/usr/lib/python3/dist-packages/passlib/handlers/sha1_crypt.pyfrom_stringzsha1_crypt.from_stringS   s8    Lsy#FFFcs&tc::::    Fc                 d    |rd n| j         }t          j        | j        | j        | j        |          S )N)r   r   
render_mc3r   r   r   )selfconfigr   s      r   	to_stringzsha1_crypt.to_stringX   s.    /dd$-}TZdiEEEr    )os_cryptbuiltinc                 ^    t          dd          r|                     | j                   dS dS )Ntestz-$sha1$1$Wq3GL2Vp$C8U25GvfHS8qGHimExLaiSFlGkAeTF)r   _set_calc_checksum_backend_calc_checksum_os_cryptr   s    r   _load_backend_os_cryptz!sha1_crypt._load_backend_os_cryptd   s<    f - . . 	**3+FGGG45r    c                 B   |                      d          }t          ||          }||                     |          S |                    |          r#t	          |          t	          |          dz   k    r!t
          j                            | ||          |dd          S )NT)r$      i)r%   r   _calc_checksum_builtin
startswithlenr   excCryptBackendError)r#   secretr$   r   s       r   r+   z"sha1_crypt._calc_checksum_os_cryptm   s    t,,&&))< ..v666v&& 	?#d))s6{{R7G*G*G&**4>>>CDDzr    c                 :    |                      | j                   dS )NT)r*   r0   r,   s    r   _load_backend_builtinz sha1_crypt._load_backend_builtin{   s    &&s'ABBBtr    c                    t          |t                    r|                    d          }t          |v rt          j                            |           | j        }t          d          | j	        |fz                      d          }t          d|          }t          |          D ]} ||          }t          j        || j                                      d          S )Nzutf-8z
%s$sha1$%sasciisha1)
isinstancer   encode_BNULLr   r3   NullPasswordErrorr   r   r   r	   r   r   encode_transposed_bytes_chk_offsetsdecode)r#   r5   r   result
keyed_hmac_s         r   r0   z!sha1_crypt._calc_checksum_builtin   s    fg&& 	,]]7++FV&**4000L//TY$77??HH!&&11
 	( 	(AZ''FF*643DEELLWUUUr    )   r   r            r            
   	                     r         N)F)__name__
__module____qualname____doc__namesetting_kwdsr   r   checksum_sizer   HASH64_CHARSchecksum_charsdefault_salt_sizemax_salt_size
salt_charsdefault_rounds
min_rounds
max_roundsrounds_costclassmethodr   r%   backendsr-   r+   r7   r0   r@    r    r   r   r      s
        J D2LAhKKEM_N MJ NJJK
 ; ; [;F F F F 'H
   [	 	 	   [V V V  LLLr    r   )rY   logging	getLoggerrV   logpasslib.utilsr   r   passlib.utils.binaryr   passlib.utils.compatr   r   r   passlib.crypto.digestr	   passlib.utils.handlersutilshandlersr   __all__r=   HasManyBackends	HasRoundsHasSaltGenericHandlerr   rh   r    r   <module>rx      s     'g'11 1 0 0 0 0 0 0 0 $ $ $ $ $ $ 3 3 3 3 3 3 3 3 3 3 . . . . . . # # # # # # # # #
 
} } } } }#R\2:r?P } } } } }r    