
    q	h%                         S SK JrJr  S SKJrJr  SSKJr  SSKJ	r
  SSKJr  SrSrS	r\ " S
 S5      5       r\ " S S5      5       r " S S5      r " S S5      r " S S5      rg)    )	dataclassfield)ListOptional   )	FfiClient)e2ee_pb2)ffi_pb2s   LKFrameEncryptionKey   c                   T    \ rS rSr% Sr\\   \S'   \r	\\S'   \
r\\S'   \r\\S'   Srg)KeyProviderOptions   N
shared_keyratchet_saltratchet_window_sizefailure_tolerance )__name__
__module____qualname____firstlineno__r   r   bytes__annotations__DEFAULT_RATCHET_SALTr   DEFAULT_RATCHET_WINDOW_SIZEr   intDEFAULT_FAILURE_TOLERANCEr   __static_attributes__r       B/var/www/html/env/lib/python3.13/site-packages/livekit/rtc/e2ee.pyr   r      s0    "&J&.L%.::6s6r    r   c                       \ rS rSr% \" \S9r\\S'   \R                  R                  r\R                  R                  \S'   Srg)E2EEOptions#   )default_factorykey_provider_optionsencryption_typer   N)r   r   r   r   r   r   r&   r   
proto_e2eeEncryptionTypeGCMr'   	ValueTyper   r   r    r!   r#   r#   #   s6    /4EW/X,X;E;T;T;X;XOZ..88Xr    r#   c                       \ rS rSrS\S\4S jr\S\4S j5       rS\	S\SS	4S
 jr
S\S\	4S jrS\S\	4S jrS\S\	S\SS	4S jrS\S\S\	4S jrS\S\S\	4S jrSrg	)KeyProvider)   room_handleoptionsc                     X l         Xl        g N)_options_room_handleselfr/   r0   s      r!   __init__KeyProvider.__init__*   s    'r    returnc                     U R                   $ r2   )r3   r6   s    r!   r0   KeyProvider.options.       }}r    key	key_indexNc                 
   [         R                  " 5       nU R                  UR                  l        X#R                  R
                  l        XR                  R
                  l        [        R                  R                  U5        g)zSets the shared encryption key.

Parameters:
    key (bytes): The new shared key.
    key_index (int): The index of the key.

Example:
    ```python
    key_provider.set_shared_key(b"my_shared_key", key_index=1)
    ```
N)	proto_ffi
FfiRequestr4   e2eer/   set_shared_keyr?   r   r   instancerequest)r6   r>   r?   reqs       r!   rD   KeyProvider.set_shared_key2   sX     ""$#00,5)-0*""3'r    c                    [         R                  " 5       nU R                  UR                  l        XR                  R
                  l        [        R                  R                  U5      nUR                  R
                  R                  nU$ )zExports the shared encryption key.

Parameters:
    key_index (int): The index of the key to export.

Returns:
    bytes: The exported shared key.

Example:
    ```python
    key = key_provider.export_shared_key(key_index=1)
    ```
)rA   rB   r4   rC   r/   get_shared_keyr?   r   rE   rF   r>   )r6   r?   rG   respr>   s        r!   export_shared_keyKeyProvider.export_shared_keyD   sd     ""$#00,5)!!))#.ii&&**
r    c                    [         R                  " 5       nU R                  UR                  l        XR                  R
                  l        [        R                  R                  U5      nUR                  R
                  R                  nU$ )a  Ratchets the shared encryption key to a new key.

Parameters:
    key_index (int): The index of the key to ratchet.

Returns:
    bytes: The new ratcheted shared key.

Example:
    ```python
    new_key = key_provider.ratchet_shared_key(key_index=1)
    ```
)rA   rB   r4   rC   r/   ratchet_shared_keyr?   r   rE   rF   new_key)r6   r?   rG   rK   rP   s        r!   rO   KeyProvider.ratchet_shared_keyY   sd     ""$#0009##-!!))#.))..66r    participant_identityc                 J   [         R                  " 5       nU R                  UR                  l        XR                  R
                  l        X4R                  R
                  l        X$R                  R
                  l        X0l        [        R                  R                  U5        g)aE  Sets the encryption key for a specific participant.

Parameters:
    participant_identity (str): The identity of the participant.
    key (bytes): The encryption key to set.
    key_index (int): The index of the key.

Example:
    ```python
    key_provider.set_key("participant123", b"participant_key", key_index=2)
    ```
N)rA   rB   r4   rC   r/   set_keyrR   r?   r>   r   rE   rF   )r6   rR   r>   r?   rG   s        r!   rT   KeyProvider.set_keyp   sm     ""$#000D-%."""""3'r    c                 L   [         R                  " 5       nU R                  UR                  l        XR                  R
                  l        X#R                  R
                  l        [        R                  R                  U5      nUR                  R
                  R                  nU$ )aB  Exports the encryption key for a specific participant.

Parameters:
    participant_identity (str): The identity of the participant.
    key_index (int): The index of the key to export.

Returns:
    bytes: The exported key.

Example:
    ```python
    key = key_provider.export_key("participant123", key_index=2)
    ```
)rA   rB   r4   rC   r/   get_keyrR   r?   r   rE   rF   r>   )r6   rR   r?   rG   rK   r>   s         r!   
export_keyKeyProvider.export_key   st     ""$#000D-%."!!))#.ii##
r    c                 L   [         R                  " 5       nU R                  UR                  l        XR                  R
                  l        X#R                  R
                  l        [        R                  R                  U5      nUR                  R
                  R                  nU$ )a[  Ratchets the encryption key for a specific participant to a new key.

Parameters:
    participant_identity (str): The identity of the participant.
    key_index (int): The index of the key to ratchet.

Returns:
    bytes: The new ratcheted key.

Example:
    ```python
    new_key = key_provider.ratchet_key("participant123", key_index=2)
    ```
)rA   rB   r4   rC   r/   ratchet_keyrR   r?   r   rE   rF   rP   )r6   rR   r?   rG   rK   rP   s         r!   r[   KeyProvider.ratchet_key   st     ""$#004H1)2&!!))#.))''//r    )r3   r4   r?   )r   r   r   r   r   r   r7   propertyr0   r   rD   rL   rO   strrT   rX   r[   r   r   r    r!   r-   r-   )   s    (C (2D ( +  (% (C (D ($3 5 *C E .(C (e ( (PT (,s s u .   r    r-   c                       \ rS rSrS\S\S\S\4S jr\S\4S j5       r	\S\4S	 j5       r
\S\4S
 j5       rS\SS4S jrS\SS4S jrSrg)FrameCryptor   r/   rR   r?   enabledc                 4    Xl         X@l        X l        X0l        g r2   )r4   _enabled_participant_identity
_key_index)r6   r/   rR   r?   rb   s        r!   r7   FrameCryptor.__init__   s    '%9"#r    r9   c                     U R                   $ r2   )re   r;   s    r!   rR   !FrameCryptor.participant_identity   s    )))r    c                     U R                   $ r2   )rf   r;   s    r!   r?   FrameCryptor.key_index   s    r    c                     U R                   $ r2   rd   r;   s    r!   rb   FrameCryptor.enabled   r=   r    Nc                 ,   Xl         [        R                  " 5       nU R                  UR                  l        U R                  UR                  R                  l        XR                  R                  l	        [        R                  R                  U5        g)zEnables or disables frame encryption.

Parameters:
    enabled (bool): True to enable, False to disable.

Example:
    ```python
    frame_cryptor.set_enabled(True)
    ```
N)rd   rA   rB   r4   rC   r/   re   cryptor_set_enabledrR   rb   r   rE   rF   r6   rb   rG   s      r!   set_enabledFrameCryptor.set_enabled   se      ""$#00<@<V<V$$9/6$$,""3'r    c                 ,   Xl         [        R                  " 5       nU R                  UR                  l        U R                  UR                  R                  l        XR                  R                  l	        [        R                  R                  U5        g)zSets the key index for encryption/decryption.

Parameters:
    key_index (int): The new key index.

Example:
    ```python
    frame_cryptor.set_key_index(3)
    ```
N)rf   rA   rB   r4   rC   r/   re   cryptor_set_key_indexrR   r?   r   rE   rF   )r6   r?   rG   s      r!   set_key_indexFrameCryptor.set_key_index   se     $""$#00>B>X>X&&;3<&&0""3'r    )rd   rf   re   r4   )r   r   r   r   r   r^   boolr7   r]   rR   r?   rb   rr   rv   r   r   r    r!   r`   r`      s    $C $s $s $]a $ *c * * 3     (4 (D ($(s (t (r    r`   c                       \ rS rSrS\S\\   4S jr\S\\	   4S j5       r
\S\4S j5       rS\SS	4S
 jrS\\   4S jrSrg	)E2EEManager   r/   r0   c                     X l         Xl        US LU l        Ub&  [        U R                  UR                  5      U l        g g r2   )r0   r4   rd   r-   r&   _key_providerr5   s      r!   r7   E2EEManager.__init__   s?    't+!,T->->@\@\!]D r    r9   c                     U R                   $ r2   )r}   r;   s    r!   key_providerE2EEManager.key_provider   s    !!!r    c                     U R                   $ r2   rm   r;   s    r!   rb   E2EEManager.enabled   r=   r    rb   Nc                     Xl         [        R                  " 5       nU R                  UR                  l        XR                  R                  l        [        R                  R                  U5        g)zEnables or disables end-to-end encryption.

Parameters:
    enabled (bool): True to enable, False to disable.

Example:
    ```python
    e2ee_manager.set_enabled(True)
    ```
N)rd   rA   rB   r4   rC   r/   manager_set_enabledrb   r   rE   rF   rq   s      r!   rr   E2EEManager.set_enabled   sM      ""$#00/6$$,""3'r    c           	         [         R                  " 5       nU R                  UR                  l        [
        R                  R                  U5      n/ nUR                  R                  R                   HH  nUR                  [        U R                  UR                  UR                  UR                  5      5        MJ     U$ )a  Retrieves the list of frame cryptors for participants.

Returns:
    List[FrameCryptor]: A list of FrameCryptor instances.

Example:
    ```python
    cryptors = e2ee_manager.frame_cryptors()
    for cryptor in cryptors:
        print(cryptor.participant_identity)
    ```
)rA   rB   r4   rC   r/   r   rE   rF   manager_get_frame_cryptorsframe_cryptorsappendr`   rR   r?   rb   )r6   rG   rK   r   frame_cryptors        r!   r   E2EEManager.frame_cryptors  s     ""$#00!!))#.!YYAAPPM!!%%!66!++!))	 Q r    )rd   r}   r4   r0   )r   r   r   r   r   r   r#   r7   r]   r-   r   rx   rb   rr   r   r`   r   r   r   r    r!   rz   rz      s|    ^C ^(;2G ^ "h{3 " "   (4 (D ("\ 2 r    rz   N)dataclassesr   r   typingr   r   _ffi_clientr   _protor	   r(   r
   rA   r   r   r   r   r#   r-   r`   rz   r   r    r!   <module>r      s    ) ! " * (.     7 7 7 Y Y Y
J JZ5( 5(p= =r    