o
    Vh                     @   s   d Z ddl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 ddlmZmZmZ dd	l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.    )DictOptional)DBusConnection)	SS_PREFIX)Session)LockedExceptionPromptDismissedException)DBusAddressWrapperexec_promptopen_sessionformat_secretunlock_objects)Cipher
algorithmsmodes)default_backendItemc                	   @   s  e Zd ZdZ	d,dededee 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	#d.d$ed%eddfd&d'Zdefd(d)Zdefd*d+ZdS )/r   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   f/var/www/html/construction_image-detection-poc/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_locked-   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   unlock3   s   zItem.unlockc                 C   s   | j d}t|S )z%Returns item attributes (dictionary).
Attributes)r   r   dict)r   attrsr   r   r   get_attributesB   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_attributesG   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_labelK   s   zItem.get_labelr3   c                 C   s   |    | jdd| dS )zSets item label to `label`.r   sN)r(   r   r/   r2   r   r   r   	set_labelQ   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   deleteV   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   r:   object_path	encryptedbytesaes_keyr   AESr   r   CBCr   	decryptorupdatefinalizer!   )r   secretaesaes_ivrJ   encrypted_secretpadded_secretr   r   r   
get_secret_   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   r:   rD   r"   )r   rM   r   r   r   get_secret_content_typep   s
   zItem.get_secret_content_type
text/plainrM   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   r:   )r   rM   rV   _secretr   r   r   
set_secretx   s
   zItem.set_secretc                 C   r1   )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   r1   )z_Returns UNIX timestamp (integer) representing the time
        when the item was last modified.Modifiedr[   )r   modifiedr   r   r   get_modified   s   zItem.get_modifiedr    )r   N)rU   )__name__
__module____qualname____doc__r   r"   r   r   r   r%   r#   r'   r(   r)   r   r-   r0   r4   r6   r>   rF   rR   rT   rY   r\   r^   ra   r   r   r   r   r      s:    


		
	N)re   typingr   r   jeepney.io.blockingr   secretstorage.definesr   secretstorage.dhcryptor   secretstorage.exceptionsr   r   secretstorage.utilr	   r
   r   r   r   &cryptography.hazmat.primitives.ciphersr   r   r   cryptography.hazmat.backendsr   r   r   r   r   r   r   <module>   s   