o
    5h}'                     @   s   d Z ddlZddlZeeZddlmZ ddlm	Z	m
Z
 ddlmZmZmZ ddlm  mZ g dZG dd dejjejZed	Zd
ZG dd dejjejZG dd dejZdS )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                       sL   e Zd ZdZd ZdZedd Zd fdd	Zdd	 Z	edd
dZ
  ZS )r	   a  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                 C      t |trdS tj|dNThash
isinstancer   uhexcExpectedStringErrorclsr    r   i/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/passlib/handlers/misc.pyidentify.      
zunix_fallback.identifyFc                    s*   t dt tt| jdi | || _d S )Nzf'unix_fallback' is deprecated, and will be removed in Passlib 1.8; please use 'unix_disabled' instead.r   )r   DeprecationWarningsuperr	   __init__r   )selfr   kwds	__class__r   r   r   5   s
   
zunix_fallback.__init__c                 C   s   | j r| j S tdS )N!)checksumr   )r   secretr   r   r   _calc_checksum=   s   zunix_fallback._calc_checksumc                 C   s.   t | t|tst j|d|rdS |S )Nr   F)r   validate_secretr   r   r   r   )r   r#   r   r   r   r   r   verifyE   s   

zunix_fallback.verify)F)__name__
__module____qualname____doc__namecontext_kwdsclassmethodr   r   r$   r&   __classcell__r   r   r   r   r	      s    
r	   z*!s   *!c                       s   e Zd ZdZd ZdZdZeee	Z
dejv redZnedZed fdd		Zed
d Zedd Zedd ZejdddedddZedddZedd Z  ZS )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!   Nc                    s>   t t| jdi |}|d ur| |std| ||_|S )Nzinvalid marker: %rr   )r   r   usingr   
ValueErrordefault_marker)r   r0   r   subclsr   r   r   r3   x   s   
zunix_disabled.usingc                 C   s@   t |trt}nt |trt}ntj|d| p|d |v S )Nr   r   )r   r   _MARKER_CHARSbytes_MARKER_BYTESr   r   r   )r   r   startr   r   r   r      s   

zunix_disabled.identifyc                 C   s$   t | | |st j| dS )NF)r   r%   r   r   InvalidHashError)r   r#   r   r   r   r   r&      s   

zunix_disabled.verifyc                 K   sT   |rt | | | jdi ||S t | | j}|r"| |s$J t|ddS )Nr0   paramr   )r   warn_hash_settings_deprecationr3   r   r%   r5   r   r   )r   r#   r   r0   r   r   r   r      s   
zunix_disabled.hash1.72.0
deprecatedremovedc                 C   sN   |  |stj| |rt| t|ddS |d ur"| j|d} | |S )Nconfigr<   r/   )r   r   r   r;   r%   r   r3   r   )r   r#   rD   r0   r   r   r   genhash   s   


zunix_disabled.genhashc                 C   sB   |  d}|d urt|dd}| |r| |}|r||7 }|S )N r   r<   )r   r   r   enable)r   r   outr   r   r   disable   s   


zunix_disabled.disablec                 C   sR   t |dd}| jD ]}||r"|t|d  }|r|  S tdq	tj| )Nr   r<   zcannot restore original hash)r   _disable_prefixes
startswithlenr4   r   r   r;   )r   r   prefixorigr   r   r   rG      s   

zunix_disabled.enableN)r'   r(   r)   r*   r+   setting_kwdsr,   tuplestrr7   rJ   sysplatformr   r5   r-   r3   r   r&   r   r   deprecated_methodrE   rI   rG   r.   r   r   r   r   r   R   s0    




	r   c                   @   s~   e Zd ZdZd ZdZdZdZedd Z	eddd	Z
edd
dZejdddedd ZejdddedddZdS )r
   a~  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                 C   r   r   r   r   r   r   r   r      r   zplaintext.identifyNc                 C   s    t | |s
| j}t||dS )Nr#   )r   r%   default_encodingr   )r   r#   rW   r   r   r   r      s   
zplaintext.hashc                 C   s>   |s| j }t||d}| |stj| t| |||S )Nr   )rX   r   r   r   r   r;   r   r   )r   r#   r   rW   r   r   r   r&      s   
zplaintext.verifyr?   r@   rA   c                 C   s
   |  dS )NrF   )r   )r   r   r   r   	genconfig   s   
zplaintext.genconfigc                 C   s$   |  |stj| | j||dS )NrV   )r   r   r   r;   r   )r   r#   rD   rW   r   r   r   rE     s   
zplaintext.genhashrO   )r'   r(   r)   r*   r+   rP   r,   rX   r-   r   r   r&   r   rU   rY   rE   r   r   r   r   r
      s$    
r
   )r*   rS   logging	getLoggerr'   logwarningsr   passlib.utilsr   r   passlib.utils.compatr   r   r   passlib.utils.handlersutilshandlersr   __all__ifcDisabledHashStaticHandlerr	   r7   r9   MinimalHandlerr   r
   r   r   r   r   <module>   s    	6~