
    Dj                         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dS )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dS )"r   zRepresents a secret item.N
connection	item_pathsessionreturnc                     || _         t          |t          |          | _        | j                            d           || _        || _        d S )NLabel)r   r   
ITEM_IFACE_itemget_propertyr   r   )selfr   r   r   s       M/home/thesage/.hermes/venv/lib/python3.11/site-packages/secretstorage/item.py__init__zItem.__init__!   sD    "'	:zJJ

((($    otherr   c                 Z    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                 P    t          | 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"     DJ++H55666r   c                 L    |                                  rt          d          dS )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/     >> 	5!"3444	5 	5r   timeoutc                 <    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     & do/?QQQQr   c                 T    | j                             d          }t          |          S )z%Returns item attributes (dictionary).
Attributes)r   r   dict)r   attrss     r   get_attributeszItem.get_attributesM   s#    
''55E{{r   
attributesc                 >    | j                             dd|           dS )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BBBBBr   c                 h    | 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   s2    
''00%%%%%%r   r;   c                 f    |                                   | j                            dd|           dS )zSets item label to `label`.r   sN)r,   r   r7   r:   s     r   	set_labelzItem.set_label\   s4       
e44444r   c                     |                                   | j                            dd          \  }|dk    r)t          | j        |          \  }}|rt          d          dS dS )zDeletes the item.Delete /zPrompt dismissed.N)r,   r   callr   r   r   )r   prompt	dismissed_results       r   deletezItem.deletea   su       *//(B//S==!,T_f!E!EIw D./BCCC =D Dr   c                    |                                   | j        st          | 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                                                                }|d         }|                    t          |                    |                                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   s5      | 	9'88DL*//+sDL4LMM|% 	$###|#///nT\122vay!!3	& 1 1?3D3DEEOOQQ	!!9!((/?)@)@AAIDVDVDXDXX-/////0}R00011r   c                     |                                   | j        st          | 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{   s]       | 	9'88DL*//+sDL4LMM6!9~~r   
text/plainrX   content_typec                     |                                   | j        st          | j                  | _        t	          | j        ||          }| j                            dd|           dS )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   rb   _secrets       r   
set_secretzItem.set_secret   sb    
 	   | 	9'88DLflCC
Z99999r   c                 h    | 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   s4    
 *)))44'3'''''r   c                 h    | j                             d          }t          |t                    sJ |S )z_Returns UNIX timestamp (integer) representing the time
        when the item was last modified.Modifiedri   )r   modifieds     r   get_modifiedzItem.get_modified   s4     :**:66(C(((((r   c                 B    d|                                  d| j        dS )Nz<Item z path=>)r<   r   r)   s    r   __repr__zItem.__repr__   s'    E((EE$.EEEEr   r"   )r   N)ra   )__name__
__module____qualname____doc__r   r$   r	   r   r(   r%   r*   r,   floatr/   r2   r4   r8   r<   r?   rH   rQ   r]   r`   rf   rj   rl   rp   rs    r   r   r   r      sK       ## <@% %> %%*1D.%DH% % % %1, 1 1 1 1 174 7 7 7 7
5 5 5 5R Redl Rd R R R R*S#X    
Cc3h CD C C C C3    5s 5t 5 5 5 5
D D D D2E 2 2 2 2"     (4	: 	: 	:!$	:8<	: 	: 	: 	:S    c    F# F F F F F Fr   N)rw   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   ry   r   r   <module>r      s'  ? ? 9 8 8 8 8 8 L L L L L L L L L L . . . . . . + + + + + + * * * * * * N N N N N N N N              
AF AF AF AF AF AF AF AF AF AFr   