U
    ¶[Öey  ã                   @   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
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                   @   s
  e Zd ZdZd)eeee ddœdd„Zde	dœdd	„Z
e	d
œdd„Zdd
œdd„Ze	d
œdd„Zeeef d
œdd„Zeeef ddœdd„Zed
œdd„Zeddœdd„Zdd
œdd„Zed
œdd„Zed
œdd „Zd*eedd"œd#d$„Zed
œd%d&„Zed
œ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   úT/var/www/html/services/stratfitenv/lib/python3.8/site-packages/secretstorage/item.pyÚ__init__   s
    zItem.__init__r   )Úotherr   c                 C   s   t |jtƒst‚| j|jkS )N)Ú
isinstancer   ÚstrÚAssertionError)r   r   r   r   r   Ú__eq__#   s    zItem.__eq__)r   c                 C   s   t | j d¡ƒS )zDReturns :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 )zSIf 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   Úunlock2   s    zItem.unlockc                 C   s   | j  d¡}t|ƒS )z%Returns item attributes (dictionary).Ú
Attributes)r   r   Údict)r   Úattrsr   r   r   Úget_attributesA   s    zItem.get_attributes)Ú
attributesr   c                 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_attributesF   s    zItem.set_attributesc                 C   s   | j  d¡}t|tƒst‚|S )z$Returns item label (unicode string).r   )r   r   r    r!   r"   ©r   Úlabelr   r   r   Ú	get_labelJ   s    zItem.get_label)r2   r   c                 C   s   |   ¡  | j dd|¡ dS )zSets item label to `label`.r   ÚsN)r(   r   r/   r1   r   r   r   Ú	set_labelP   s    zItem.set_labelc                 C   s@   |   ¡  | j dd¡\}|dkr<t| j|ƒ\}}|r<tdƒ‚dS )zDeletes the item.ÚDeleteÚ ú/zPrompt dismissed.N)r(   r   Úcallr
   r   r   )r   ÚpromptZ	dismissedÚ_resultr   r   r   ÚdeleteU   s    zItem.deletec                 C   sÄ   |   ¡  | jst| jƒ| _| j dd| jj¡\}| jjsDt|d ƒS | jj	dk	sTt
‚t | jj	¡}t|d ƒ}t|t |¡tƒ ƒ ¡ }|d }| t|ƒ¡| ¡  }t|tƒs²t
‚|d|d  … S )z!Returns item secret (bytestring).Ú	GetSecretÚoé   Né   éÿÿÿÿ)r(   r   r   r   r   r9   Úobject_pathZ	encryptedÚbytesZaes_keyr"   r   ZAESr   r   ZCBCr   Ú	decryptorÚupdateÚfinalizer    )r   ÚsecretZaesZaes_ivrD   Zencrypted_secretZ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   r9   rB   r!   )r   rG   r   r   r   Úget_secret_content_typeo   s
    zItem.get_secret_content_typeú
text/plain)rG   Úcontent_typer   c                 C   s<   |   ¡  | jst| jƒ| _t| j||ƒ}| j dd|¡ dS )zƒSets item secret to `secret`. If `content_type` is given,
		also sets the content type of the secret (``text/plain`` by
		default).Z	SetSecretz(oayays)N)r(   r   r   r   r   r   r9   )r   rG   rL   Z_secretr   r   r   Ú
set_secretw   s
    zItem.set_secretc                 C   s   | j  d¡}t|tƒst‚|S )zlReturns UNIX timestamp (integer) representing the time
		when the item was created.

		.. versionadded:: 1.1ÚCreated©r   r   r    Úintr"   )r   Úcreatedr   r   r   Úget_created‚   s    zItem.get_createdc                 C   s   | j  d¡}t|tƒst‚|S )zYReturns UNIX timestamp (integer) representing the time
		when the item was last modified.ZModifiedrO   )r   Úmodifiedr   r   r   Úget_modified‹   s    zItem.get_modified)N)rK   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r!   r   r   r   r%   r#   r'   r(   r)   r   r-   r0   r3   r5   r<   rC   rH   rJ   rM   rP   rR   rT   r   r   r   r   r      s2    ÿ  ÿ		 ÿ ÿ	N)rX   Útypingr   r   Zjeepney.io.blockingr   Zsecretstorage.definesr   Zsecretstorage.dhcryptor   Zsecretstorage.exceptionsr   r   Zsecretstorage.utilr	   r
   r   r   r   Z&cryptography.hazmat.primitives.ciphersr   r   r   Zcryptography.hazmat.backendsr   r   Úobjectr   r   r   r   r   Ú<module>   s   