Skip to content

Commit da83149

Browse files
authored
Merge pull request #54 from Xila-Project/Feature/Login
2 parents edcf7f5 + 98674ab commit da83149

File tree

34 files changed

+1635
-189
lines changed

34 files changed

+1635
-189
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ members = [
7878
"Modules/Executables/WASM",
7979
"Modules/Executables/Shell/Graphical",
8080
"Modules/Executables/Terminal",
81+
"Modules/Authentication"
8182
]
8283
exclude = [
8384
"Modules/Virtual_machine/Tests/WASM_test",

Modules/Authentication/Cargo.toml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "Authentication"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
Virtual_file_system = { path = "../Virtual_file_system" }
8+
Users = { path = "../Users" }
9+
Task = { path = "../Task" }
10+
File_system = { path = "../File_system" }
11+
sha2 = { version = "0.10", features = ["asm"] }
12+
miniserde = "0.1.41"

Modules/Authentication/src/Error.rs

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
use std::fmt::Display;
2+
3+
pub type Result_type<T> = Result<T, Error_type>;
4+
5+
#[derive(Debug, Clone)]
6+
pub enum Error_type {
7+
Failed_to_get_current_task_identifier(Task::Error_type),
8+
Failed_to_read_users_directory(File_system::Error_type),
9+
Failed_to_get_user_file_path,
10+
Failed_to_open_user_file(File_system::Error_type),
11+
Failed_to_read_user_file(File_system::Error_type),
12+
Failed_to_parse_user_file(miniserde::Error),
13+
Failed_to_add_user(Users::Error_type),
14+
Failed_to_get_new_user_identifier(Users::Error_type),
15+
Failed_to_create_user(Users::Error_type),
16+
Failed_to_write_user_file(File_system::Error_type),
17+
Failed_to_read_group_directory(File_system::Error_type),
18+
Failed_to_get_group_file_path,
19+
Failed_to_open_group_file(File_system::Error_type),
20+
Failed_to_read_group_file(File_system::Error_type),
21+
Failed_to_parse_group_file(miniserde::Error),
22+
Failed_to_add_group(Users::Error_type),
23+
Failed_to_get_new_group_identifier(Users::Error_type),
24+
Failed_to_create_group(Users::Error_type),
25+
Failed_to_write_group_file(File_system::Error_type),
26+
Invalid_password,
27+
Failed_to_open_random_device(File_system::Error_type),
28+
Failed_to_read_random_device(File_system::Error_type),
29+
Failed_to_get_user_identifier(Users::Error_type),
30+
}
31+
32+
impl Display for Error_type {
33+
fn fmt(&self, Formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
34+
match self {
35+
Self::Failed_to_get_current_task_identifier(Error) => {
36+
write!(
37+
Formatter,
38+
"Failed to get current task identifier: {}",
39+
Error
40+
)
41+
}
42+
Self::Failed_to_read_users_directory(Error) => {
43+
write!(Formatter, "Failed to read users directory: {}", Error)
44+
}
45+
Self::Failed_to_get_user_file_path => {
46+
write!(Formatter, "Failed to get user file path")
47+
}
48+
Self::Failed_to_read_user_file(Error) => {
49+
write!(Formatter, "Failed to read user file: {}", Error)
50+
}
51+
Self::Failed_to_open_user_file(Error) => {
52+
write!(Formatter, "Failed to open user file: {}", Error)
53+
}
54+
Self::Failed_to_parse_user_file(Error) => {
55+
write!(Formatter, "Failed to parse user file: {}", Error)
56+
}
57+
Self::Failed_to_add_user(Error) => {
58+
write!(Formatter, "Failed to add user: {}", Error)
59+
}
60+
Self::Failed_to_read_group_directory(Error) => {
61+
write!(Formatter, "Failed to read group directory: {}", Error)
62+
}
63+
Self::Failed_to_get_group_file_path => {
64+
write!(Formatter, "Failed to get group file path")
65+
}
66+
Self::Failed_to_open_group_file(Error) => {
67+
write!(Formatter, "Failed to open group file: {}", Error)
68+
}
69+
Self::Failed_to_read_group_file(Error) => {
70+
write!(Formatter, "Failed to read group file: {}", Error)
71+
}
72+
Self::Failed_to_parse_group_file(Error) => {
73+
write!(Formatter, "Failed to parse group file: {}", Error)
74+
}
75+
Self::Failed_to_add_group(Error) => {
76+
write!(Formatter, "Failed to add group: {}", Error)
77+
}
78+
Self::Invalid_password => {
79+
write!(Formatter, "Invalid password")
80+
}
81+
Self::Failed_to_open_random_device(Error) => {
82+
write!(Formatter, "Failed to open random device: {}", Error)
83+
}
84+
Self::Failed_to_read_random_device(Error) => {
85+
write!(Formatter, "Failed to read random device: {}", Error)
86+
}
87+
Self::Failed_to_create_user(Error) => {
88+
write!(Formatter, "Failed to create user: {}", Error)
89+
}
90+
Self::Failed_to_get_new_user_identifier(Error) => {
91+
write!(Formatter, "Failed to get new user identifier: {}", Error)
92+
}
93+
Self::Failed_to_write_user_file(Error) => {
94+
write!(Formatter, "Failed to write user file: {}", Error)
95+
}
96+
Self::Failed_to_get_new_group_identifier(Error) => {
97+
write!(Formatter, "Failed to get new group identifier: {}", Error)
98+
}
99+
Self::Failed_to_create_group(Error) => {
100+
write!(Formatter, "Failed to create group: {}", Error)
101+
}
102+
Self::Failed_to_write_group_file(Error) => {
103+
write!(Formatter, "Failed to write group file: {}", Error)
104+
}
105+
Self::Failed_to_get_user_identifier(Error) => {
106+
write!(Formatter, "Failed to get user identifier: {}", Error)
107+
}
108+
}
109+
}
110+
}
111+
112+
impl From<Task::Error_type> for Error_type {
113+
fn from(Error: Task::Error_type) -> Self {
114+
Self::Failed_to_get_current_task_identifier(Error)
115+
}
116+
}

Modules/Authentication/src/Group.rs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use miniserde::{Deserialize, Serialize};
2+
use Users::{
3+
Group_identifier_inner_type, Group_identifier_type, User_identifier_inner_type,
4+
User_identifier_type,
5+
};
6+
7+
#[derive(Clone, Debug, Deserialize, Serialize)]
8+
pub struct Group_type {
9+
Identifier: Group_identifier_inner_type,
10+
Name: String,
11+
Users: Vec<User_identifier_inner_type>,
12+
}
13+
14+
impl Group_type {
15+
pub fn New(
16+
Identifier: Group_identifier_inner_type,
17+
Name: String,
18+
Users: Vec<User_identifier_inner_type>,
19+
) -> Self {
20+
Self {
21+
Identifier,
22+
Name,
23+
Users,
24+
}
25+
}
26+
27+
pub fn Get_identifier(&self) -> Group_identifier_type {
28+
Group_identifier_type::New(self.Identifier)
29+
}
30+
31+
pub fn Get_name(&self) -> &str {
32+
&self.Name
33+
}
34+
35+
pub fn Get_users(&self) -> &[User_identifier_type] {
36+
// Avoid to copy the vector since User_identifier_type is transparent to User_identifier_inner_type.
37+
unsafe { core::mem::transmute(self.Users.as_slice()) }
38+
}
39+
}

Modules/Authentication/src/User.rs

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
use miniserde::{Deserialize, Serialize};
2+
use Users::{
3+
Group_identifier_inner_type, Group_identifier_type, User_identifier_inner_type,
4+
User_identifier_type,
5+
};
6+
7+
#[derive(Clone, Debug, Deserialize, Serialize)]
8+
pub struct User_type {
9+
Identifier: User_identifier_inner_type,
10+
Name: String,
11+
Primary_group: Group_identifier_inner_type,
12+
Hash: String,
13+
Salt: String,
14+
}
15+
16+
impl User_type {
17+
pub fn New(
18+
Identifier: User_identifier_inner_type,
19+
Name: String,
20+
Primary_group: Group_identifier_inner_type,
21+
Hash: String,
22+
Salt: String,
23+
) -> Self {
24+
Self {
25+
Identifier,
26+
Name,
27+
Primary_group,
28+
Hash,
29+
Salt,
30+
}
31+
}
32+
33+
pub fn Get_identifier(&self) -> User_identifier_type {
34+
User_identifier_type::New(self.Identifier)
35+
}
36+
37+
pub fn Get_primary_group(&self) -> Group_identifier_type {
38+
Group_identifier_type::New(self.Primary_group)
39+
}
40+
41+
pub fn Get_name(&self) -> &str {
42+
&self.Name
43+
}
44+
45+
pub fn Get_hash(&self) -> &str {
46+
&self.Hash
47+
}
48+
49+
pub fn Get_salt(&self) -> &str {
50+
&self.Salt
51+
}
52+
53+
pub fn Set_hash(&mut self, Hash: String) {
54+
self.Hash = Hash;
55+
}
56+
57+
pub fn Set_salt(&mut self, Salt: String) {
58+
self.Salt = Salt;
59+
}
60+
61+
pub fn Set_primary_group(&mut self, Primary_group: Group_identifier_inner_type) {
62+
self.Primary_group = Primary_group;
63+
}
64+
65+
pub fn Set_name(&mut self, Name: String) {
66+
self.Name = Name;
67+
}
68+
}

0 commit comments

Comments
 (0)