
    g`0                        S r SSKJ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  SSKJr  \" S5      R                   rSSKJs  Jr  / S	Qr " S
 S\R.                  \R0                  \R2                  5      r " S S\R2                  5      r\R8                  " S\SSSS9r " S S\R<                  \R2                  5      r " S S\R<                  \R2                  5      r g)z;passlib.handlers.nthash - Microsoft Windows -related hashes    )hexlifyN)warn)
to_unicoderight_pad_string)unicode)lookup_hashmd4)lmhashnthash
bsd_nthashmsdccmsdcc2c                   r    \ rS rSrSrS rSr\R                  r	Sr
SrSr\S 5       rS rS	r\SS j5       rSrg
)r
      a  This class implements the Lan Manager Password hash, and follows the :ref:`password-hash-api`.

It has no salt and a single fixed round.

The :meth:`~passlib.ifc.PasswordHash.using` method accepts a single
optional keyword:

:param bool truncate_error:
    By default, this will silently truncate passwords larger than 14 bytes.
    Setting ``truncate_error=True`` will cause :meth:`~passlib.ifc.PasswordHash.hash`
    to raise a :exc:`~passlib.exc.PasswordTruncateError` instead.

    .. versionadded:: 1.7

The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.verify` methods accept a single
optional keyword:

:type encoding: str
:param encoding:

    This specifies what character encoding LMHASH should use when
    calculating digest. It defaults to ``cp437``, the most
    common encoding encountered.

Note that while this class outputs digests in lower-case hexadecimal,
it will accept upper-case as well.
)truncate_error       cp437c                 "    UR                  5       $ Nlowerclshashs     Q/home/matz/Project1/venv/lib/python3.13/site-packages/passlib/handlers/windows.py
_norm_hashlmhash._norm_hashU       zz|    c                     U R                   (       a  U R                  U5        [        U R                  XR                  5      5      R                  S5      $ Nascii)use_defaults_check_truncate_policyr   rawencodingdecodeselfsecrets     r   _calc_checksumlmhash._calc_checksumY   s<    ''/txx67>>wGGr    s   KGS!@#$%Nc                 b   U(       d  U R                   nSSKJn  U R                  n[	        U[
        5      (       a   UR                  5       R                  U5      nO1[	        U[        5      (       a  UR                  5       nO[        S5      e[        US5      nU" USS U5      U" USS U5      -   $ )aD  encode password using LANMAN hash algorithm.

:type secret: unicode or utf-8 encoded bytes
:arg secret: secret to hash
:type encoding: str
:arg encoding:
    optional encoding to use for unicode inputs.
    this defaults to ``cp437``, which is the
    common case for most situations.

:returns: returns string of raw bytes
r   )des_encrypt_blockzsecret must be unicode or bytesr      )default_encodingpasslib.crypto.desr/   _magic
isinstancer   upperencodebytes	TypeErrorr   )r   r+   r'   r/   MAGICs        r   r&   
lmhash.rawc   s     ++H 	9

fg&& \\^**84F&&
 \\^F=>>!&"- !e4 "u56 	6r     r   )__name__
__module____qualname____firstlineno____doc__namesetting_kwdsuh	HEX_CHARSchecksum_charschecksum_sizetruncate_sizer1   classmethodr   r,   r3   r&   __static_attributes__r;   r    r   r
   r
      sf    D D&L
 \\NM
 M
 
  H F#6 #6r    r
   c                   r    \ rS rSrSrS r\R                  rSr	\
S 5       rS r\
S 5       r\
S
S j5       rSrg	)r      ap  This class implements the NT Password hash, and follows the :ref:`password-hash-api`.

It has no salt and a single fixed round.

The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.genconfig` methods accept no optional keywords.

Note that while this class outputs lower-case hexadecimal digests,
it will accept upper-case digests as well.
r   c                 "    UR                  5       $ r   r   r   s     r   r   nthash._norm_hash   r   r    c                 T    [        U R                  U5      5      R                  S5      $ r"   )r   r&   r(   r)   s     r   r,   nthash._calc_checksum   s!    txx'(//88r    c                 h    [        USSS9n[        UR                  S5      5      R                  5       $ )zencode password using MD4-based NTHASH algorithm

:arg secret: secret as unicode or utf-8 encoded bytes

:returns: returns string of raw bytes
utf-8r+   param	utf-16-le)r   r	   r6   digest)r   r+   s     r   r&   
nthash.raw   s/     FG8<6==-.5577r    c                     [        S[        5        [        R                  U5      nU(       a  [	        U5      R                  S5      $ U$ )Nzfnthash.raw_nthash() is deprecated, and will be removed in Passlib 1.8, please use nthash.raw() insteadr#   )r   DeprecationWarningr   r&   r   r(   )r   r+   hexrets       r   
raw_nthashnthash.raw_nthash   s>     ?	! jj /2ws|""7+;;r    r;   N)F)r<   r=   r>   r?   r@   rA   rC   rD   rE   rF   rH   r   r,   r&   r[   rI   r;   r    r   r   r      s]     D\\NM
  9 	8 	8 < <r    r   r   z$3$$aZ  The class support FreeBSD's representation of NTHASH
    (which is compatible with the :ref:`modular-crypt-format`),
    and follows the :ref:`password-hash-api`.

    It has no salt and a single fixed round.

    The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.genconfig` methods accept no optional keywords.
    )prefixidentdocc                   ^    \ rS rSrSrS r\R                  rSr	\
S 5       rS r\
S 5       rSrg)	r      a  This class implements Microsoft's Domain Cached Credentials password hash,
and follows the :ref:`password-hash-api`.

It has a fixed number of rounds, and uses the associated
username as the salt.

The :meth:`~passlib.ifc.PasswordHash.hash`, :meth:`~passlib.ifc.PasswordHash.genhash`, and :meth:`~passlib.ifc.PasswordHash.verify` methods
have the following optional keywords:

:type user: str
:param user:
    String containing name of user account this password is associated with.
    This is required to properly calculate the hash.

    This keyword is case-insensitive, and should contain just the username
    (e.g. ``Administrator``, not ``SOMEDOMAIN\Administrator``).

Note that while this class outputs lower-case hexadecimal digests,
it will accept upper-case digests as well.
r   c                 "    UR                  5       $ r   r   r   s     r   r   msdcc._norm_hash  r   r    c                 h    [        U R                  XR                  5      5      R                  S5      $ r"   r   r&   userr(   r)   s     r   r,   msdcc._calc_checksum
  %    txx		23::7CCr    c                     [        USSS9R                  S5      n[        USSS9R                  5       R                  S5      n[        [        U5      R	                  5       U-   5      R	                  5       $ )zencode password using mscash v1 algorithm

:arg secret: secret as unicode or utf-8 encoded bytes
:arg user: username to use as salt

:returns: returns string of raw bytes
rQ   r+   rR   rT   rf   )r   r6   r   r	   rU   )r   r+   rf   s      r   r&   	msdcc.raw  se     FG8<CCKP$v6<<>EEkR3v;%%'$./6688r    r;   Nr<   r=   r>   r?   r@   rA   rC   rD   rE   rF   rH   r   r,   r&   rI   r;   r    r   r   r      sH    ( D\\NM D 
9 
9r    r   c                   ^    \ rS rSrSrS r\R                  rSr	\
S 5       rS r\
S 5       rSrg)	r   i  a  This class implements version 2 of Microsoft's Domain Cached Credentials
password hash, and follows the :ref:`password-hash-api`.

It has a fixed number of rounds, and uses the associated
username as the salt.

The :meth:`~passlib.ifc.PasswordHash.hash`, :meth:`~passlib.ifc.PasswordHash.genhash`, and :meth:`~passlib.ifc.PasswordHash.verify` methods
have the following extra keyword:

:type user: str
:param user:
    String containing name of user account this password is associated with.
    This is required to properly calculate the hash.

    This keyword is case-insensitive, and should contain just the username
    (e.g. ``Administrator``, not ``SOMEDOMAIN\Administrator``).
r   c                 "    UR                  5       $ r   r   r   s     r   r   msdcc2._norm_hash3  r   r    c                 h    [        U R                  XR                  5      5      R                  S5      $ r"   re   r)   s     r   r,   msdcc2._calc_checksum7  rh   r    c                    SSK Jn  [        USSS9R                  S5      n[        USSS9R	                  5       R                  S5      n[        [        U5      R                  5       U-   5      R                  5       nU" SXBS	S
5      $ )zencode password using msdcc v2 algorithm

:type secret: unicode or utf-8 bytes
:arg secret: secret

:type user: str
:arg user: username to use as salt

:returns: returns string of raw bytes
r   )pbkdf2_hmacrQ   r+   rR   rT   rf   sha1i (     )passlib.crypto.digestrr   r   r6   r   r	   rU   )r   r+   rf   rr   tmps        r   r&   
msdcc2.raw:  sx     	6FG8<CCKP$v6<<>EEkR#f+$$&-.55763eR88r    r;   Nrk   r;   r    r   r   r     sH    " D\\NM D 9 9r    r   )!r@   binasciir   logging	getLoggerr<   logwarningsr   passlib.utilsr   r   passlib.utils.compatr   ru   r   constr	   passlib.utils.handlersutilshandlersrC   __all__TruncateMixinHasEncodingContextStaticHandlerr
   r   PrefixWrapperr   HasUserContextr   r   r;   r    r   <module>r      s    A
  g''1  7 ( -% # #k6Rr44b6F6F k6h-<R -<f lF6		
T+9Br// +9`-9R 0 0 -9r    