o j­_yã@s dZddlmZmZddlmZddlmZddlm Z ddl m Z m Z ddl mZmZmZmZmZddlmZmZmZdd lmZed ZGd d „d eƒZd S) aQSecretStorage 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 ` 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 @seZdZdZ d,dededeeddfdd„Zd d de fd d „Z de fd d„Z d-dd„Z de fdd„Z deeeffdd„Zdeeefddfdd„Zdefdd„Zdeddfdd„Zd-dd„Zdefdd „Zdefd!d"„Z #d.d$ed%eddfd&d'„Zdefd(d)„Zdefd*d+„ZdS)/rzRepresents a secret item.NÚ connectionÚ item_pathÚsessionÚreturncCs0||_t|t|ƒ|_|j d¡||_||_dS)NÚLabel)rr Ú ITEM_IFACEÚ_itemÚ get_propertyrr)Úselfrrr©rú4/usr/lib/python3/dist-packages/secretstorage/item.pyÚ__init__s   z Item.__init__ÚotherrcCst|jtƒsJ‚|j|jkS©N)Ú isinstancerÚstr)rrrrrÚ__eq__#s z Item.__eq__cCst|j d¡ƒS)zDReturns :const:`True` if item is locked, otherwise :const:`False`.ÚLocked)Úboolrr©rrrrÚ is_locked'szItem.is_lockedcCs| ¡rtdƒ‚dS)zSIf collection is locked, raises :exc:`~secretstorage.exceptions.LockedException`.zItem is locked!N)r'rr&rrrÚensure_not_locked,sÿzItem.ensure_not_lockedcCst|j|jgƒ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 rrr&rrrÚunlock2s z Item.unlockcCs|j d¡}t|ƒS)z%Returns item attributes (dictionary).Ú Attributes)rrÚdict)rÚattrsrrrÚget_attributesAs zItem.get_attributesÚ attributescCs|j dd|¡dS)z2Sets item attributes to `attributes` (dictionary).r*za{ss}N)rÚ set_property)rr.rrrÚset_attributesFszItem.set_attributescCó|j d¡}t|tƒs J‚|S)z$Returns item label (unicode string).r)rrr!r"©rÚlabelrrrÚ get_labelJs zItem.get_labelr3cCs| ¡|j dd|¡dS)zSets item label to `label`.rÚsN)r(rr/r2rrrÚ set_labelPszItem.set_labelcCsD| ¡|j dd¡\}|dkrt|j|ƒ\}}|r tdƒ‚dSdS)zDeletes the item.ÚDeleteÚú/zPrompt dismissed.N)r(rÚcallr rr)rÚpromptÚ dismissedÚ_resultrrrÚdeleteUsýz Item.deletecCsÄ| ¡|js t|jƒ|_|j dd|jj¡\}|jjs"t|dƒS|jj dus*J‚t   |jj ¡}t|dƒ}t |t  |¡tƒƒ ¡}|d}| t|ƒ¡| ¡}t|tƒsYJ‚|d|d …S)z!Returns item secret (bytestring).Ú GetSecretÚoéNééÿÿÿÿ)r(rr rrr:Ú object_pathÚ encryptedÚbytesÚaes_keyrÚAESrrÚCBCrÚ decryptorÚupdateÚfinalizer!)rÚsecretÚaesÚaes_ivrJÚencrypted_secretÚ padded_secretrrrÚ get_secret^s   zItem.get_secretcCs<| ¡|js t|jƒ|_|j dd|jj¡\}t|dƒS)z-Returns content type of item secret (string).r?r@é)r(rr rrr:rDr")rrMrrrÚget_secret_content_typeos   zItem.get_secret_content_typeú text/plainrMÚ content_typecCs<| ¡|js t|jƒ|_t|j||ƒ}|j dd|¡dS)zƒSets 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(rr rr rr:)rrMrVÚ_secretrrrÚ set_secretws  zItem.set_secretcCr1)zlReturns UNIX timestamp (integer) representing the time when the item was created. .. versionadded:: 1.1ÚCreated©rrr!Úint)rÚcreatedrrrÚ get_created‚s zItem.get_createdcCr1)zYReturns UNIX timestamp (integer) representing the time when the item was last modified.ÚModifiedr[)rÚmodifiedrrrÚ get_modified‹s zItem.get_modifiedr )rN)rU)Ú__name__Ú __module__Ú __qualname__Ú__doc__rr"rrrr%r#r'r(r)rr-r0r4r6r>rFrRrTrYr\r^rarrrrrs:ÿÿÿ ÿ    ÿÿ ÿ  N)reÚtypingrrÚjeepney.io.blockingrÚsecretstorage.definesrÚsecretstorage.dhcryptorÚsecretstorage.exceptionsrrÚsecretstorage.utilr r r r r Ú&cryptography.hazmat.primitives.ciphersrrrÚcryptography.hazmat.backendsrrÚobjectrrrrrÚs