o
    i                     @   s   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G d
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                	   @   s$  e Zd ZdZ	d.dedededB ddfddZd	d
defddZ	defddZ
d/ddZdefddZdeeef fddZdeeef ddfddZdefddZdeddfddZd/ddZdefdd Zdefd!d"Z	#d0d$ed%eddfd&d'Zdefd(d)Zdefd*d+Zdefd,d-ZdS )1r   zRepresents a secret item.N
connection	item_pathsessionreturnc                 C   s0   || _ t|t|| _| jd || _|| _d S )NLabel)r   r   
ITEM_IFACE_itemget_propertyr   r   )selfr   r   r    r   X/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/secretstorage/item.py__init__!   s
   
zItem.__init__otherr   c                 C   s   t |jtsJ | j|jkS N)
isinstancer   str)r   r   r   r   r   __eq__)   s   zItem.__eq__c                 C   s   t | jdS )zJReturns :const:`True` if item is locked, otherwise
        :const:`False`.Locked)boolr   r   r   r   r   r   	is_locked-   s   zItem.is_lockedc                 C   s   |   rtddS )zYIf collection is locked, raises
        :exc:`~secretstorage.exceptions.LockedException`.zItem is locked!N)r%   r	   r$   r   r   r   ensure_not_locked2   s   zItem.ensure_not_lockedc                 C   s   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.

        .. versionadded:: 2.1.2

        .. versionchanged:: 3.0
           No longer accepts the ``callback`` argument.
        )r   r   r   r$   r   r   r   unlock8   s   zItem.unlockc                 C   s   | j d}t|S )z%Returns item attributes (dictionary).
Attributes)r   r   dict)r   attrsr   r   r   get_attributesG   s   zItem.get_attributes
attributesc                 C   s   | j dd| dS )z2Sets item attributes to `attributes` (dictionary).r(   za{ss}N)r   set_property)r   r,   r   r   r   set_attributesL   s   zItem.set_attributesc                 C      | j d}t|tsJ |S )z$Returns item label (unicode string).r   )r   r   r   r    r   labelr   r   r   	get_labelP   s   zItem.get_labelr1   c                 C   s   |    | jdd| dS )zSets item label to `label`.r   sN)r&   r   r-   r0   r   r   r   	set_labelV   s   zItem.set_labelc                 C   sD   |    | 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_resultr   r   r   delete[   s   zItem.deletec                 C   s   |    | jst| j| _| jdd| jj\}| jjs"t|d S | jj	dus*J t
| jj	}t|d }t|t|t  }|d }|t||  }t|tsYJ |d|d   S )z!Returns item secret (bytestring).	GetSecreto   N   )r&   r   r   r   r   r8   object_path	encryptedbytesaes_keyr   AESr   r   CBCr   	decryptorupdatefinalizer   )r   secretaesaes_ivrH   encrypted_secretpadded_secretr   r   r   
get_secretd   s   zItem.get_secretc                 C   s<   |    | jst| j| _| jdd| jj\}t|d S )z-Returns content type of item secret (string).r=   r>      )r&   r   r   r   r   r8   rB   r    )r   rK   r   r   r   get_secret_content_typeu   s
   zItem.get_secret_content_type
text/plainrK   content_typec                 C   s<   |    | 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   r8   )r   rK   rT   _secretr   r   r   
set_secret}   s
   zItem.set_secretc                 C   r/   )zxReturns UNIX timestamp (integer) representing the time
        when the item was created.

        .. versionadded:: 1.1Createdr   r   r   int)r   createdr   r   r   get_created   s   zItem.get_createdc                 C   r/   )z_Returns UNIX timestamp (integer) representing the time
        when the item was last modified.ModifiedrY   )r   modifiedr   r   r   get_modified   s   zItem.get_modifiedc                 C   s   d|   d| jdS )Nz<Item z path=>)r2   r   r$   r   r   r   __repr__   s   zItem.__repr__r   )r   N)rS   )__name__
__module____qualname____doc__r   r    r   r   r#   r!   r%   r&   r'   r)   r+   r.   r2   r4   r<   rD   rP   rR   rW   rZ   r\   r_   ra   r   r   r   r   r      s<    


		
	N)re   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   r   r   r   r   <module>   s   