Skip to content

Commit d2b7229

Browse files
committed
Using secrecy 0.8
modified session_key.rs to impl secrecy::Zeroize for SessionKey modified session.rs in attempts of adding secrecy::Secret<SessionKey> to InnerSession struct.
1 parent 1774b8a commit d2b7229

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

actix-session/Cargo.toml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ redis-rs-tls-session = ["redis-rs-session", "redis/tokio-native-tls-comp"]
3030
[dependencies]
3131
actix-service = "2"
3232
actix-utils = "3"
33-
actix-web = { version = "4", default_features = false, features = ["cookies", "secure-cookies"] }
33+
actix-web = { version = "4", default_features = false, features = [
34+
"cookies",
35+
"secure-cookies",
36+
] }
3437

3538
anyhow = "1"
3639
async-trait = "0.1"
@@ -44,14 +47,27 @@ tracing = { version = "0.1.30", default-features = false, features = ["log"] }
4447
actix = { version = "0.13", default-features = false, optional = true }
4548
actix-redis = { version = "0.12", optional = true }
4649
futures-core = { version = "0.3.7", default-features = false, optional = true }
50+
secrecy = "0.8"
4751

4852
# redis-rs-session
49-
redis = { version = "0.21", default-features = false, features = ["aio", "tokio-comp", "connection-manager"], optional = true }
53+
redis = { version = "0.21", default-features = false, features = [
54+
"aio",
55+
"tokio-comp",
56+
"connection-manager",
57+
], optional = true }
5058

5159
[dev-dependencies]
52-
actix-session = { path = ".", features = ["cookie-session", "redis-actor-session", "redis-rs-session"] }
60+
actix-session = { path = ".", features = [
61+
"cookie-session",
62+
"redis-actor-session",
63+
"redis-rs-session",
64+
] }
5365
actix-test = "0.1.0-beta.10"
54-
actix-web = { version = "4", default_features = false, features = ["cookies", "secure-cookies", "macros"] }
66+
actix-web = { version = "4", default_features = false, features = [
67+
"cookies",
68+
"secure-cookies",
69+
"macros",
70+
] }
5571
env_logger = "0.9"
5672
log = "0.4"
5773

actix-session/src/session.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use anyhow::Context;
1717
use derive_more::{Display, From};
1818
use serde::{de::DeserializeOwned, Serialize};
1919

20+
use crate::storage::SessionKey;
21+
2022
/// The primary interface to access and modify session state.
2123
///
2224
/// [`Session`] is an [extractor](#impl-FromRequest)—you can specify it as an input type for your
@@ -77,6 +79,7 @@ impl Default for SessionStatus {
7779
struct SessionInner {
7880
state: HashMap<String, String>,
7981
status: SessionStatus,
82+
session_key: SessionKey,
8083
}
8184

8285
impl Session {
@@ -101,7 +104,13 @@ impl Session {
101104
Ok(None)
102105
}
103106
}
104-
107+
/// Get a the session key itself from the overall session.
108+
///
109+
/// Needs to be implemented
110+
pub fn get_session_key(&self) -> secrecy::Secret<SessionKey> {
111+
let key = self.0.borrow().session_key.clone();
112+
secrecy::Secret::new(key)
113+
}
105114
/// Get all raw key-value data from the session.
106115
///
107116
/// Note that values are JSON encoded.

actix-session/src/storage/session_key.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use derive_more::{Display, From};
1717
/// let session_key: Result<SessionKey, _> = key.try_into();
1818
/// assert!(session_key.is_err());
1919
/// ```
20-
#[derive(Debug, PartialEq, Eq)]
21-
pub struct SessionKey(String);
20+
#[derive(Debug, PartialEq, Eq, Default, Clone)]
21+
pub struct SessionKey(pub String);
2222

2323
impl TryFrom<String> for SessionKey {
2424
type Error = InvalidSessionKeyError;
@@ -41,6 +41,12 @@ impl AsRef<str> for SessionKey {
4141
}
4242
}
4343

44+
impl secrecy::Zeroize for SessionKey {
45+
fn zeroize(&mut self) {
46+
self.0.zeroize();
47+
}
48+
}
49+
4450
impl From<SessionKey> for String {
4551
fn from(key: SessionKey) -> Self {
4652
key.0

0 commit comments

Comments
 (0)