1pub mod auth;
2pub mod database;
3pub mod errors;
4pub mod request;
5mod utils;
6
7#[derive(Clone, Debug)]
8pub struct User<U> {
9 pub user_id: UserId,
10 pub user_attributes: U,
11}
12
13#[derive(Clone, Debug)]
14pub struct Session {
15 pub active_period_expires_at: i64,
16 pub session_id: String,
17 pub idle_period_expires_at: i64,
18 pub state: SessionState,
19 pub fresh: bool,
20}
21
22#[derive(Clone, Debug)]
23pub struct ValidationSuccess<U> {
24 pub session: Session,
25 pub user: User<U>,
26}
27
28#[derive(Clone, Debug, PartialEq)]
29pub enum SessionState {
30 Active,
31 Idle,
32}
33
34#[derive(Clone, Debug)]
35pub struct UserData {
36 pub provider_id: String,
37 pub provider_user_id: String,
38 pub password: Option<String>,
39}
40
41impl UserData {
42 pub fn new(provider_id: String, provider_user_id: String, password: Option<String>) -> Self {
43 assert!(
44 !provider_id.contains(':'),
45 "provider id must not contain any ':' characters"
46 );
47 Self {
48 provider_id,
49 provider_user_id,
50 password,
51 }
52 }
53}
54
55#[derive(Clone, Debug)]
56pub enum KeyType {
57 Persistent { primary: bool },
58 SingleUse { expires_in: KeyTimestamp },
59}
60
61#[derive(Clone, Debug)]
62pub enum NaiveKeyType {
63 Persistent,
64 SingleUse { expires_in: KeyTimestamp },
65}
66
67pub struct SessionId<'a>(&'a str);
68
69impl<'a> SessionId<'a> {
70 pub fn new(session_id: &'a str) -> Self {
71 Self(session_id)
72 }
73
74 pub fn as_str(&self) -> &str {
75 self.0
76 }
77}
78
79impl<'a> ToString for SessionId<'a> {
80 fn to_string(&self) -> String {
81 self.0.to_string()
82 }
83}
84
85impl<'a> From<&'a str> for SessionId<'a> {
86 fn from(value: &'a str) -> Self {
87 Self::new(value)
88 }
89}
90
91#[derive(Clone, Debug, Copy)]
92pub struct KeyTimestamp(pub(crate) i64);
93
94#[derive(Clone, Debug)]
95pub struct Key {
96 pub key_type: KeyType,
97 pub password_defined: bool,
98 pub user_id: UserId,
99 pub provider_id: String,
100 pub provider_user_id: String,
101}
102
103#[derive(Clone, Debug)]
104pub struct UserId(String);
105
106impl UserId {
107 pub fn new(user_id: String) -> Self {
108 assert!(
109 !user_id.contains('.'),
110 "user id must not contain any '.' characters"
111 );
112 Self(user_id)
113 }
114
115 pub fn as_str(&self) -> &str {
116 &self.0
117 }
118}
119
120impl ToString for UserId {
121 fn to_string(&self) -> String {
122 self.0.clone()
123 }
124}