§
    HŠtj(U  ã                   ól  — 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j!        ej"        ¦  «        Z# G d„ de#¦  «        Z$ G d„ de#¦  «        Z%dS )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   é>   é?   Fc                 ó¢  ‡— t          | t          ¦  «        r|                      d¦  «        } t          | t          ¦  «        sJ ‚t          | v r-t
          j                             |rt          nt          ¦  «        ‚t          | ¦  «        }d|cxk    rdk    sn J d¦   «         ‚t          |t          ¦  «        s
J d¦   «         ‚|                     d¦  «        }t          |¦  «        }|dk     s
J d¦   «         ‚|rt          j        }t          }nt          j        }t          } || |z   | z   ¦  «                             ¦   «         } || |z   ¦  «        }	|	j        }
 |
t%          ||¦  «        ¦  «         |}|r |
|d	z  r|n| ¦  «         |d	z  }|°|	                     ¦   «         }|d
k     r/t%           || |z  ¦  «                             ¦   «         |¦  «        }nM || ¦  «        }|j        }|d	z
  }|r || ¦  «         |d	z  }|°t%          |                     ¦   «         |¦  «        }t          |¦  «        |k    sJ ‚ ||dt'          |d         ¦  «        z   z  ¦  «                             ¦   «         d|…         }t          |¦  «        |k    s
J d¦   «         ‚||z   }||z   }|||||z   ||z   ||z   gŠˆfd„t(          D ¦   «         }|}t+          |d¦  «        \  }}|rM|D ]C\  }} || |||z   ¦  «                             ¦   «         z   ¦  «                             ¦   «         }ŒD|d	z  }|°M|r„|d	z	  }|d|…         D ]C\  }} || |||z   ¦  «                             ¦   «         z   ¦  «                             ¦   «         }ŒD|d	z  r, ||||         d         z   ¦  «                             ¦   «         }t-          j        ||¦  «                             d¦  «        S )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!c                 ó6   •— g | ]\  }}‰|         ‰|         f‘ŒS © rW   )Ú.0ÚevenÚoddÚpermss      €úY/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/passlib/handlers/sha2_crypt.pyú
<listcomp>z#_raw_sha2_crypt.<locals>.<listcomp>Û   s*   ø€ ÐJÐJÐJ©9¨4°ˆe�DŒk˜5 œ:Ð&ÐJÐJÐJó    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ÚdataÚdcÚblocksÚtailrY   rZ   Úpairsr[   s                             @r\   Ú_raw_sha2_cryptrŠ   8   sn  ø€ õB �#•wÑÔð "à�jŠj˜Ñ!Ô!ˆÝ�c�5Ñ!Ô!Ð!Ð!Ð!Ý�€}€}ÝŒf×&Ò&°wÐ'P¥| |ÅLÑQÔQÐQÝ�#‰hŒh€Gð �6Ð&Ð&Ò&Ð&˜YÒ&Ð&Ð&Ð&Ð&Ð(8Ñ&Ô&Ð&õ �d�GÑ$Ô$Ð8Ð8Ð&8Ñ8Ô8Ð$Ø�;Š;�wÑÔ€DÝ�4‰yŒy€HØ�bŠ=ˆ=ˆ=Ð*‰=Œ=ˆ=ð ð +Ý”^ˆ
Ý*ˆˆå”^ˆ
Ý*ˆð
 
ˆ�C˜$‘J Ñ$Ñ	%Ô	%×	,Ò	,Ñ	.Ô	.€Bð ˆJ�s˜T‘zÑ"Ô"€EØ”<€Lð €L•˜r 7Ñ+Ô+Ñ,Ô,Ð,ð 	€AØ
ð Øˆ˜1˜q™5Ð)�R�R cÑ*Ô*Ð*Ø	ˆa‰ˆð ð ð
 
�Š‰Œ€Bð �‚|€|õ ˜:˜: c¨G¡mÑ4Ô4×;Ò;Ñ=Ô=¸wÑGÔGˆˆð �*˜S‘/”/ˆØ œˆØ�A‰IˆØð 	ØˆN˜3ÑÔÐØ�‰FˆAð ð 	õ ˜7Ÿ>š>Ñ+Ô+¨WÑ5Ô5ˆÝˆr‰7Œ7�gÒÐÐÐð
 
ˆ�D˜B¥°°A´Ñ!7Ô!7Ñ7Ñ8Ñ	9Ô	9×	@Ò	@Ñ	BÔ	BÀ9ÀHÀ9Ô	M€BÝˆr‰7Œ7�hÒÐÐÐ >ÑÔÐð\ ˆr‰E€EØˆr‰E€EØ�˜˜u R™x¨¨B©°°5±Ð9€Eð KÐJÐJÐJÕ8IÐJÑJÔJ€Dð 
€BÝ˜& "Ñ%Ô%�L€FˆDØ
ð Øð 	Kð 	K‰IˆD�#Ø�˜C * *¨R°$©YÑ"7Ô"7×">Ò">Ñ"@Ô"@Ñ@ÑAÔA×HÒHÑJÔJˆBˆBØ�!‰ˆð ð ð ð 	:à�a‘ˆØ˜f˜u˜fœð 	Kð 	K‰IˆD�#Ø�˜C * *¨R°$©YÑ"7Ô"7×">Ò">Ñ"@Ô"@Ñ@ÑAÔA×HÒHÑJÔJˆBˆBð �!‰8ð 	:Ø�˜B  e¤¨Q¤Ñ/Ñ0Ô0×7Ò7Ñ9Ô9ˆBõ
 Ô& r¨=Ñ9Ô9×@Ò@ÀÑIÔIÐIr^   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)rs   rt   Úimplicit_roundsÚ	salt_sizer$   rR   rS   ÚlinearFNc                 ó~   •—  t          t          | ¦  «        j        di |¤Ž |€| j        o
| j        dk    }|| _        d S )Néˆ  rW   )ÚsuperrŽ   Ú__init__Úuse_defaultsrt   r�   )Úselfr�   ÚkwdsÚ	__class__s      €r\   r•   z_SHA2_Common.__init__  sN   ø€ Ø*��l˜DÑ!Ô!Ô*Ð2Ð2¨TÐ2Ð2Ð2àÐ"Ø#Ô0ÐH°T´[ÀDÒ5HˆOØ.ˆÔÐÐr^   c                 ó>   — |                       || j        d u ¬¦  «        S ©N)Úrelaxed)Ú
_norm_saltÚchecksum)r—   rs   s     r\   Ú_parse_saltz_SHA2_Common._parse_salt  s   € à�Š˜t¨T¬]¸dÐ-BˆÑCÔCÐCr^   c                 ó>   — |                       || j        d u ¬¦  «        S r›   )Ú_norm_roundsrž   )r—   rt   s     r\   Ú_parse_roundsz_SHA2_Common._parse_rounds#  s"   € à× Ò  °´À$Ð1FÐ ÑGÔGÐGr^   c                 ó8  — t          |dd¦  «        }| j        }|                     |¦  «        st          j                             | ¦  «        ‚t          |¦  «        dk    sJ ‚|dd …                              t          ¦  «        }|d                              t          ¦  «        r�t          t          ¦  «        dk    sJ ‚| 
                    d¦  «        dd …         }|                     t          ¦  «        r*|t          k    rt          j                             | ¦  «        ‚t          |¦  «        }d}nd}d}t          |¦  «        d	k    r|\  }}n=t          |¦  «        d
k    r|d         }d }nt          j                             | ¦  «        ‚ | |||pd |¬¦  «        S )NrT   Úhashr   r   r'   Fr“   Tr   r   )rt   rs   rž   r�   )r   ÚidentÚ
startswithrc   rd   ÚInvalidHashErrorrf   ÚsplitÚ_UDOLLARÚ_UROUNDSÚpopÚ_UZEROÚZeroPaddedRoundsErrorÚintÚMalformedHashError)Úclsr¤   r¥   Úpartsrt   r�   rs   Úchks           r\   Úfrom_stringz_SHA2_Common.from_string'  s‹  € õ ˜$ ¨Ñ0Ô0ˆØ”	ˆØ�Š˜uÑ%Ô%ð 	/Ý”&×)Ò)¨#Ñ.Ô.Ð.Ý�5‰zŒz˜QŠˆˆˆØ�Q�R�R”—’�xÑ(Ô(ˆð �Œ8×Ò�xÑ(Ô(ð 		#Ý•x‘=”= AÒ%Ð%Ð%Ð%Ø—Y’Y˜q‘\”\ ! " "Ô%ˆFØ× Ò ¥Ñ(Ô(ð 8¨VµvÒ-=Ð-=Ý”f×2Ò2°3Ñ7Ô7Ð7Ý˜‘[”[ˆFØ#ˆOˆOàˆFØ"ˆOõ ˆu‰:Œ:˜Š?ˆ?Ø‰IˆD�#�#Ý�‰ZŒZ˜1Š_ˆ_Ø˜”8ˆDØˆCˆCå”&×+Ò+¨CÑ0Ô0Ð0ð ˆsØØØ�[˜DØ+ð	ñ ô ð 	r^   c                 ó  — | j         dk    r;| j        r4t          d¦  «        | j        | j        | j        pt          d¦  «        fz  }n9t          d¦  «        | j        | j         | j        | j        pt          d¦  «        fz  }t          |¦  «        S )Nr“   z%s%s$%sÚ z%srounds=%d$%s$%s)rt   r�   r	   r¥   rs   rž   r
   )r—   r¤   s     r\   Ú	to_stringz_SHA2_Common.to_stringT  sŒ   € ØŒ;˜$ÒÐ 4Ô#7ÐÝ�Y‘<”< 4¤:¨t¬yØ#'¤=Ð#9µA°b±E´Eð#;ñ ;ˆDˆDõ Ð(Ñ)Ô)¨T¬Z¸¼Ø-1¬Y¸¼Ð8NÍÈ2ÉÌð-Pñ PˆDå˜TÑ"Ô"Ð"r^   )Úos_cryptÚbuiltinc                 óZ   — t          | j        Ž r|                      | j        ¦  «         dS dS )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  s2   € å�s”~Ð&ð 	Ø×*Ò*¨3Ô+FÑGÔGÐGØ�4à�5r^   c                 ó<  — |                       ¦   «         }t          ||¦  «        }|€|                      |¦  «        S | j        }|                     | j        ¦  «        r|| dz
           t          k    r!t          j         	                    | ||¦  «        ‚|| d …         S )Nr   )
r¶   r   Ú_calc_checksum_builtinÚchecksum_sizer¦   r¥   r©   rc   rd   ÚCryptBackendError)r—   ÚsecretÚconfigr¤   Úcss        r\   r¼   z$_SHA2_Common._calc_checksum_os_cryptq  s™   € Ø—’Ñ!Ô!ˆÝ˜& &Ñ)Ô)ˆØˆ<ð ×.Ò.¨vÑ6Ô6Ð6ð ÔˆØ�Š˜tœzÑ*Ô*ð 	?¨d°B°3°q±5¬k½XÒ.EÐ.EÝ”&×*Ò*¨4°¸Ñ>Ô>Ð>Ø�R�C�D�DŒzÐr^   c                 ó:   — |                       | j        ¦  «         dS )NT)r»   rÀ   r½   s    r\   Ú_load_backend_builtinz"_SHA2_Common._load_backend_builtin‚  s   € à×&Ò& sÔ'AÑBÔBÐBØˆtr^   c                 óD   — t          || j        | j        | j        ¦  «        S ©N)rŠ   rs   rt   Ú_cdb_use_512)r—   rÃ   s     r\   rÀ   z#_SHA2_Common._calc_checksum_builtin‡  s$   € Ý˜v t¤y°$´+Ø#Ô0ñ2ô 2ð 	2r^   rÉ   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úsetting_kwdsrc   Ú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ÐLð
 F€Là”_€Nð €MØ”€Jà€JØ€JØ€Kà€LØ€Nð
 €Oð/ð /ð /ð /ð /ð /ðDð Dð DðHð Hð Hð ð*ð *ñ „[ð*ðX#ð #ð #ð '€Hð €Jàðð ñ „[ððð ð ð" ðð ñ „[ðð2ð 2ð 2ð 2ð 2ð 2ð 2r^   rŽ   c                   ó8   — e Zd ZdZd Z ed¦  «        ZdZdZdZ	dS )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º   rW   r^   r\   r   r   �  s>   € € € € € ð*ð *ð\ €DØˆAˆe‰HŒH€EØ€Mà€Nð
:€J€J€Jr^   c                   ó<   — e Zd ZdZd Z ed¦  «        ZdZdZdZ	dZ
dS )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º   rW   r^   r\   r   r   Ñ  sC   € € € € € ð*ð *ð^ €DØˆAˆe‰HŒH€EØ€MØ€Là€Nð
(€J€J€Jr^   )F)&rÎ   rg   ÚloggingÚ	getLoggerrË   ÚlogÚpasslib.utilsr   r   r   r   Úpasslib.utils.binaryr   Úpasslib.utils.compatr   r	   r
   r   Úpasslib.utils.handlersÚutilsÚhandlersrc   Ú__all__rb   rn   rk   ri   rŠ   rª   r©   r¬   ÚHasManyBackendsÚ	HasRoundsÚHasSaltÚGenericHandlerrŽ   r   r   rW   r^   r\   ú<module>rï      sí  ðØ ?Ð ?ð
 €€€Ø €€€Ð'�gÔ'¨Ñ1Ô1�ð4ð 4ð 4ð 4ð 4ð 4ð 4ð 4ð 4ð 4ð 4ð 4à $Ð $Ð $Ð $Ð $Ð $ð8ð 8ð 8ð 8ð 8ð 8ð 8ð 8ð 8ð 8ð 8ð 8à #Ð #Ð #Ð #Ð #Ð #Ð #Ð #Ð #ð Øð€ð 
€ðÐ ðÐ ðÐ ð|Jð |Jð |Jð |JðB ˆ1ˆY‰<Œ<€Øˆ1ˆS‰6Œ6€Ø	
ˆˆ3‰Œ€ðL2ð L2ð L2ð L2ð L2�2Ô% r¤|°R´ZØÔ$ñL2ô L2ð L2ðd9:ð 9:ð 9:ð 9:ð 9:�<ñ 9:ô 9:ð 9:ðD=(ð =(ð =(ð =(ð =(�<ñ =(ô =(ð =(ð =(ð =(r^   