Ë
    àU.j(U  ã                   ór  — d Z ddlZddlZ ej                  e«      ZddlmZmZm	Z	m
Z
 ddlmZ ddlmZmZmZmZ ddlmc mZ ddgZdZd	Zd
ZdZdd„Z ed«      Z ed«      Z ed«      Z G d„ dej>                  ej@                  ejB                  ejD                  «      Z# G d„ de#«      Z$ G d„ de#«      Z%y)z9passlib.handlers.sha2_crypt - SHA256-Crypt / SHA512-Crypté    N)Ú
safe_cryptÚ
test_cryptÚrepeat_stringÚ
to_unicode)Úh64)Úbyte_elem_valueÚuÚuascii_to_strÚunicodeÚsha512_cryptÚsha256_cryptó    ))r   é   ©é   é   ©r   r   )r   é   r   r   ©r   r   )é   r   r   r   )r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   ) é   é
   r   é   r   é   r   é   é   é   é   r   é   r   é   r   é   é   é   é   é   é   é   é   é   é   é   é   é   é	   é   é   )@é*   r   r   r   é+   r   r   r   é,   é-   r    r   r   é.   r!   r#   r   é/   é0   r(   r%   r'   é1   r*   r,   r)   é2   é3   r/   r.   r   é4   r0   é    r   é5   é6   é!   r   r   é7   é"   é#   r   é8   é9   é$   r"   r$   é:   é%   é&   r&   é;   é<   é'   r+   r-   é=   é(   é)   r   é>   é?   c                 óž  — t        | t        «      r| j                  d«      } t        | t        «      sJ ‚t        | v r/t
        j                  j                  |r
t        «      ‚t        «      ‚t        | «      }d|cxk  rdk  sJ d«       ‚ J d«       ‚t        |t        «      sJ d«       ‚|j                  d«      }t        |«      }|dk  sJ d«       ‚|rt        j                  }t        }nt        j                  }t        } || |z   | z   «      j!                  «       } || |z   «      }	|	j"                  }
 |
t%        ||«      «       |}|r |
|d	z  r|n| «       |d	z  }|rŒ|	j!                  «       }|d
k  r$t%         || |z  «      j!                  «       |«      }nE || «      }|j"                  }|d	z
  }|r || «       |d	z  }|rŒt%        |j!                  «       |«      }t        |«      |k(  sJ ‚ ||dt'        |d   «      z   z  «      j!                  «       d| }t        |«      |k(  sJ d«       ‚||z   }||z   }|||||z   ||z   ||z   g}t(        D ��cg c]  \  }}||   ||   f‘Œ }}}|}t+        |d«      \  }}|rB|D ]5  \  }} || |||z   «      j!                  «       z   «      j!                  «       }Œ7 |d	z  }|rŒB|rf|d	z	  }|d| D ]5  \  }} || |||z   «      j!                  «       z   «      j!                  «       }Œ7 |d	z  r ||||   d   z   «      j!                  «       }t-        j.                  ||«      j1                  d«      S c c}}w )aß  perform raw sha256-crypt / sha512-crypt

    this function provides a pure-python implementation of the internals
    for the SHA256-Crypt and SHA512-Crypt algorithms; it doesn't
    handle any of the parsing/validation of the hash strings themselves.

    :arg pwd: password chars/bytes to hash
    :arg salt: salt chars to use
    :arg rounds: linear rounds cost
    :arg use_512: use sha512-crypt instead of sha256-crypt mode

    :returns:
        encoded checksum chars
    zutf-8éè  éÿÉš;zinvalid roundszsalt not unicodeÚasciir&   zsalt too larger   é`   r$   r   Nzsalt_len somehow > hash_len!r1   )Ú
isinstancer   ÚencodeÚbytesÚ_BNULLÚuhÚexcÚNullPasswordErrorr   r   ÚlenÚhashlibÚsha512Ú_512_transpose_mapÚsha256Ú_256_transpose_mapÚdigestÚupdater   r   Ú_c_digest_offsetsÚdivmodr   Úencode_transposed_bytesÚdecode)ÚpwdÚsaltÚroundsÚuse_512Úpwd_lenÚsalt_lenÚ
hash_constÚtranspose_mapÚdbÚa_ctxÚa_ctx_updateÚiÚdaÚdpÚtmp_ctxÚtmp_ctx_updateÚdsÚdp_dpÚdp_dsÚpermsÚevenÚoddÚdataÚdcÚblocksÚtailÚpairss                              ú]C:\xampp\htdocs\tradingbinance\backend\.venv\Lib\site-packages\passlib/handlers/sha2_crypt.pyÚ_raw_sha2_cryptr…   8   s‡  € ôB �#”wÔà�j‰j˜Ó!ˆÜ�cœ5Ô!Ð!Ð!Ü��}Ü�f‰f×&Ñ&±w¤|ÓQÐQÄLÓQÐQÜ�#‹h€Gð �6Ô&˜YÒ&Ð8Ð(8Ó8Ñ&Ð8Ð(8Ó8Ð&ô �dœGÔ$Ð8Ð&8Ó8Ð$Ø�;‰;�wÓ€DÜ�4‹y€HØ�bŠ=Ð*Ð*Ó*ˆ=ñ Ü—^‘^ˆ
Ü*‰ä—^‘^ˆ
Ü*ˆñ
 
�C˜$‘J Ñ$Ó	%×	,Ñ	,Ó	.€Bñ �s˜T‘zÓ"€EØ—<‘<€Lñ ”˜r 7Ó+Ô,ð 	€AÙ
Ù˜1˜qš5‘R cÔ*Ø	ˆa‰ˆò ð
 
�‰‹€Bð �‚|ô ™: c¨G¡mÓ4×;Ñ;Ó=¸wÓG‰ñ ˜S“/ˆØ Ÿ™ˆØ�A‰IˆÙÙ˜3ÔØ�‰FˆAò ô ˜7Ÿ>™>Ó+¨WÓ5ˆÜˆr‹7�gÒÐÐñ
 
�D˜B¤°°A±Ó!7Ñ7Ñ8Ó	9×	@Ñ	@Ó	BÀ9ÀHÐ	M€BÜˆr‹7�hÒÐ>Ð >Ó>Ðð\ ˆr‰E€EØˆr‰E€EØ�˜˜u R™x¨¨B©°°5±Ð9€Eõ 9JÔJÑ8I©9¨4°ˆe�D‰k˜5 ™:Ò&Ð8I€DÑJð 
€BÜ˜& "Ó%�L€FˆDÙ
Û‰IˆD�#Ù˜C¡*¨R°$©YÓ"7×">Ñ">Ó"@Ñ@ÓA×HÑHÓJ‰Bð à�!‰ˆò ñ à�a‘ˆØ˜f˜u›‰IˆD�#Ù˜C¡*¨R°$©YÓ"7×">Ñ">Ó"@Ñ@ÓA×HÑHÓJ‰Bð &ð
 �!Š8Ù˜B  e¡¨Q¡Ñ/Ó0×7Ñ7Ó9ˆBô
 ×&Ñ& r¨=Ó9×@Ñ@ÀÓIÐIùó3 Ks   ÉM	zrounds=Ú$Ú0c                   óÊ   ‡ — e Zd ZdZdZej                  ZdZej                  Z	dZ
dZdZdZdZdZdˆ fd	„	Zd
„ Zd„ Zed„ «       Zd„ ZdZdZed„ «       Zd„ Zed„ «       Zd„ Zˆ xZS )Ú_SHA2_CommonzBclass containing common code shared by sha256_crypt & sha512_crypt)rj   rk   Úimplicit_roundsÚ	salt_sizer$   rR   rS   ÚlinearFNc                 óx   •— t        t        | �
  di |¤Ž |€| j                  xr | j                  dk(  }|| _        y )Néˆ  © )Úsuperr‰   Ú__init__Úuse_defaultsrk   rŠ   )ÚselfrŠ   ÚkwdsÚ	__class__s      €r„   r‘   z_SHA2_Common.__init__  s<   ø€ ÜŒl˜DÑ*Ñ2¨TÒ2àÐ"Ø#×0Ñ0ÒH°T·[±[ÀDÑ5HˆOØ.ˆÕó    c                 ó@   — | j                  || j                  d u ¬«      S ©N)Úrelaxed)Ú
_norm_saltÚchecksum)r“   rj   s     r„   Ú_parse_saltz_SHA2_Common._parse_salt  s   € à�‰˜t¨T¯]©]¸dÐ-BˆÓCÐCr–   c                 ó@   — | j                  || j                  d u ¬«      S r˜   )Ú_norm_roundsr›   )r“   rk   s     r„   Ú_parse_roundsz_SHA2_Common._parse_rounds#  s!   € à× Ñ  °·±À$Ð1FÐ ÓGÐGr–   c                 ó´  — t        |dd«      }| j                  }|j                  |«      st        j                  j                  | «      ‚t        |«      dk(  sJ ‚|dd  j                  t        «      }|d   j                  t        «      rst        t        «      dk(  sJ ‚|j                  d«      dd  }|j                  t        «      r(|t        k7  rt        j                  j                  | «      ‚t        |«      }d}nd}d}t        |«      d	k(  r|\  }}n5t        |«      d
k(  r|d   }d }nt        j                  j                  | «      ‚ | |||xs d |¬«      S )NrT   Úhashr   r   r'   FrŽ   Tr   r   )rk   rj   r›   rŠ   )r   ÚidentÚ
startswithrZ   r[   ÚInvalidHashErrorr]   ÚsplitÚ_UDOLLARÚ_UROUNDSÚpopÚ_UZEROÚZeroPaddedRoundsErrorÚintÚMalformedHashError)Úclsr¡   r¢   Úpartsrk   rŠ   rj   Úchks           r„   Úfrom_stringz_SHA2_Common.from_string'  s?  € ô ˜$ ¨Ó0ˆØ—	‘	ˆØ�‰˜uÔ%Ü—&‘&×)Ñ)¨#Ó.Ð.Ü�5‹z˜QŠÐˆØ�Q�R�—‘œxÓ(ˆð �‰8×ÑœxÔ(Ü”x“= AÒ%Ð%Ð%Ø—Y‘Y˜q“\ ! "Ð%ˆFØ× Ñ ¤Ô(¨V´vÒ-=Ü—f‘f×2Ñ2°3Ó7Ð7Ü˜“[ˆFØ#‰OàˆFØ"ˆOô ˆu‹:˜Š?Ø‰IˆD‘#Ü�‹Z˜1Š_Ø˜‘8ˆDØ‰Cä—&‘&×+Ñ+¨CÓ0Ð0ñ ØØØ’[˜DØ+ô	ð 	r–   c                 ój  — | j                   dk(  rS| j                  rGt        d«      | j                  | j                  | j
                  xs t        d«      fz  }t        |«      S t        d«      | j                  | j                   | j                  | j
                  xs t        d«      fz  }t        |«      S )NrŽ   z%s%s$%sÚ z%srounds=%d$%s$%s)rk   rŠ   r	   r¢   rj   r›   r
   )r“   r¡   s     r„   Ú	to_stringz_SHA2_Common.to_stringT  s˜   € Ø�;‰;˜$Ò 4×#7Ò#7Ü�Y“< 4§:¡:¨t¯y©yØ#'§=¡=Ò#9´A°b³Eð#;ñ ;ˆDô
 ˜TÓ"Ð"ô Ð(Ó)¨T¯Z©Z¸¿¹Ø-1¯Y©Y¸¿¹Ò8NÌÈ2Ëð-Pñ PˆDä˜TÓ"Ð"r–   )Úos_cryptÚbuiltinc                 ó`   — t        | j                  Ž r| j                  | j                  «       yy)NTF)r   Ú
_test_hashÚ_set_calc_checksum_backendÚ_calc_checksum_os_crypt©r­   s    r„   Ú_load_backend_os_cryptz#_SHA2_Common._load_backend_os_crypti  s(   € ä�s—~‘~Ñ&Ø×*Ñ*¨3×+FÑ+FÔGØàr–   c                 ó  — | j                  «       }t        ||«      }|€| j                  |«      S | j                  }|j	                  | j
                  «      r|| dz
     t        k7  r!t        j                  j                  | ||«      ‚|| d  S )Nr   )
r³   r   Ú_calc_checksum_builtinÚchecksum_sizer£   r¢   r¦   rZ   r[   ÚCryptBackendError)r“   ÚsecretÚconfigr¡   Úcss        r„   r¹   z$_SHA2_Common._calc_checksum_os_cryptq  s‡   € Ø—‘Ó!ˆÜ˜& &Ó)ˆØˆ<ð ×.Ñ.¨vÓ6Ð6ð ×ÑˆØ�‰˜tŸz™zÔ*¨d°B°3°q±5©k¼XÒ.EÜ—&‘&×*Ñ*¨4°¸Ó>Ð>Ø�R�C�DˆzÐr–   c                 ó:   — | j                  | j                  «       y)NT)r¸   r½   rº   s    r„   Ú_load_backend_builtinz"_SHA2_Common._load_backend_builtin‚  s   € à×&Ñ& s×'AÑ'AÔBØr–   c                 óZ   — t        || j                  | j                  | j                  «      S ©N)r…   rj   rk   Ú_cdb_use_512)r“   rÀ   s     r„   r½   z#_SHA2_Common._calc_checksum_builtin‡  s&   € Ü˜v t§y¡y°$·+±+Ø#×0Ñ0ó2ð 	2r–   rÆ   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úsetting_kwdsrZ   ÚHASH64_CHARSÚchecksum_charsÚmax_salt_sizeÚ
salt_charsÚ
min_roundsÚ
max_roundsÚrounds_costrÇ   Ú_rounds_prefixrŠ   r‘   rœ   rŸ   Úclassmethodr°   r³   Úbackendsr·   r»   r¹   rÄ   r½   Ú__classcell__)r•   s   @r„   r‰   r‰   ý   s°   ø„ áLð
 F€Là—_‘_€Nð €MØ—‘€Jà€JØ€JØ€Kà€LØ€Nð
 €Oõ/òDòHð ñ*ó ð*òX#ð '€Hð €Jàñó ðòð" ñó ðö2r–   r‰   c                   ó0   — e Zd ZdZd Z ed«      ZdZdZdZ	y)r   aK  This class implements the SHA256-Crypt 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: str
    :param salt:
        Optional salt string.
        If not specified, one will be autogenerated (this is recommended).
        If specified, it must be 0-16 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 535000, must be between 1000 and 999999999, inclusive.

        .. note::
            per the official specification, when the rounds parameter is set to 5000,
            it may be omitted from the hash string.

    :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

    ..
        commented out, currently only supported by :meth:`hash`, and not via :meth:`using`:

        :type implicit_rounds: bool
        :param implicit_rounds:
            this is an internal option which generally doesn't need to be touched.

            this flag determines whether the hash should omit the rounds parameter
            when encoding it to a string; this is only permitted by the spec for rounds=5000,
            and the flag is ignored otherwise. the spec requires the two different
            encodings be preserved as they are, instead of normalizing them.
    z$5$r2   iØ) )Útestz?$5$rounds=1000$test$QmQADEXMG8POI5WDsaeho0P36yK3Tcrgboabng6bkb/N)
rÈ   rÉ   rÊ   rË   Únamer	   r¢   r¾   Údefault_roundsr·   r�   r–   r„   r   r   �  s)   „ ñ*ð\ €DÙˆe‹H€EØ€Mà€Nð
:�Jr–   c                   ó4   — e Zd ZdZd Z ed«      ZdZdZdZ	dZ
y)r   aK  This class implements the SHA512-Crypt 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: str
    :param salt:
        Optional salt string.
        If not specified, one will be autogenerated (this is recommended).
        If specified, it must be 0-16 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 656000, must be between 1000 and 999999999, inclusive.

        .. note::
            per the official specification, when the rounds parameter is set to 5000,
            it may be omitted from the hash string.

    :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

    ..
        commented out, currently only supported by :meth:`hash`, and not via :meth:`using`:

        :type implicit_rounds: bool
        :param implicit_rounds:
            this is an internal option which generally doesn't need to be touched.

            this flag determines whether the hash should omit the rounds parameter
            when encoding it to a string; this is only permitted by the spec for rounds=5000,
            and the flag is ignored otherwise. the spec requires the two different
            encodings be preserved as they are, instead of normalizing them.
    z$6$éV   Ti€
 )rÙ   zj$6$rounds=1000$test$2M/Lx6MtobqjLjobw0Wmo4Q5OFx5nVLJvmgseatA6oMnyWeBdRDx4DU.1H3eGmse6pgsOgDisWBGI5c7TZauS0N)rÈ   rÉ   rÊ   rË   rÚ   r	   r¢   r¾   rÇ   rÛ   r·   r�   r–   r„   r   r   Ñ  s.   „ ñ*ð^ €DÙˆe‹H€EØ€MØ€Là€Nð
(�Jr–   )F)&rË   r^   ÚloggingÚ	getLoggerrÈ   ÚlogÚpasslib.utilsr   r   r   r   Úpasslib.utils.binaryr   Úpasslib.utils.compatr   r	   r
   r   Úpasslib.utils.handlersÚutilsÚhandlersrZ   Ú__all__rY   re   rb   r`   r…   r§   r¦   r©   ÚHasManyBackendsÚ	HasRoundsÚHasSaltÚGenericHandlerr‰   r   r   r�   r–   r„   Ú<module>rì      sÕ   ðÙ ?ó
 Û Ð'�g×'Ñ'¨Ó1�÷4ó 4å $÷8ó 8ç #Ð #ð Øð€ð 
€ðÐ ðÐ ðÐ ó|JñB ˆY‹<€ÙˆS‹6€Ù	
ˆ3‹€ôL2�2×%Ñ% r§|¡|°R·Z±ZØ×$Ñ$ôL2ôd9:�<ô 9:ôD=(�<õ =(r–   