Skip to content

Commit

Permalink
Update Secret Session implementation
Browse files Browse the repository at this point in the history
Session now implements Clone trait.
Has manager field.
client_public_key field now has an Arc

Also, adds remove_session() for ServiceManager

Signed-off-by: Dhanuka Warusadura <[email protected]>
  • Loading branch information
warusadura committed Feb 21, 2024
1 parent 7d584ae commit 95ebf46
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion server/src/daemon/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Service {
Algorithm::Plain => None,
Algorithm::Encrypted => Some(Key::from(input)),
};
let (session, key) = Session::new(client_public_key);
let (session, key) = Session::new(client_public_key, Arc::clone(&self.manager));
// TODO: clean up the default generated key
// TODO call self.manager.set_sessions();
let key = key
Expand Down
11 changes: 8 additions & 3 deletions server/src/daemon/service_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ impl ServiceManager {
}

pub async fn session(&self, path: ObjectPath<'_>) -> Option<&Session> {

Check failure on line 20 in server/src/daemon/service_manager.rs

View workflow job for this annotation

GitHub Actions / Clippy

methods `session`, `insert_session`, and `remove_session` are never used

Check warning on line 20 in server/src/daemon/service_manager.rs

View workflow job for this annotation

GitHub Actions / Check

methods `session`, `insert_session`, and `remove_session` are never used
self.sessions.read().await.get(&path.into())
self.sessions.read().await.get(&path.into()).to_owned();
todo!()
}

pub async fn insert_session(&mut self, path: OwnedObjectPath, session: Session) {
self.sessions.write().await.insert(path, session);
pub async fn insert_session(&mut self, path: ObjectPath<'_>, session: Session) {
self.sessions.write().await.insert(path.into(), session);
}

pub async fn remove_session(&mut self, path: ObjectPath<'_>) {
self.sessions.write().await.remove(&path.into());
}
}
17 changes: 13 additions & 4 deletions server/src/daemon/session.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// org.freedesktop.Secret.Session

use std::sync::Arc;

use oo7::Key;
use zbus::{fdo, interface, zvariant};
use zvariant::{ObjectPath, OwnedObjectPath};

#[derive(Debug)]
use super::service_manager::ServiceManager;

#[derive(Debug, Clone)]
pub struct Session {
client_public_key: Option<Key>,
client_public_key: Arc<Option<Key>>,

Check warning on line 13 in server/src/daemon/session.rs

View workflow job for this annotation

GitHub Actions / Check

fields `client_public_key` and `manager` are never read
manager: Arc<ServiceManager>,
pub path: OwnedObjectPath,
}

Expand All @@ -22,12 +27,16 @@ impl Session {
}

impl Session {
pub fn new(client_public_key: Option<Key>) -> (Self, Option<Key>) {
pub fn new(
client_public_key: Option<Key>,
manager: Arc<ServiceManager>,
) -> (Self, Option<Key>) {
// make use of the keys
let service_key = vec![0];
let instance = Self {
client_public_key,
client_public_key: Arc::new(client_public_key),
path: OwnedObjectPath::try_from(format!("{}", "a")).unwrap(),
manager,
};

(instance, Some(Key::new(service_key)))
Expand Down

0 comments on commit 95ebf46

Please sign in to comment.