
    Hdy                         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   Z G d d
e          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            	          e Zd ZdZ	 ddededee         ddfdZdd	de	fd
Z
de	fdZd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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       2lib/python3.11/site-packages/secretstorage/item.py__init__zItem.__init__   sD    $.!)ZDD$**'"""$,$///    otherr   c                 Z    t          |j        t                    sJ | j        |j        k    S N)
isinstancer   str)r   r"   s     r   __eq__zItem.__eq__#   s)    	EOS	)	))))	5?	**r!   c                 P    t          | j                            d                    S )zDReturns :const:`True` if item is locked, otherwise
		:const:`False`.Locked)boolr   r   r   s    r   	is_lockedzItem.is_locked'   s"     
dj%%h//	0	00r!   c                 L    |                                  rt          d          dS )zSIf collection is locked, raises
		:exc:`~secretstorage.exceptions.LockedException`.zItem is locked!N)r,   r   r+   s    r   ensure_not_lockedzItem.ensure_not_locked,   s/     
^^ ,	*	+	++, ,r!   c                 8    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+   s    r   unlockzItem.unlock2   s     
$.)9	:	::r!   c                 T    | j                             d          }t          |          S )z%Returns item attributes (dictionary).
Attributes)r   r   dict)r   attrss     r   get_attributeszItem.get_attributesA   s#    
*
!
!,
/
/%	er!   
attributesc                 >    | j                             dd|           dS )z2Sets item attributes to `attributes` (dictionary).r2   za{ss}N)r   set_property)r   r6   s     r   set_attributeszItem.set_attributesF   s"    *,<<<<<r!   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_labelJ   s2    
*
!
!'
*
*%	E3			,r!   r<   c                 f    |                                   | j                            dd|           dS )zSets item label to `label`.r   sN)r.   r   r8   r;   s     r   	set_labelzItem.set_labelP   s4    *'3.....r!   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.deleteU   sx    JOOHb))'&s] 8#DOV<<9g 8
"#6
7
778 88 8r!   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   rE   object_path	encryptedbytesaes_keyr   AESr   r   CBCr   	decryptorupdatefinalizer%   )r   secretaesaes_ivrV   encrypted_secretpadded_secrets          r   
get_secretzItem.get_secret^   s5   	 0t//4<JOOKdl.FGG'&		 
q	

		)))t|+,,#&S%)F++_->->??IIKK)AY""5)9#:#:;;i>P>P>R>RR-	M5	)	))))	*r***	++r!   c                     |                                   | j        st          | j                  | _        | j                            dd| j        j                  \  }t          |d                   S )z-Returns content type of item secret (string).rK   rL      )r.   r   r   r   r   rE   rP   r&   )r   rY   s     r   get_secret_content_typezItem.get_secret_content_typeo   s]    	 0t//4<JOOKdl.FGG'&	VAYr!   
text/plainrY   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   rE   )r   rY   rc   _secrets       r   
set_secretzItem.set_secretw   sb    
 	 0t//4<$,=='*//+z733333r!   c                 h    | j                             d          }t          |t                    sJ |S )zlReturns 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    
 J##I..'	GS	!	!!!!	.r!   c                 h    | j                             d          }t          |t                    sJ |S )zYReturns UNIX timestamp (integer) representing the time
		when the item was last modified.Modifiedrj   )r   modifieds     r   get_modifiedzItem.get_modified   s4     Z$$Z00(	Hc	"	""""	/r!   r$   )r   N)rb   )__name__
__module____qualname____doc__r   r&   r   r   r    r*   r'   r,   r.   r0   r   r5   r9   r=   r@   rI   rR   r^   ra   rg   rk   rm   rq    r!   r   r   r      s	          <@  '/'8DH   +) +d + + + +1 1 1 1 1
, , , ,;T ; ; ; ;T#s(^    
=d38n = = = = =    /C /D / / / /
8 8 8 8, , , , ,"c     %1	4 	4e 	4!	459	4 	4 	4 	4#    3      r!   N)ru   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   objectr   rv   r!   r   <module>r      s5  ? ? " ! ! ! ! ! ! ! . . . . . . + + + + + + * * * * * * N N N N N N N N: : : : : : : : : : : : : : L L L L L L L L L L 8 8 8 8 8 8
x x x x x6 x x x x xr!   