
    b                         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
      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.    )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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       4/usr/lib/python3/dist-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_locked-   s     >>!"344 r!   c                 D    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.unlock3   s     doo/?@@r!   c                 N    | j                   j                  d      }t        |      S )z%Returns item attributes (dictionary).
Attributes)r   r   dict)r   attrss     r   get_attributeszItem.get_attributesB   s     

''5E{r!   
attributesc                 >    | j                   j                  dd|       y)z2Sets item attributes to `attributes` (dictionary).r2   za{ss}N)r   set_property)r   r6   s     r   set_attributeszItem.set_attributesG   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_labelK   s+    

''0%%%%r!   r<   c                 ^    | j                          | j                  j                  dd|       y)zSets item label to `label`.r   sN)r.   r   r8   r;   s     r   	set_labelzItem.set_labelQ   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.deleteV   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   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_   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).rK   rL      )r.   r   r   r   r   rE   rP   r&   )r   rY   s     r   get_secret_content_typezItem.get_secret_content_typep   sU     ||'8DL**//+sDLL4L4LM6!9~r!   rY   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   rE   )r   rY   rb   _secrets       r   
set_secretzItem.set_secretx   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.Modifiedri   )r   modifieds     r   get_modifiedzItem.get_modified   s-     ::**:6(C(((r!   r$   )r   N)z
text/plain)__name__
__module____qualname____doc__r   r&   r   r   r    r*   r'   r,   r.   r0   r   r5   r9   r=   r@   rI   rR   r^   ra   rf   rj   rl   rp    r!   r   r   r      s   # ?C%> %%*27*;%GK%1, 1 174 7
5A AS#X 
Cc3h CD C3 5s 5t 5
D2E 2"  (4	: 	:!$	:8<	:S c r!   N)rt   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   ru   r!   r   <module>r~      sD   ? " . + * N: : L L 8
x xr!   