KeyBoxen 0.1.0

Standalone secret-service daemon for window managers
// Copyright (C) 2022 KeyBoxen Authors
// SPDX-License-Identifier: GPL-3.0-or-later

//! Items module
//!
//! This module implements the object that represents each
//! [item][ch03]. An item is a container for a [secret][ch02] and its
//! associated parameters.
//!
//! # Lazy loading
//! The secret is not loaded into memory by default. It is loaded only on
//! demand from the on-disk database in its encrypted form. The secret
//! is then decrypted using the key from the collection before sending
//! it to the client via DBus.
//!
//! # Locking
//! The items can be locked in a **soft** form.
//!
//! If the collection is already unlocked, then the user will be just
//! prompted for confirmation (allow/disallow) before the secret is
//! passed to the client.
//!
//! If the collection is locked, then the user will be prompted for
//! the collection's password. Both the collection and the item will
//! be considered unlocked upon successful password entry.
//!
//! ## Default locking
//! Items can be set to be locked by default. If it is marked as such,
//! then the user will be prompted for confirmation to unlock in every
//! new session where the secret is needed.
//!
//! [ch02]: https://specifications.freedesktop.org/secret-service/latest/ch02.html
//! [ch03]: https://specifications.freedesktop.org/secret-service/latest/ch03.html

use super::{lock, Item};

impl lock::Lockable for Item {
    fn is_locked(&self) -> bool {
        self.locked
    }

    fn lock(&mut self) -> lock::Result {
        self.locked = true;
        Ok(())
    }

    fn unlock(&mut self) -> lock::Result {
        self.locked = false;
        Ok(())
    }
}