
    g}'                     l   S r SSKrSSKr\R                  " \5      rSSKJr  SSKJ	r	J
r
  SSKJrJrJr  SSKJs  Jr  / SQr " S S\R(                  R*                  \R,                  5      r\" S	5      rS
r " S S\R(                  R*                  \R4                  5      r " S S\R4                  5      rg)z.passlib.handlers.misc - misc generic handlers
    N)warn)to_native_strstr_consteq)unicodeuunicode_or_bytes_types)unix_disabledunix_fallback	plaintextc                   b   ^  \ rS rSrSrS rSr\S 5       rSU 4S jjr	S r
\SS j5       rSrU =r$ )	r
      aQ  This class provides the fallback behavior for unix shadow files, and follows the :ref:`password-hash-api`.

This class does not implement a hash, but instead provides fallback
behavior as found in /etc/shadow on most unix variants.
If used, should be the last scheme in the context.

* this class will positively identify all hash strings.
* for security, passwords will always hash to ``!``.
* it rejects all passwords if the hash is NOT an empty string (``!`` or ``*`` are frequently used).
* by default it rejects all passwords if the hash is an empty string,
  but if ``enable_wildcard=True`` is passed to verify(),
  all passwords will be allowed through if the hash is an empty string.

.. deprecated:: 1.6
    This has been deprecated due to its "wildcard" feature,
    and will be removed in Passlib 1.8. Use :class:`unix_disabled` instead.
)enable_wildcardc                 n    [        U[        5      (       a  g[        R                  R	                  US5      eNThash
isinstancer   uhexcExpectedStringErrorclsr   s     N/home/matz/Project1/venv/lib/python3.13/site-packages/passlib/handlers/misc.pyidentifyunix_fallback.identify.   *    d233&&,,T6::    c                 Z   > [        S[        5        [        [        U ]  " S0 UD6  Xl        g )Nzf'unix_fallback' is deprecated, and will be removed in Passlib 1.8; please use 'unix_disabled' instead. )r   DeprecationWarningsuperr
   __init__r   )selfr   kwds	__class__s      r   r"   unix_fallback.__init__5   s/     3  	! 	mT+3d3.r   c                 R    U R                   (       a  U R                   $ [        S5      $ )N!)checksumr   )r#   secrets     r   _calc_checksumunix_fallback._calc_checksum=   s    == == S6Mr   c                     [         R                  " U5        [        U[        5      (       d   [         R                  R                  US5      eU(       a  gU$ )Nr   F)r   validate_secretr   r   r   r   )r   r*   r   r   s       r   verifyunix_fallback.verifyE   sA    
6"$ 677&&,,T6::""r   )F)__name__
__module____qualname____firstlineno____doc__namecontext_kwdsclassmethodr   r"   r+   r/   __static_attributes____classcell__r%   s   @r   r
   r
      sD    " D'L; ;/ # #r   r
   z*!s   *!c                   4  ^  \ rS rSrSrS rSrSr\" \	" \
5      5      rS\R                  ;   a	  \" S5      rO\" S5      r\SU 4S jj5       r\S	 5       r\S
 5       r\S 5       r\R,                  " SSS9\SS j5       5       r\SS j5       r\S 5       rSrU =r$ )r	   R   a  This class provides disabled password behavior for unix shadow files,
and follows the :ref:`password-hash-api`.

This class does not implement a hash, but instead matches the "disabled account"
strings found in ``/etc/shadow`` on most Unix variants. "encrypting" a password
will simply return the disabled account marker. It will reject all passwords,
no matter the hash string. The :meth:`~passlib.ifc.PasswordHash.hash`
method supports one optional keyword:

:type marker: str
:param marker:
    Optional marker string which overrides the platform default
    used to indicate a disabled account.

    If not specified, this will default to ``"*"`` on BSD systems,
    and use the Linux default ``"!"`` for all other platforms.
    (:attr:`!unix_disabled.default_marker` will contain the default value)

.. versionadded:: 1.6
    This class was added as a replacement for the now-deprecated
    :class:`unix_fallback` class, which had some undesirable features.
markerr   bsd*r(   c                    > [         [        U ]
  " S0 UD6nUb*  U R                  U5      (       d  [	        SU-  5      eXl        U$ )Nzinvalid marker: %rr   )r!   r	   usingr   
ValueErrordefault_marker)r   r?   r$   subclsr%   s       r   rC   unix_disabled.usingx   sH    }c0848<<'' !5!>??$*!r   c                     [        U[        5      (       a  [        nO<[        U[        5      (       a  [        nO [
        R                  R                  US5      eU(       + =(       d    US   U;   $ )Nr   r   )r   r   _MARKER_CHARSbytes_MARKER_BYTESr   r   r   )r   r   starts      r   r   unix_disabled.identify   sU      dG$$!Ee$$!E&&,,T6::x+47e++r   c                     [         R                  " U5        U R                  U5      (       d  [         R                  R	                  U 5      eg)NF)r   r.   r   r   InvalidHashError)r   r*   r   s      r   r/   unix_disabled.verify   s7    
6"||D!!&&))#..r   c                    U(       a7  [         R                  " X5        U R                  " S0 UD6R                  U5      $ [         R                  " U5        U R
                  nU(       a  U R                  U5      (       d   e[        USS9$ )Nr?   paramr   )r   warn_hash_settings_deprecationrC   r   r.   rE   r   r   )r   r*   r$   r?   s       r   r   unix_disabled.hash   sm    --c899$t$))&11
6"###,,v....V844r   1.72.0
deprecatedremovedc                     U R                  U5      (       d  [        R                  R                  U 5      eU(       a   [        R                  " U5        [        USS9$ Ub  U R                  US9n U R                  U5      $ )NconfigrR   r>   )r   r   r   rO   r.   r   rC   r   )r   r*   r\   r?   s       r   genhashunix_disabled.genhash   sk     ||F##&&))#..v& x88!iivi.88F##r   c                     U R                  S5      nUb<  [        USS9nU R                  U5      (       a  U R                  U5      nU(       a  X!-  nU$ )N r   rR   )r   r   r   enable)r   r   outs      r   disableunix_disabled.disable   sM    hhrl V4D||D!!zz$'
r   c                     [        USS9nU R                   H=  nUR                  U5      (       d  M  U[        U5      S  nU(       a  Us  $ [	        S5      e   [
        R                  R                  U 5      e)Nr   rR   zcannot restore original hash)r   _disable_prefixes
startswithlenrD   r   r   rO   )r   r   prefixorigs       r   ra   unix_disabled.enable   sh    T0++Fv&&CKL)K$%CDD , ff%%c**r   N)r1   r2   r3   r4   r5   r6   setting_kwdsr7   tuplestrrI   rf   sysplatformr   rE   r8   rC   r   r/   r   r   deprecated_methodr]   rc   ra   r9   r:   r;   s   @r   r	   r	   R   s    , DLLc-01 3
 3  , ,.   5 5 UE:
$  ;
$ 	 	 	+ 	+r   r	   c                       \ rS rSrSrS rSrSrSr\	S 5       r
\	SS j5       r\	SS	 j5       r\R                  " S
SS9\	S 5       5       r\R                  " S
SS9\	SS j5       5       rSrg)r      aV  This class stores passwords in plaintext, and follows the :ref:`password-hash-api`.

The :meth:`~passlib.ifc.PasswordHash.hash`, :meth:`~passlib.ifc.PasswordHash.genhash`, and :meth:`~passlib.ifc.PasswordHash.verify` methods all require the
following additional contextual keyword:

:type encoding: str
:param encoding:
    This controls the character encoding to use (defaults to ``utf-8``).

    This encoding will be used to encode :class:`!unicode` passwords
    under Python 2, and decode :class:`!bytes` hashes under Python 3.

.. versionchanged:: 1.6
    The ``encoding`` keyword was added.
r   encodingzutf-8c                 n    [        U[        5      (       a  g[        R                  R	                  US5      er   r   r   s     r   r   plaintext.identify   r   r   Nc                 l    [         R                  " U5        U(       d  U R                  n[        XS5      $ )Nr*   )r   r.   default_encodingr   )r   r*   rv   s      r   r   plaintext.hash   s+    
6"++HVx88r   c                     U(       d  U R                   n[        X#S5      nU R                  U5      (       d  [        R                  R                  U 5      e[        U R                  X5      U5      $ )Nr   )rz   r   r   r   r   rO   r   r   )r   r*   r   rv   s       r   r/   plaintext.verify   sV    ++HTV4||D!!&&))#..388F5t<<r   rV   rW   rX   c                 $    U R                  S5      $ )Nr`   )r   )r   s    r   	genconfigplaintext.genconfig   s     xx|r   c                     U R                  U5      (       d  [        R                  R                  U 5      eU R	                  XS9$ )Nru   )r   r   r   rO   r   )r   r*   r\   rv   s       r   r]   plaintext.genhash  s9     ||F##&&))#..xxx22r   rl   )r1   r2   r3   r4   r5   r6   rm   r7   rz   r8   r   r   r/   r   rr   r   r]   r9   r   r   r   r   r      s    " DL L; ; 9 9 = = UE:  ; UE:3  ;3r   r   )r5   rp   logging	getLoggerr1   logwarningsr   passlib.utilsr   r   passlib.utils.compatr   r   r   passlib.utils.handlersutilshandlersr   __all__ifcDisabledHashStaticHandlerr
   rI   rK   MinimalHandlerr	   r   r   r   r   <module>r      s     g''1  5 C C # #4#BFF'')9)9 4#l $|+BFF''):): |+|93!! 93r   