
     hBJ                        d Z ddlmZmZ ddlmZ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mZmZmZ ddlmZ ddlmc mZ g d	Z G d
 dej8                  ej:                  ej<                  ej>                        Z dde	fdZ! e!ddd ed            Z" e!ddd      Z# e!ddd      Z$ ejJ                  de"ddd      Z& ejJ                  de#ddd      Z' ejJ                  de$d d!d      Z(d"Z) G d# d$ej8                  ej:                  ej<                  ej>                        Z* G d% d&ej8                  ejV                  ej>                        Z, G d' d(ej:                  ej<                  ej>                        Z- G d) d*ej8                  ej:                  ej<                  ej>                        Z.y)+z,passlib.handlers.pbkdf - PBKDF2 based hashes    )hexlify	unhexlify)	b64encode	b64decodeN)
to_unicode)ab64_decodeab64_encode)str_to_basciiuuascii_to_strunicode)pbkdf2_hmac)pbkdf2_sha1pbkdf2_sha256pbkdf2_sha512cta_pbkdf2_sha1dlitz_pbkdf2_sha1grub_pbkdf2_sha512c                   d    e Zd ZdZdZej                  ZdZdZ	dZ
dZdZdZdZed	        Zd
 Zd Zy)Pbkdf2DigestHandlerz1base class for various pbkdf2_{digest} algorithmssalt	salt_sizerounds      N       linearc                     t        j                  || j                  |       \  }}}t        |j	                  d            }|rt        |j	                  d            } | |||      S )N)handlerasciir   r   checksum)uh	parse_mc3identr   encodeclshashr   r   chks        Y/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/passlib/handlers/pbkdf2.pyfrom_stringzPbkdf2DigestHandler.from_string?   sW    LLsyy#Fc4;;w/0cjj12C&tc::    c                     t        | j                        j                  d      }t        | j                        j                  d      }t	        j
                  | j                  | j                  ||      S Nr"   )r	   r   decoder$   r%   
render_mc3r'   r   selfr   r,   s      r-   	to_stringzPbkdf2DigestHandler.to_stringG   sQ    499%,,W5$--(//8}}TZZdC@@r/   c                 p    t        | j                  || j                  | j                  | j                        S )N)r   _digestr   r   checksum_sizer5   secrets     r-   _calc_checksumz"Pbkdf2DigestHandler._calc_checksumL   s'    4<<DKKI[I[\\r/   )__name__
__module____qualname____doc__setting_kwdsr%   HASH64_CHARSchecksum_charsdefault_salt_sizemax_salt_sizedefault_rounds
min_rounds
max_roundsrounds_costr8   classmethodr.   r6   r<    r/   r-   r   r      s_    ; 3L__N M NJJK G ; ;A
]r/   r   i.  c                     d| z   }|t        d      | fz  }t        }t        ||ft        |||| |||dz  dz   dz  dt        | j	                         |j
                  |      z              S )	z;create new Pbkdf2DigestHandler subclass for a specific hashpbkdf2_z$pbkdf2-%s$         a$  This class implements a generic ``PBKDF2-HMAC-%(digest)s``-based password hash, and follows the :ref:`password-hash-api`.

    It supports a variable-length salt, and a variable number of rounds.

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

    :type salt: bytes
    :param salt:
        Optional salt bytes.
        If specified, the length must be between 0-1024 bytes.
        If not specified, a %(dsc)d byte salt will be autogenerated (this is recommended).

    :type salt_size: int
    :param salt_size:
        Optional number of bytes to use when autogenerating new salts.
        Defaults to %(dsc)d bytes, but can be any value between 0 and 1024.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to %(dr)d, but must be within ``range(1,1<<32)``.

    :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 ``rounds``
        that are too small or too large, and ``salt`` strings that are too long.

        .. versionadded:: 1.6
    )digestdscdr)r>   namer'   r8   rF   r9   encoded_checksum_sizer@   )r   r   typedictupperrD   )	hash_namedigest_sizer   r'   modulerT   bases          r-   create_pbkdf2_hashr]   P   s    y D}- I</Dtgt!*1}Q2> ioo'T-C-C
O?P(  ( (r/   sha1   i z$pbkdf2$)r'   sha256    iHq  sha512@   ia  ldap_pbkdf2_sha1z{PBKDF2}Tldap_pbkdf2_sha256z{PBKDF2-SHA256}z$pbkdf2-sha256$ldap_pbkdf2_sha512z{PBKDF2-SHA512}z$pbkdf2-sha512$s   -_c                   t    e Zd ZdZd ZdZ ed      ZdZdZ	dZ
ej                  ZdZdZd	Zed
        Zd Zd Zy)r   a  This class implements Cryptacular's PBKDF2-based crypt algorithm, and follows the :ref:`password-hash-api`.

    It supports a variable-length salt, and a variable number of rounds.

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

    :type salt: bytes
    :param salt:
        Optional salt bytes.
        If specified, it may be any length.
        If not specified, a one will be autogenerated (this is recommended).

    :type salt_size: int
    :param salt_size:
        Optional number of bytes to use when autogenerating new salts.
        Defaults to 16 bytes, but can be any value between 0 and 1024.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 60000, must be within ``range(1,1<<32)``.

    :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 ``rounds``
        that are too small or too large, and ``salt`` strings that are too long.

        .. versionadded:: 1.6
    r   $p5k2$r_   r   r   r   r   r   c                     t        j                  || j                  d|       \  }}}t        |j	                  d      t
              }|rt        |j	                  d      t
              } | |||      S )Nr   )rounds_baser!   r"   r#   )r%   r&   r'   r   r(   CTA_ALTCHARSr)   s        r-   r.   zcta_pbkdf2_sha1.from_string   s`     LLsyybRUVcW-|<CJJw/>C&tc::r/   c                    t        | j                  t              j                  d      }t        | j                  t              j                  d      }t        j                  | j                  | j                  ||d      S )Nr"   r   rj   )	r   r   rk   r2   r$   r%   r3   r'   r   r4   s      r-   r6   zcta_pbkdf2_sha1.to_string   sW    L188A|4;;GD}}TZZdCRPPr/   c                 H    t        d|| j                  | j                  d      S )Nr^   r_   r   r   r   r:   s     r-   r<   zcta_pbkdf2_sha1._calc_checksum   s    66499dkk2FFr/   N)r=   r>   r?   r@   rT   rA   r   r'   r9   rD   rE   r   rF   rG   rH   rI   rJ   r.   r6   r<   rK   r/   r-   r   r      sk    J D2LhKEM M !//NJJK ; ;QGr/   r   c                       e Zd ZdZd ZdZ ed      Z ed      ZdZ	dZ
ej                  Zej                  ZdZdZd	Zed
        Zd Zd Zd Zy)r   aC  This class implements Dwayne Litzenberger's PBKDF2-based crypt algorithm, and follows the :ref:`password-hash-api`.

    It supports a variable-length salt, and a variable number of rounds.

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

    :type salt: str
    :param salt:
        Optional salt string.
        If specified, it may be any length, but must use the characters in the regexp range ``[./0-9A-Za-z]``.
        If not specified, a 16 character salt will be autogenerated (this is recommended).

    :type salt_size: int
    :param salt_size:
        Optional number of bytes to use when autogenerating new salts.
        Defaults to 16 bytes, but can be any value between 0 and 1024.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 60000, must be within ``range(1,1<<32)``.

    :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 ``rounds``
        that are too small or too large, and ``salt`` strings that are too long.

        .. versionadded:: 1.6
    r   rh   z1000000000000000000000000000000000000000000000000=r   r   r   r   r   c                 h    t        j                  || j                  dd|       \  }}} | |||      S )Nr     )rj   rF   r!   r#   )r%   r&   r'   r)   s        r-   r.   zdlitz_pbkdf2_sha1.from_string9  s6    LLsyyb8;SJc&tc::r/   c                     | j                   }|dk(  rd }t        j                  | j                  || j                  | j
                  d      S Nrr   r   rm   )r   r%   r3   r'   r   r$   r5   r   s     r-   r6   zdlitz_pbkdf2_sha1.to_string?  s;    S=F}}TZZDMMWYZZr/   c                     | j                   }|dk(  rd }t        j                  | j                  || j                  d d      S rt   )r   r%   r3   r'   r   ru   s     r-   _get_configzdlitz_pbkdf2_sha1._get_configE  s6    S=F}}TZZDbQQr/   c                     | j                         }t        d||| j                  d      }t        |      j	                  d      S )Nr^      r"   )rw   r   r   r	   r2   )r5   r;   r   results       r-   r<   z dlitz_pbkdf2_sha1._calc_checksumN  s<    !VVT4;;C6"))'22r/   N)r=   r>   r?   r@   rT   rA   r   r'   _stub_checksumrD   rE   r%   rB   
salt_charsr   rF   rG   rH   rI   rJ   r.   r6   rw   r<   rK   r/   r-   r   r      s~    J D2LhKE~&N MJ
 !//NJJK ; ;
[R3r/   r   c                   P    e Zd ZdZd ZdZ ed      ZdZdxZ	Z
ed        Zd Zd Zy	)
atlassian_pbkdf2_sha1aB  This class implements the PBKDF2 hash used by Atlassian.

    It supports a fixed-length salt, and a fixed number of rounds.

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

    :type salt: bytes
    :param salt:
        Optional salt bytes.
        If specified, the length must be exactly 16 bytes.
        If not specified, a salt will be autogenerated (this is recommended).

    :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
    )r   z	{PKCS5S2}ra   r   c                    t        |dd      }| j                  }|j                  |      st        j                  j                  |       t        |t        |      d  j                  d            }|d d |dd  }} | ||      S )Nr"   r+   r   )r   r$   )	r   r'   
startswithr%   excInvalidHashErrorr   lenr(   )r*   r+   r'   datar   r,   s         r-   r.   z!atlassian_pbkdf2_sha1.from_string{  s|    $0		u%&&))#..c%jk*11':;"ItBCycs++r/   c                     | j                   | j                  z   }| j                  t        |      j	                  d      z   }t        |      S r1   )r   r$   r'   r   r2   r   )r5   r   r+   s      r-   r6   zatlassian_pbkdf2_sha1.to_string  s<    yy4==(zzIdO227;;T""r/   c                 4    t        d|| j                  dd      S )Nr^   i'  ra   )r   r   r:   s     r-   r<   z$atlassian_pbkdf2_sha1._calc_checksum  s     66499eR@@r/   N)r=   r>   r?   r@   rT   rA   r   r'   r9   min_salt_sizerE   rJ   r.   r6   r<   rK   r/   r-   r~   r~   [  sJ    . #DLkNEM %'&MM, ,#
Ar/   r~   c                   t    e Zd ZdZd ZdZ ed      ZdZdZ	dZ
ej                  ZdZdZdZed	        Zd
 Zd Zy)r   a  This class implements Grub's pbkdf2-hmac-sha512 hash, and follows the :ref:`password-hash-api`.

    It supports a variable-length salt, and a variable number of rounds.

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

    :type salt: bytes
    :param salt:
        Optional salt bytes.
        If specified, the length must be between 0-1024 bytes.
        If not specified, a 64 byte salt will be autogenerated (this is recommended).

    :type salt_size: int
    :param salt_size:
        Optional number of bytes to use when autogenerating new salts.
        Defaults to 64 bytes, but can be any value between 0 and 1024.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 19000, but must be within ``range(1,1<<32)``.

    :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 ``rounds``
        that are too small or too large, and ``salt`` strings that are too long.

        .. versionadded:: 1.6
    r   zgrub.pbkdf2.sha512.rc   r   r   r   r   c                     t        j                  || j                  t        d      |       \  }}}t	        |j                  d            }|rt	        |j                  d            } | |||      S )N.)sepr!   r"   r#   )r%   r&   r'   r   r   r(   r)   s        r-   r.   zgrub_pbkdf2_sha512.from_string  s`    LLsyyaf146cW-.CJJw/0C&tc::r/   c           	      8   t        | j                        j                  d      j                         }t        | j                        j                  d      j                         }t        j                  | j                  | j                  ||t        d            S )Nr"   r   )r   )
r   r   r2   rX   r$   r%   r3   r'   r   r   r4   s      r-   r6   zgrub_pbkdf2_sha512.to_string  si    tyy!((1779dmm$++G4::<}}TZZdCQsVLLr/   c                 H    t        d|| j                  | j                  d      S )Nrb   rc   ro   r:   s     r-   r<   z!grub_pbkdf2_sha512._calc_checksum  s     8VTYYRHHr/   N)r=   r>   r?   r@   rT   rA   r   r'   r9   rD   rE   r   rF   rG   rH   rI   rJ   r.   r6   r<   rK   r/   r-   r   r     si    @  D2L#$EM M"11NJJK; ;M
Ir/   r   )/r@   binasciir   r   base64r   r   logging	getLoggerr=   logpasslib.utilsr   passlib.utils.binaryr   r	   passlib.utils.compatr
   r   r   r   passlib.crypto.digestr   passlib.utils.handlersutilshandlersr%   __all__	HasRounds
HasRawSaltHasRawChecksumGenericHandlerr   r]   r   r   r   PrefixWrapperrd   re   rf   rk   r   HasSaltr   r~   r   rK   r/   r-   <module>r      s   2
 ( ' 'g''1 % 9 I I - # #1]",,r7H7H"J[J[ 1]f 7<4PX .f !V1Z=I"8R7"8R7#2##$6ZQ[cgh %R%%&:MK\^ow{| %R%%&:MK\^ow{|  WGbllBMM23D3DbFWFW WG@`3bjj"2C2C `3R3ABMM2+<+<b>O>O 3ApDIr}}b6G6GIZIZ DIr/   