
    ҙi                         d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZmZ ddlmZmZmZmZmZ e
d	z   Z G d
 d	      Zy)aQ  SecretStorage item contains a *secret*, some *attributes* and a
*label* visible to user. Editing all these properties and reading the
secret is possible only when the :doc:`collection <collection>` storing
the item is unlocked. The collection can be unlocked using collection's
:meth:`~secretstorage.collection.Collection.unlock` method.    )default_backend)Cipher
algorithmsmodes)DBusConnection)	SS_PREFIX)Session)LockedExceptionPromptDismissedException)DBusAddressWrapperexec_promptformat_secretopen_sessionunlock_objectsItemc            	          e Zd ZdZ	 ddedededz  ddfdZdd	defd
Z	defdZ
ddZddedz  defdZdeeef   fdZdeeef   ddfdZdefdZdeddfdZddZdefdZdefdZ	 d dededdfdZdefdZdefdZdefdZy)!r   zRepresents a secret item.N
connection	item_pathsessionreturnc                     || _         t        |t        |      | _        | j                  j	                  d       || _        || _        y )NLabel)r   r   
ITEM_IFACE_itemget_propertyr   r   )selfr   r   r   s       N/mnt/e/genesis-system/.venv/lib/python3.12/site-packages/secretstorage/item.py__init__zItem.__init__!   s9    "'	:zJ


($    otherr   c                 l    t        |j                  t              sJ | j                  |j                  k(  S N)
isinstancer   str)r   r    s     r   __eq__zItem.__eq__)   s)    %//3///~~00r   c                 J    t        | j                  j                  d            S )zJReturns :const:`True` if item is locked, otherwise
        :const:`False`.Locked)boolr   r   r   s    r   	is_lockedzItem.is_locked-   s     DJJ++H566r   c                 :    | j                         rt        d      y)zYIf collection is locked, raises
        :exc:`~secretstorage.exceptions.LockedException`.zItem is locked!N)r*   r
   r)   s    r   ensure_not_lockedzItem.ensure_not_locked2   s     >>!"344 r   timeoutc                 H    t        | j                  | j                  g|      S )a  Requests unlocking the item. Usually, this means that the
        whole collection containing this item will be unlocked.

        Returns a boolean representing whether the prompt has been
        dismissed; that means :const:`False` on successful unlocking
        and :const:`True` if it has been dismissed.

        :raises: ``TimeoutError`` if `timeout` (in seconds) passed
           and the prompt was neither accepted nor dismissed.

        .. versionadded:: 2.1.2

        .. versionchanged:: 3.0
           No longer accepts the ``callback`` argument.

        .. versionchanged:: 3.5
           Added ``timeout`` argument.
        )r-   )r   r   r   )r   r-   s     r   unlockzItem.unlock8   s    & doo/?QQr   c                 N    | j                   j                  d      }t        |      S )z%Returns item attributes (dictionary).
Attributes)r   r   dict)r   attrss     r   get_attributeszItem.get_attributesM   s     

''5E{r   
attributesc                 >    | j                   j                  dd|       y)z2Sets item attributes to `attributes` (dictionary).r1   za{ss}N)r   set_property)r   r5   s     r   set_attributeszItem.set_attributesR   s    

gzBr   c                 `    | j                   j                  d      }t        |t              sJ |S )z$Returns item label (unicode string).r   )r   r   r#   r$   r   labels     r   	get_labelzItem.get_labelV   s+    

''0%%%%r   r;   c                 ^    | j                          | j                  j                  dd|       y)zSets item label to `label`.r   sN)r,   r   r7   r:   s     r   	set_labelzItem.set_label\   s$     

e4r   c                     | j                          | j                  j                  dd      \  }|dk7  r't        | j                  |      \  }}|rt        d      yy)zDeletes the item.Delete /zPrompt dismissed.N)r,   r   callr   r   r   )r   prompt	dismissed_results       r   deletezItem.deletea   sY     **//(B/S=!,T__f!EIw./BCC  r   c                    | j                          | j                  st        | j                        | _        | j                  j                  dd| j                  j                        \  }| j                  j                  st        |d         S | j                  j                  J t        j                  | j                  j                        }t        |d         }t        |t        j                  |      t                     j!                         }|d   }|j#                  t        |            |j%                         z   }t'        |t              sJ |d|d     S )z!Returns item secret (bytestring).	GetSecreto   N   )r,   r   r   r   r   rD   object_path	encryptedbytesaes_keyr   AESr   r   CBCr   	decryptorupdatefinalizer#   )r   secretaesaes_ivrU   encrypted_secretpadded_secrets          r   
get_secretzItem.get_secretj   s    ||'8DL**//+sDLL4L4LM||%%##||##///nnT\\112vay!3		& 1?3DEOOQ	!!9!((/?)@AIDVDVDXX-///0}R0011r   c                     | j                          | j                  st        | j                        | _        | j                  j                  dd| j                  j                        \  }t        |d         S )z-Returns content type of item secret (string).rJ   rK      )r,   r   r   r   r   rD   rO   r$   )r   rX   s     r   get_secret_content_typezItem.get_secret_content_type{   sU     ||'8DL**//+sDLL4L4LM6!9~r   rX   content_typec                     | j                          | j                  st        | j                        | _        t	        | j                  ||      }| j
                  j                  dd|       y)zSets item secret to `secret`. If `content_type` is given,
        also sets the content type of the secret (``text/plain`` by
        default).	SetSecretz(oayays)N)r,   r   r   r   r   r   rD   )r   rX   ra   _secrets       r   
set_secretzItem.set_secret   sM    
 	 ||'8DLflC

Z9r   c                 `    | j                   j                  d      }t        |t              sJ |S )zxReturns UNIX timestamp (integer) representing the time
        when the item was created.

        .. versionadded:: 1.1Createdr   r   r#   int)r   createds     r   get_createdzItem.get_created   s-    
 **)))4'3'''r   c                 `    | j                   j                  d      }t        |t              sJ |S )z_Returns UNIX timestamp (integer) representing the time
        when the item was last modified.Modifiedrh   )r   modifieds     r   get_modifiedzItem.get_modified   s-     ::**:6(C(((r   c                 D    d| j                         d| j                  dS )Nz<Item z path=>)r<   r   r)   s    r   __repr__zItem.__repr__   s$    (+6$..1C1EEr   r"   )r   N)z
text/plain)__name__
__module____qualname____doc__r   r$   r	   r   r(   r%   r*   r,   floatr/   r2   r4   r8   r<   r?   rH   rQ   r]   r`   re   ri   rk   ro   rr    r   r   r   r      s(   # <@%> %%*1D.%DH%1, 1 174 7
5Redl Rd R*S#X 
Cc3h CD C3 5s 5t 5
D2E 2"  (4	: 	:!$	:8<	:S c F# Fr   N)rv   cryptography.hazmat.backendsr   &cryptography.hazmat.primitives.ciphersr   r   r   jeepney.io.blockingr   secretstorage.definesr   secretstorage.dhcryptor	   secretstorage.exceptionsr
   r   secretstorage.utilr   r   r   r   r   r   r   rx   r   r   <module>r      sE   ? 9 L L . + * N  
AF AFr   