
    g                         S r SSKr\R                  " \5      rSSKJrJr  SSKJ	r	  SSK
JrJrJr  SSKJr  SSKJs  Jr  / rSr " S S	\R,                  \R.                  \R0                  \R2                  5      rg)
zpasslib.handlers.sha1_crypt
    N)
safe_crypt
test_crypt)h64)uunicodeirange)compile_hmac    c                       \ rS rSrSrS rSr\" S5      rSr	\
R                  rSrSr\
R                  rSrS	rS
rSr\S 5       rSS jrSr\S 5       rS r\S 5       rS r/ SQrSrg)
sha1_crypt   a  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    [         R                  " XR                  U S9u  p#nU " X#US9$ )N)handler)r   r   checksum)uh	parse_mc3ident)clshashr   r   chks        T/home/matz/Project1/venv/lib/python3.13/site-packages/passlib/handlers/sha1_crypt.pyfrom_stringsha1_crypt.from_stringS   s(    LLyy#Fc&c::    c                     U(       a  S OU R                   n[        R                  " U R                  U R                  U R
                  U5      $ )N)r   r   
render_mc3r   r   r   )selfconfigr   s      r   	to_stringsha1_crypt.to_stringX   s0    d$--}}TZZdiiEEr"   )os_cryptbuiltinc                 ^    [        SS5      (       a  U R                  U R                  5        gg)Ntestz-$sha1$1$Wq3GL2Vp$C8U25GvfHS8qGHimExLaiSFlGkAeTF)r   _set_calc_checksum_backend_calc_checksum_os_cryptr   s    r   _load_backend_os_crypt!sha1_crypt._load_backend_os_cryptd   s0    f - . .**3+F+FGr"   c                 
   U R                  SS9n[        X5      nUc  U R                  U5      $ UR                  U5      (       a  [	        U5      [	        U5      S-   :w  a   [
        R                  R                  XU5      eUSS  $ )NT)r&      i)r'   r   _calc_checksum_builtin
startswithlenr   excCryptBackendError)r%   secretr&   r   s       r   r.   "sha1_crypt._calc_checksum_os_cryptm   sz    t,&)< ..v66v&&#d)s6{R7G*G&&**4>>CDzr"   c                 :    U R                  U R                  5        g)NT)r-   r4   r/   s    r   _load_backend_builtin sha1_crypt._load_backend_builtin{   s    &&s'A'ABr"   c                    [        U[        5      (       a  UR                  S5      n[        U;   a  [        R
                  R                  U 5      eU R                  n[        S5      U R                  U4-  R                  S5      n[        SU5      n[        U5       H  nU" U5      nM     [        R                  " X0R                  5      R                  S5      $ )Nzutf-8z
%s$sha1$%sasciisha1)
isinstancer   encode_BNULLr   r7   NullPasswordErrorr   r   r   r	   r   r   encode_transposed_bytes_chk_offsetsdecode)r%   r9   r   result
keyed_hmac_s         r   r4   !sha1_crypt._calc_checksum_builtin   s    fg&&]]7+FV&&**400L/TYY$77??H!&&1
A'F  **63D3DELLWUUr"   )   r   r            r            
   	                     r          N)F)__name__
__module____qualname____firstlineno____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'   backendsr0   r.   r<   r4   rF   __static_attributes__r]   r"   r   r   r      s    J D2LhKEM__N MJ NJJK
 ; ;F 'H
  	  VLr"   r   )rb   logging	getLoggerr^   logpasslib.utilsr   r   passlib.utils.binaryr   passlib.utils.compatr   r   r   passlib.crypto.digestr	   passlib.utils.handlersutilshandlersr   __all__rC   HasManyBackends	HasRoundsHasSaltGenericHandlerr   r]   r"   r   <module>r      sk    g''1 1 $ 3 3 . # #
 
}##R\\2::r?P?P }r"   