
     h`0                        d Z ddlmZ ddlZ ej                  e      ZddlmZ ddl	m
Z
mZ ddlmZ ddlmZ  ed      j                   Zddlmc mZ g d	Z G d
 dej.                  ej0                  ej2                        Z G d dej2                        Z ej8                  deddd      Z G d dej<                  ej2                        Z G d dej<                  ej2                        Z y)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                   h    e Zd ZdZd ZdZej                  ZdZ	dZ
dZed        Zd ZdZedd
       Zy	)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                 "    |j                         S Nlowerclshashs     Z/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/passlib/handlers/windows.py
_norm_hashzlmhash._norm_hashU       zz|    c                     | j                   r| j                  |       t        | j                  || j                              j                  d      S Nascii)use_defaults_check_truncate_policyr   rawencodingdecodeselfsecrets     r   _calc_checksumzlmhash._calc_checksumY   s>    ''/txx67>>wGGr   s   KGS!@#$%Nc                 D   |s| j                   }ddlm} | j                  }t	        |t
              r |j                         j                  |      }n,t	        |t              r|j                         }nt        d      t        |d      } ||dd |       ||dd |      z   S )a  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$   z
lmhash.rawc   s     ++H 	9

fg& \\^**84F&
 \\^F=>>!&"- !e4 "u56 	6r   r   )__name__
__module____qualname____doc__namesetting_kwdsuh	HEX_CHARSchecksum_charschecksum_sizetruncate_sizer.   classmethodr   r*   r0   r$    r   r   r
   r
      sf    D D&L
 \\NM
 M
 
  H F#6 #6r   r
   c                   h    e Zd ZdZd Zej                  ZdZe	d        Z
d Ze	d        Ze	dd       Zy)	r   a  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                 "    |j                         S r   r   r   s     r   r   znthash._norm_hash   r   r   c                 T    t        | j                  |            j                  d      S r    )r   r$   r&   r'   s     r   r*   znthash._calc_checksum   s!    txx'(//88r   c                 n    t        |dd      }t        |j                  d            j                         S )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	   r3   digest)r   r)   s     r   r$   z
nthash.raw   s/     FG8<6==-.5577r   c                     t        dt               t        j                  |      }|rt	        |      j                  d      S |S )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_nthashznthash.raw_nthash   s>     ?	! jj /2ws|""7+;;r   N)F)r7   r8   r9   r:   r;   r=   r>   r?   r@   rB   r   r*   r$   rQ   rC   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                   V    e Zd ZdZd Zej                  ZdZe	d        Z
d Ze	d        Zy)r   aK  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                 "    |j                         S r   r   r   s     r   r   zmsdcc._norm_hash  r   r   c                 j    t        | j                  || j                              j                  d      S r    r   r$   userr&   r'   s     r   r*   zmsdcc._calc_checksum
  '    txx		23::7CCr   c                     t        |dd      j                  d      }t        |dd      j                         j                  d      }t        t        |      j	                         |z         j	                         S )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
        rH   r)   rI   rK   rY   )r   r3   r   r	   rL   )r   r)   rY   s      r   r$   z	msdcc.raw  se     FG8<CCKP$v6<<>EEkR3v;%%'$./6688r   Nr7   r8   r9   r:   r;   r=   r>   r?   r@   rB   r   r*   r$   rC   r   r   r   r      sH    ( D\\NM D 
9 
9r   r   c                   V    e Zd ZdZd Zej                  ZdZe	d        Z
d Ze	d        Zy)r   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                 "    |j                         S r   r   r   s     r   r   zmsdcc2._norm_hash3  r   r   c                 j    t        | j                  || j                              j                  d      S r    rX   r'   s     r   r*   zmsdcc2._calc_checksum7  rZ   r   c                    ddl m} t        |dd      j                  d      }t        |dd      j	                         j                  d      }t        t        |      j                         |z         j                         } |d||d	d
      S )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_hmacrH   r)   rI   rK   rY   sha1i (     )passlib.crypto.digestra   r   r3   r   r	   rL   )r   r)   rY   ra   tmps        r   r$   z
msdcc2.raw:  sz     	6FG8<CCKP$v6<<>EEkR#f+$$&-.55763eR88r   Nr\   rC   r   r   r   r     sH    " D\\NM D 9 9r   r   )!r:   binasciir   logging	getLoggerr7   logwarningsr   passlib.utilsr   r   passlib.utils.compatr   rd   r   constr	   passlib.utils.handlersutilshandlersr=   __all__TruncateMixinHasEncodingContextStaticHandlerr
   r   PrefixWrapperr   HasUserContextr   r   rC   r   r   <module>rw      s    A
  'g''1  7 ( -% # #k6Rr44b6F6F k6h-<R -<f RlF6		
T+9Br// +9`-9R 0 0 -9r   