Skip to content

Commit d3d7410

Browse files
committed
Update Secret Session implementation
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 <dhanuka@gnome.org>
1 parent 7d584ae commit d3d7410

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

server/src/daemon/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Service {
4545
Algorithm::Plain => None,
4646
Algorithm::Encrypted => Some(Key::from(input)),
4747
};
48-
let (session, key) = Session::new(client_public_key);
48+
let (session, key) = Session::new(client_public_key, Arc::clone(&self.manager));
4949
// TODO: clean up the default generated key
5050
// TODO call self.manager.set_sessions();
5151
let key = key

server/src/daemon/service_manager.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@ impl ServiceManager {
1717
}
1818
}
1919

20-
pub async fn session(&self, path: ObjectPath<'_>) -> Option<&Session> {
21-
self.sessions.read().await.get(&path.into())
20+
pub async fn session(&self, path: ObjectPath<'_>) -> Option<Session> {
21+
self.sessions
22+
.read()
23+
.await
24+
.get(&path.into())
25+
.to_owned()
26+
.cloned()
2227
}
2328

24-
pub async fn insert_session(&mut self, path: OwnedObjectPath, session: Session) {
25-
self.sessions.write().await.insert(path, session);
29+
pub async fn insert_session(&mut self, path: ObjectPath<'_>, session: Session) {
30+
self.sessions.write().await.insert(path.into(), session);
31+
}
32+
33+
pub async fn remove_session(&mut self, path: ObjectPath<'_>) {
34+
self.sessions.write().await.remove(&path.into());
2635
}
2736
}

server/src/daemon/session.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
// org.freedesktop.Secret.Session
22

3+
use std::sync::Arc;
4+
35
use oo7::Key;
46
use zbus::{fdo, interface, zvariant};
57
use zvariant::{ObjectPath, OwnedObjectPath};
68

7-
#[derive(Debug)]
9+
use super::service_manager::ServiceManager;
10+
11+
#[derive(Debug, Clone)]
812
pub struct Session {
9-
client_public_key: Option<Key>,
13+
client_public_key: Arc<Option<Key>>,
14+
manager: Arc<ServiceManager>,
1015
pub path: OwnedObjectPath,
1116
}
1217

@@ -22,12 +27,16 @@ impl Session {
2227
}
2328

2429
impl Session {
25-
pub fn new(client_public_key: Option<Key>) -> (Self, Option<Key>) {
30+
pub fn new(
31+
client_public_key: Option<Key>,
32+
manager: Arc<ServiceManager>,
33+
) -> (Self, Option<Key>) {
2634
// make use of the keys
2735
let service_key = vec![0];
2836
let instance = Self {
29-
client_public_key,
37+
client_public_key: Arc::new(client_public_key),
3038
path: OwnedObjectPath::try_from(format!("{}", "a")).unwrap(),
39+
manager,
3140
};
3241

3342
(instance, Some(Key::new(service_key)))

0 commit comments

Comments
 (0)