def set_secret(self, secret, content_type='text/plain'): """Sets item secret to `secret`. If `content_type` is given, also sets the content type of the secret (``text/plain`` by default).""" self.ensure_not_locked() if not self.session: self.session = open_session(self.bus) secret = format_secret(self.session, secret, content_type) self.item_iface.SetSecret(secret, signature='(oayays)')
def set_secret(self, secret: bytes, content_type: str = 'text/plain') -> None: """Sets item secret to `secret`. If `content_type` is given, also sets the content type of the secret (``text/plain`` by default).""" self.ensure_not_locked() if not self.session: self.session = open_session(self.connection) _secret = format_secret(self.session, secret, content_type) self._item.call('SetSecret', '(oayays)', _secret)
def create_item(self, label, attributes, secret, replace=False, content_type='text/plain'): """Creates a new :class:`~secretstorage.item.Item` with given `label` (unicode string), `attributes` (dictionary) and `secret` (bytestring). If `replace` is :const:`True`, replaces the existing item with the same attributes. If `content_type` is given, also sets the content type of the secret (``text/plain`` by default). Returns the created item.""" self.ensure_not_locked() if not self.session: self.session = open_session(self.bus) secret = format_secret(self.session, secret, content_type) attributes = dbus.Dictionary(attributes, signature='ss') properties = { SS_PREFIX+'Item.Label': label, SS_PREFIX+'Item.Attributes': attributes } new_item, prompt = self.collection_iface.CreateItem(properties, secret, replace, signature='a{sv}(oayays)b') return Item(self.bus, new_item, self.session)
def create_item(self, label: str, attributes: Dict[str, str], secret: bytes, replace: bool = False, content_type: str = 'text/plain') -> Item: """Creates a new :class:`~secretstorage.item.Item` with given `label` (unicode string), `attributes` (dictionary) and `secret` (bytestring). If `replace` is :const:`True`, replaces the existing item with the same attributes. If `content_type` is given, also sets the content type of the secret (``text/plain`` by default). Returns the created item.""" self.ensure_not_locked() if not self.session: self.session = open_session(self.connection) _secret = format_secret(self.session, secret, content_type) properties = { SS_PREFIX + 'Item.Label': ('s', label), SS_PREFIX + 'Item.Attributes': ('a{ss}', attributes), } new_item, prompt = self._collection.call('CreateItem', 'a{sv}(oayays)b', properties, _secret, replace) return Item(self.connection, new_item, self.session)