
    g2                        S r SSKJrJr  SSKJrJrJrJr  SSK	r	\	R                  " \5      rSSK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r  SSKJs  Jr  / S	Qr " S
 S\R<                  5      r " S S\R@                  \RB                  \RD                  5      r# " S S\5      r$ " S S\5      r% " S S\#5      r& " S S\#5      r' " S S\#5      r( " S S\#5      r) " S S\5      r*\ V s/ s H  n SU -   PM
     sn r+S r,\," 5         gs  sn f )z.passlib.handlers.digests - plain hash digests
    )	b64encode	b64decode)md5sha1sha256sha512N)	plaintext)unix_crypt_schemes
to_unicode)uascii_to_strunicodeu)classproperty)ldap_plaintextldap_md5	ldap_sha1ldap_salted_md5ldap_salted_sha1ldap_salted_sha256ldap_salted_sha512ldap_des_cryptldap_bsdi_cryptldap_md5_cryptldap_sha1_cryptldap_bcryptldap_sha256_cryptldap_sha512_cryptc                   R    \ rS rSrSrSrSrSr\R                  r
\S 5       rS rSrg)_Base64DigestHelper)   zhelper for ldap_md5 / ldap_sha1Nc                     U R                   $ )z/tell StaticHandler to strip ident from checksum)identclss    V/home/matz/Project1/venv/lib/python3.13/site-packages/passlib/handlers/ldap_digests.py_hash_prefix _Base64DigestHelper._hash_prefix2   s     yy    c                     [        U[        5      (       a  UR                  S5      nU R                  U5      R	                  5       n[        U5      R                  S5      $ )Nutf-8ascii)
isinstancer   encode
_hash_funcdigestr   decode)selfsecretchks      r%   _calc_checksum"_Base64DigestHelper._calc_checksum7   sI    fg&&]]7+Foof%,,.~$$W--r(    )__name__
__module____qualname____firstlineno____doc__r"   r.   _hash_regexuhPADDED_BASE64_CHARSchecksum_charsr   r&   r4   __static_attributes__r6   r(   r%   r   r   )   s8    ) EJK++N .r(   r   c                   p    \ rS rSrSrSr\R                  rSr	Sr
SrS=rrSrSrSr\S 5       rS rS	 rS
rg)_SaltedBase64DigestHelper=   z-helper for ldap_salted_md5 / ldap_salted_sha1)salt	salt_sizeN      c                    [        USS5      nU R                  R                  U5      nU(       d  [        R                  R                  U 5      e [        UR                  S5      R                  S5      5      nU R                  nU(       d   eU " US U X4S  S9$ ! [         a     [        R                  R                  U 5      ef = f)Nr+   hashtmp)checksumrD   )r   r<   matchr=   excInvalidHashErrorr   groupr-   	TypeErrorMalformedHashErrorchecksum_size)r$   rI   mdatacss        r%   from_string%_SaltedBase64DigestHelper.from_stringN   s    $0OO!!$'&&))#..	1QWWU^227;<D 	rD"IDI66	  	1&&++C00	1s   )B *Cc                     U R                   U R                  -   nU R                  [        U5      R	                  S5      -   n[        U5      $ )Nr+   )rK   rD   r"   r   r0   r   )r1   rT   rI   s      r%   	to_string#_SaltedBase64DigestHelper.to_string\   s<    }}tyy(zzIdO227;;T""r(   c                     [        U[        5      (       a  UR                  S5      nU R                  XR                  -   5      R                  5       $ )Nr*   )r,   r   r-   r.   rD   r/   )r1   r2   s     r%   r4   (_SaltedBase64DigestHelper._calc_checksuma   s<    fg&&]]7+Fv		1299;;r(   r6   )r7   r8   r9   r:   r;   setting_kwdsr=   r>   r?   r"   r.   r<   min_salt_sizemax_salt_sizedefault_salt_sizeclassmethodrV   rY   r4   r@   r6   r(   r%   rB   rB   =   s\    7(L++NEJK$%%MM
 MM7 7#
<r(   rB   c                   `    \ rS rSrSrS r\" S5      r\r	\
R                  " \" S5      5      rSrg)r   i   zThis class stores passwords using LDAP's plain MD5 format, and follows the :ref:`password-hash-api`.

The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.genconfig` methods have no optional keywords.
z{MD5}z%^\{MD5\}(?P<chk>[+/a-zA-Z0-9]{22}==)$r6   N)r7   r8   r9   r:   r;   namer   r"   r   r.   recompiler<   r@   r6   r(   r%   r   r   i   s0     DgJEJ**QGHIKr(   r   c                   `    \ rS rSrSrS r\" S5      r\r	\
R                  " \" S5      5      rSrg)r   s   zThis class stores passwords using LDAP's plain SHA1 format, and follows the :ref:`password-hash-api`.

The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.genconfig` methods have no optional keywords.
z{SHA}z$^\{SHA\}(?P<chk>[+/a-zA-Z0-9]{27}=)$r6   N)r7   r8   r9   r:   r;   rd   r   r"   r   r.   re   rf   r<   r@   r6   r(   r%   r   r   s   s0     DgJEJ**QFGHKr(   r   c                   d    \ rS rSrSrS r\" S5      rSr\	r
\R                  " \" S5      5      rSrg)r   }   ao  This class stores passwords using LDAP's salted MD5 format, and follows the :ref:`password-hash-api`.

It supports a 4-16 byte salt.

The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:

:type salt: bytes
:param salt:
    Optional salt string.
    If not specified, one will be autogenerated (this is recommended).
    If specified, it may be any 4-16 byte string.

:type salt_size: int
:param salt_size:
    Optional number of bytes to use when autogenerating new salts.
    Defaults to 4 bytes for compatibility with the LDAP spec,
    but some systems use larger salts, and Passlib supports
    any value between 4-16.

: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
    ``salt`` strings that are too long.

    .. versionadded:: 1.6

.. versionchanged:: 1.6
    This format now supports variable length salts, instead of a fix 4 bytes.
z{SMD5}rG   z+^\{SMD5\}(?P<tmp>[+/a-zA-Z0-9]{27,}={0,2})$r6   N)r7   r8   r9   r:   r;   rd   r   r"   rR   r   r.   re   rf   r<   r@   r6   r(   r%   r   r   }   s6    @ DhKEMJ**QMNOKr(   r   c                   d    \ rS rSrSrS r\" S5      rSr\	r
\R                  " \" S5      5      rSrg)r      as  
This class stores passwords using LDAP's "Salted SHA1" format,
and follows the :ref:`password-hash-api`.

It supports a 4-16 byte salt.

The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:

:type salt: bytes
:param salt:
    Optional salt string.
    If not specified, one will be autogenerated (this is recommended).
    If specified, it may be any 4-16 byte string.

:type salt_size: int
:param salt_size:
    Optional number of bytes to use when autogenerating new salts.
    Defaults to 4 bytes for compatibility with the LDAP spec,
    but some systems use larger salts, and Passlib supports
    any value between 4-16.

: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
    ``salt`` strings that are too long.

    .. versionadded:: 1.6

.. versionchanged:: 1.6
    This format now supports variable length salts, instead of a fix 4 bytes.
z{SSHA}   z+^\{SSHA\}(?P<tmp>[+/a-zA-Z0-9]{32,}={0,2})$r6   N)r7   r8   r9   r:   r;   rd   r   r"   rR   r   r.   re   rf   r<   r@   r6   r(   r%   r   r      s6    !D DhKEMJ**QMNOKr(   r   c                   h    \ rS rSrSrS r\" S5      rSrSr	\
r\R                  " \" S5      5      rSrg)	r      a  
This class stores passwords using LDAP's "Salted SHA2-256" format,
and follows the :ref:`password-hash-api`.

It supports a 4-16 byte salt.

The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:

:type salt: bytes
:param salt:
    Optional salt string.
    If not specified, one will be autogenerated (this is recommended).
    If specified, it may be any 4-16 byte string.

:type salt_size: int
:param salt_size:
    Optional number of bytes to use when autogenerating new salts.
    Defaults to 8 bytes for compatibility with the LDAP spec,
    but Passlib supports any value between 4-16.

: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
    ``salt`` strings that are too long.

.. versionadded:: 1.7.3
z	{SSHA256}       z.^\{SSHA256\}(?P<tmp>[+/a-zA-Z0-9]{48,}={0,2})$r6   N)r7   r8   r9   r:   r;   rd   r   r"   rR   r`   r   r.   re   rf   r<   r@   r6   r(   r%   r   r      ;    <  DkNEMJ**QPQRKr(   r   c                   h    \ rS rSrSrS r\" S5      rSrSr	\
r\R                  " \" S5      5      rSrg)	r      a  
This class stores passwords using LDAP's "Salted SHA2-512" format,
and follows the :ref:`password-hash-api`.

It supports a 4-16 byte salt.

The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:

:type salt: bytes
:param salt:
    Optional salt string.
    If not specified, one will be autogenerated (this is recommended).
    If specified, it may be any 4-16 byte string.

:type salt_size: int
:param salt_size:
    Optional number of bytes to use when autogenerating new salts.
    Defaults to 8 bytes for compatibility with the LDAP spec,
    but Passlib supports any value between 4-16.

: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
    ``salt`` strings that are too long.

.. versionadded:: 1.7.3
z	{SSHA512}@   rq   z.^\{SSHA512\}(?P<tmp>[+/a-zA-Z0-9]{91,}={0,2})$r6   N)r7   r8   r9   r:   r;   rd   r   r"   rR   r`   r   r.   re   rf   r<   r@   r6   r(   r%   r   r      rr   r(   r   c                       \ rS rSrSrS r\R                  " \" S5      5      r	\
R                  " SSS9\S 5       5       r\S 5       rS	rg
)r   i   a%  This class stores passwords in plaintext, and follows the :ref:`password-hash-api`.

This class acts much like the generic :class:`!passlib.hash.plaintext` handler,
except that it will identify a hash only if it does NOT begin with the ``{XXX}`` identifier prefix
used by RFC2307 passwords.

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.
z^\{\w+\}.*$z1.7z2.0)
deprecatedremovedc                     g)N!r6   r#   s    r%   	genconfigldap_plaintext.genconfig:  s    
 r(   c                     [         R                  " U5      n[        U5      =(       a    U R                  R	                  U5      S L $ )N)r=   to_unicode_for_identifybool	_2307_patrL   )r$   rI   s     r%   identifyldap_plaintext.identifyA  s7     ))$/Dz?cmm11$74??r(   r6   N)r7   r8   r9   r:   r;   rd   re   rf   r   r   r=   deprecated_methodra   r{   r   r@   r6   r(   r%   r   r      s^    , D

1^,-IUE:  ;
 @ @r(   r   ldap_c                      [        5       n [         H)  nSU-   n[        R                  " X![	        S5      SS9X'   M+     A g )Nr   z{CRYPT}T)prefixlazy)globalsr
   r=   PrefixWrapperr   )gwnamerd   s      r%   _init_ldap_crypt_handlersr   N  s=     		A#""4q|$O $ 	
r(   )-r;   base64r   r   hashlibr   r   r   r   logging	getLoggerr7   logre   passlib.handlers.miscr	   passlib.utilsr
   r   passlib.utils.compatr   r   r   passlib.utils.decorr   passlib.utils.handlersutilshandlersr=   __all__StaticHandlerr   
HasRawSaltHasRawChecksumGenericHandlerrB   r   r   r   r   r   r   r   ldap_crypt_schemesr   )rd   s   0r%   <module>r      s   ( - - g''1 	 , 8 : : - # #,."** .('<r/@/@"BSBS '<XJ" JI# I%P/ %PN(P0 (PX%S2 %SP%S2 %SP%@Y %@X 3EF2D$w~2DF 
   Gs   -D
