Ë
    òÏjl  ã                   óJ   — d dl Z d dlmZ d dlmZmZ d dlmZ  G d„ de«      Zy)é    N)ÚAny)ÚCipherProtocolÚSerializerProtocol)ÚJsonPlusSerializerc                   ó’   — e Zd ZdZ e«       fdededdfd„Zdede	e
ef   fd„Zd	e	e
ef   defd
„Ze e«       fdededd fd„«       Zy)ÚEncryptedSerializerzHSerializer that encrypts and decrypts data using an encryption protocol.ÚcipherÚserdeÚreturnNc                 ó    — || _         || _        y )N)r	   r
   )Úselfr	   r
   s      úa/var/www/html/gaurav-v2/venv/lib/python3.12/site-packages/langgraph/checkpoint/serde/encrypted.pyÚ__init__zEncryptedSerializer.__init__   s   € ð ˆŒØˆ�
ó    Úobjc                 óŒ   — | j                   j                  |«      \  }}| j                  j                  |«      \  }}|› d|› �|fS )zESerialize an object to a tuple `(type, bytes)` and encrypt the bytes.Ú+)r
   Údumps_typedr	   Úencrypt)r   r   ÚtypÚdataÚ
ciphernameÚ
ciphertexts         r   r   zEncryptedSerializer.dumps_typed   sK   € ð —J‘J×*Ñ*¨3Ó/‰	ˆˆTà!%§¡×!4Ñ!4°TÓ!:Ñˆ
�Jà��a˜
�|Ð$ jÐ0Ð0r   r   c                 óæ   — |\  }}d|vr| j                   j                  |«      S |j                  dd«      \  }}| j                  j	                  ||«      }| j                   j                  ||f«      S )Nr   é   )r
   Úloads_typedÚsplitr	   Údecrypt)r   r   Ú
enc_cipherr   r   r   Údecrypted_datas          r   r   zEncryptedSerializer.loads_typed   so   € Ø!%Ñˆ
�Jà�jÑ Ø—:‘:×)Ñ)¨$Ó/Ð/à$×*Ñ*¨3°Ó2‰ˆˆZàŸ™×,Ñ,¨Z¸ÓDˆà�z‰z×%Ñ% s¨NÐ&;Ó<Ð<r   Úkwargsc                 óŠ  ‡‡‡— 	 ddl mŠ d‰v r‰j                  d«      ŠnJt	        j
                  d«      }|€t        d«      ‚|j                  «       Št        ‰«      dvrt        d	«      ‚‰j                  d
«      €‰j                  ‰d
<    G ˆˆˆfd„dt        «      } |  |«       |«      S # t        $ r t        d«      d‚w xY w)z5Create an `EncryptedSerializer` using AES encryption.r   )ÚAESzQPycryptodome is not installed. Please install it with `pip install pycryptodome`.NÚkeyÚLANGGRAPH_AES_KEYz2LANGGRAPH_AES_KEY environment variable is not set.)é   é   é    z3LANGGRAPH_AES_KEY must be 16, 24, or 32 bytes long.Úmodec                   óL   •— e Zd Zdedeeef   fˆ ˆˆfd„Zdededefˆ ˆˆfd„Zy)úHEncryptedSerializer.from_pycryptodome_aes.<locals>.PycryptodomeAesCipherÚ	plaintextr   c                 óz   •—  ‰j                   ‰fi ‰¤Ž}|j                  |«      \  }}d|j                  |z   |z   fS )NÚaes)ÚnewÚencrypt_and_digestÚnonce)r   r,   r	   r   Útagr#   r$   r!   s        €€€r   r   zPEncryptedSerializer.from_pycryptodome_aes.<locals>.PycryptodomeAesCipher.encryptB   sE   ø€ Ø ˜Ÿ™ Ñ/¨Ñ/�Ø"(×";Ñ";¸IÓ"F‘�
˜CØ˜fŸl™l¨SÑ0°:Ñ=Ð=Ð=r   r   r   c                 ó’   •— |dk(  s
J d|› �«       ‚|d d }|dd }|dd  } ‰j                   ‰fi ‰	¤d|i¤Ž}|j                  ||«      S )Nr.   zUnsupported cipher: r&   r(   r1   )r/   Údecrypt_and_verify)
r   r   r   r1   r2   Úactual_ciphertextr	   r#   r$   r!   s
          €€€r   r   zPEncryptedSerializer.from_pycryptodome_aes.<locals>.PycryptodomeAesCipher.decryptG   so   ø€ Ø! UÒ*ÐOÐ.BÀ:À,Ð,OÓOÐ*Ø" 3 B˜�Ø   BÐ'�Ø$.¨r¨s OÐ!à ˜Ÿ™ Ñ<¨Ñ<°eÒ<�Ø×0Ñ0Ð1BÀCÓHÐHr   N)Ú__name__Ú
__module__Ú__qualname__ÚbytesÚtupleÚstrr   r   )r#   r$   r!   s   €€€r   ÚPycryptodomeAesCipherr+   A   sC   ø„ ð>¨ð >°5¸¸e¸Ñ3D÷ >ð
I¨#ð I¸5ð IÀU÷ Ið Ir   r<   )ÚCrypto.Cipherr#   ÚImportErrorÚpopÚosÚgetenvÚ
ValueErrorÚencodeÚlenÚgetÚMODE_EAXr   )Úclsr
   r!   Úkey_strr<   r#   r$   s     `  @@r   Úfrom_pycryptodome_aesz)EncryptedSerializer.from_pycryptodome_aes&   sÐ   ú€ ð
	Ý)ð �F‰?ØŸ™ EÓ*‰Cä—i‘iÐ 3Ó4ˆGØˆÜ Ð!UÓVÐVØ—.‘.Ó"ˆCÜ�3‹x˜|Ñ+Ü Ð!VÓWÐWð �:‰:�fÓÐ%Ø Ÿ\™\ˆF�6‰N÷	Ið 	I¤Nô 	Iñ Ñ(Ó*¨EÓ2Ð2øôG ò 	ÜØcóàðð	ús   …B, Â,C)r6   r7   r8   Ú__doc__r   r   r   r   r   r:   r;   r9   r   r   ÚclassmethodrI   © r   r   r   r      s–   „ ÙRñ CUÓBVñØ$ðØ-?ðà	óð1˜sð 1 u¨S°%¨ZÑ'8ó 1ð
=  c¨5 jÑ 1ð 
=°có 
=ð á);Ó)=ñ)3Ø&ð)3ØILð)3à	ò)3ó ñ)3r   r   )	r@   Útypingr   Úlanggraph.checkpoint.serde.baser   r   Ú#langgraph.checkpoint.serde.jsonplusr   r   rL   r   r   Ú<module>rP      s    ðÛ 	Ý ç NÝ BôH3Ð,õ H3r   