
    <i|                     J    S SK r S SKJr  S SKJrJr  S SKJr   " S S\5      rg)    N)Any)CipherProtocolSerializerProtocol)JsonPlusSerializerc                       \ rS rSrSr\" 5       4S\S\SS4S jjrS\	S\
\\4   4S	 jrS
\
\\4   S\	4S jr\\" 5       4S\S\	SS 4S jj5       rSrg)EncryptedSerializer   zHSerializer that encrypts and decrypts data using an encryption protocol.cipherserdereturnNc                     Xl         X l        g )Nr
   r   )selfr
   r   s      t/home/dmtnaga/Documents/work/airagagent/rag_env/lib/python3.13/site-packages/langgraph/checkpoint/serde/encrypted.py__init__EncryptedSerializer.__init__   s     
    objc                     U R                   R                  U5      u  p#U R                  R                  U5      u  pEU SU 3U4$ )zESerialize an object to a tuple `(type, bytes)` and encrypt the bytes.+)r   dumps_typedr
   encrypt)r   r   typdata
ciphername
ciphertexts         r   r   EncryptedSerializer.dumps_typed   sG     JJ**3/	!%!4!4T!:
a
|$j00r   r   c                     Uu  p#SU;  a  U R                   R                  U5      $ UR                  SS5      u  pEU R                  R	                  XS5      nU R                   R                  XF45      $ )Nr      )r   loads_typedsplitr
   decrypt)r   r   
enc_cipherr   r   r   decrypted_datas          r   r    EncryptedSerializer.loads_typed   sg    !%
j ::))$//$**32,,ZDzz%%s&;<<r   kwargsc                   ^^^  SSK Jm  ST;   a  TR                  S5      mON[        R
                  " S5      nUc  [        S5      eUR                  5       m[        T5      S;  a  [        S	5      eTR                  S
5      c  TR                  TS
'    " UUU4S jS[        5      nU " U" 5       U5      $ ! [         a    [        S5      Sef = f)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                   \   > \ rS rSrS\S\\\4   4U UU4S jjrS\S\S\4U UU4S jjrSr	g	)
HEncryptedSerializer.from_pycryptodome_aes.<locals>.PycryptodomeAesCipherA   	plaintextr   c                 x   > TR                   " T40 TD6nUR                  U5      u  p4SUR                  U-   U-   4$ )Naes)newencrypt_and_digestnonce)r   r2   r
   r   tagr(   r)   r&   s        r   r   PEncryptedSerializer.from_pycryptodome_aes.<locals>.PycryptodomeAesCipher.encryptB   sA    //"(";";I"F
fllS0:===r   r   r   c                    > US:X  d
   SU 35       eUS S nUSS nUSS  nTR                   " T40 T	DSU0D6nUR                  XT5      $ )Nr4   zUnsupported cipher: r+   r-   r7   )r5   decrypt_and_verify)
r   r   r   r7   r8   actual_ciphertextr
   r(   r)   r&   s
          r   r"   PEncryptedSerializer.from_pycryptodome_aes.<locals>.PycryptodomeAesCipher.decryptG   sk    !U*O.B:,,OO*"3B B'$.rsO!<<e<001BHHr    N)
__name__
__module____qualname____firstlineno__bytestuplestrr   r"   __static_attributes__)r(   r)   r&   s   r   PycryptodomeAesCipherr0   A   sH    > >5e3D > >
I# I5 IU I Ir   rG   )Crypto.Cipherr(   ImportErrorpoposgetenv
ValueErrorencodelengetMODE_EAXr   )clsr   r&   key_strrG   r(   r)   s     `  @@r   from_pycryptodome_aes)EncryptedSerializer.from_pycryptodome_aes&   s    
	) F?E*Cii 34G !UVV.."C3x|+ !VWW ::f% \\F6N	I 	IN 	I (*E22G  	c	s   B4 4Cr   )r?   r@   rA   rB   __doc__r   r   r   r   r   rD   rE   rC   r   r    classmethodrT   rF   r>   r   r   r   r      s    R CUBV$-?	1s 1uS%Z'8 1
=c5j 1 
=c 
= );)=)3&)3IL)3	)3 )3r   r   )	rK   typingr   langgraph.checkpoint.serde.baser   r   #langgraph.checkpoint.serde.jsonplusr   r   r>   r   r   <module>r[      s     	  N BH3, H3r   