Skip to content

Commit a562edc

Browse files
committed
adding secure file vault
1 parent 4a12444 commit a562edc

File tree

17 files changed

+739
-0
lines changed

17 files changed

+739
-0
lines changed

Module03/data_vault/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "data_vault"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
serde = { version = "1.0", features = ["derive"] }
8+
serde_json = "1.0"
9+

Module03/data_vault/src/colors.rs

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// Reset and text styles
2+
pub const RESET: &str = "\x1b[0m";
3+
pub const BOLD: &str = "\x1b[1m";
4+
5+
// Tailwind CSS Colors: Gray
6+
pub const GRAY50: &str = "\x1b[38;2;249;250;251m";
7+
pub const GRAY100: &str = "\x1b[38;2;243;244;246m";
8+
pub const GRAY200: &str = "\x1b[38;2;229;231;235m";
9+
pub const GRAY300: &str = "\x1b[38;2;209;213;219m";
10+
pub const GRAY400: &str = "\x1b[38;2;156;163;175m";
11+
pub const GRAY500: &str = "\x1b[38;2;107;114;128m";
12+
pub const GRAY600: &str = "\x1b[38;2;75;85;99m";
13+
pub const GRAY700: &str = "\x1b[38;2;55;65;81m";
14+
pub const GRAY800: &str = "\x1b[38;2;31;41;55m";
15+
pub const GRAY900: &str = "\x1b[38;2;17;24;39m";
16+
17+
// Tailwind CSS Colors: Red
18+
pub const RED50: &str = "\x1b[38;2;254;242;242m";
19+
pub const RED100: &str = "\x1b[38;2;254;226;226m";
20+
pub const RED200: &str = "\x1b[38;2;254;202;202m";
21+
pub const RED300: &str = "\x1b[38;2;252;165;165m";
22+
pub const RED400: &str = "\x1b[38;2;248;113;113m";
23+
pub const RED500: &str = "\x1b[38;2;239;68;68m";
24+
pub const RED600: &str = "\x1b[38;2;220;38;38m";
25+
pub const RED700: &str = "\x1b[38;2;185;28;28m";
26+
pub const RED800: &str = "\x1b[38;2;153;27;27m";
27+
pub const RED900: &str = "\x1b[38;2;127;29;29m";
28+
29+
// Tailwind CSS Colors: Yellow
30+
pub const YELLOW50: &str = "\x1b[38;2;255;251;235m";
31+
pub const YELLOW100: &str = "\x1b[38;2;254;243;199m";
32+
pub const YELLOW200: &str = "\x1b[38;2;253;230;138m";
33+
pub const YELLOW300: &str = "\x1b[38;2;252;211;77m";
34+
pub const YELLOW400: &str = "\x1b[38;2;251;191;36m";
35+
pub const YELLOW500: &str = "\x1b[38;2;245;158;11m";
36+
pub const YELLOW600: &str = "\x1b[38;2;217;119;6m";
37+
pub const YELLOW700: &str = "\x1b[38;2;180;83;9m";
38+
pub const YELLOW800: &str = "\x1b[38;2;146;64;14m";
39+
pub const YELLOW900: &str = "\x1b[38;2;120;53;15m";
40+
41+
// Tailwind CSS Colors: Green
42+
pub const GREEN50: &str = "\x1b[38;2;240;253;244m";
43+
pub const GREEN100: &str = "\x1b[38;2;220;252;231m";
44+
pub const GREEN200: &str = "\x1b[38;2;187;247;208m";
45+
pub const GREEN300: &str = "\x1b[38;2;134;239;172m";
46+
pub const GREEN400: &str = "\x1b[38;2;74;222;128m";
47+
pub const GREEN500: &str = "\x1b[38;2;34;197;94m";
48+
pub const GREEN600: &str = "\x1b[38;2;22;163;74m";
49+
pub const GREEN700: &str = "\x1b[38;2;21;128;61m";
50+
pub const GREEN800: &str = "\x1b[38;2;22;101;52m";
51+
pub const GREEN900: &str = "\x1b[38;2;20;83;45m";
52+
53+
// Tailwind CSS Colors: Blue
54+
pub const BLUE50: &str = "\x1b[38;2;239;246;255m";
55+
pub const BLUE100: &str = "\x1b[38;2;219;234;254m";
56+
pub const BLUE200: &str = "\x1b[38;2;191;219;254m";
57+
pub const BLUE300: &str = "\x1b[38;2;147;197;253m";
58+
pub const BLUE400: &str = "\x1b[38;2;96;165;250m";
59+
pub const BLUE500: &str = "\x1b[38;2;59;130;246m";
60+
pub const BLUE600: &str = "\x1b[38;2;37;99;235m";
61+
pub const BLUE700: &str = "\x1b[38;2;29;78;216m";
62+
pub const BLUE800: &str = "\x1b[38;2;30;64;175m";
63+
pub const BLUE900: &str = "\x1b[38;2;30;58;138m";
64+
65+
// Tailwind CSS Colors: Indigo
66+
pub const INDIGO50: &str = "\x1b[38;2;238;242;255m";
67+
pub const INDIGO100: &str = "\x1b[38;2;224;231;255m";
68+
pub const INDIGO200: &str = "\x1b[38;2;199;210;254m";
69+
pub const INDIGO300: &str = "\x1b[38;2;165;180;252m";
70+
pub const INDIGO400: &str = "\x1b[38;2;129;140;248m";
71+
pub const INDIGO500: &str = "\x1b[38;2;99;102;241m";
72+
pub const INDIGO600: &str = "\x1b[38;2;79;70;229m";
73+
pub const INDIGO700: &str = "\x1b[38;2;67;56;202m";
74+
pub const INDIGO800: &str = "\x1b[38;2;55;48;163m";
75+
pub const INDIGO900: &str = "\x1b[38;2;49;46;129m";
76+
77+
// Tailwind CSS Colors: Purple
78+
pub const PURPLE50: &str = "\x1b[38;2;250;245;255m";
79+
pub const PURPLE100: &str = "\x1b[38;2;243;232;255m";
80+
pub const PURPLE200: &str = "\x1b[38;2;233;213;255m";
81+
pub const PURPLE300: &str = "\x1b[38;2;216;180;254m";
82+
pub const PURPLE400: &str = "\x1b[38;2;192;132;252m";
83+
pub const PURPLE500: &str = "\x1b[38;2;168;85;247m";
84+
pub const PURPLE600: &str = "\x1b[38;2;147;51;234m";
85+
pub const PURPLE700: &str = "\x1b[38;2;126;34;206m";
86+
pub const PURPLE800: &str = "\x1b[38;2;107;33;168m";
87+
pub const PURPLE900: &str = "\x1b[38;2;88;28;135m";
88+
89+
90+
// Tailwind CSS Colors: Cyan
91+
pub const CYAN50: &str = "\x1b[38;2;236;254;255m";
92+
pub const CYAN100: &str = "\x1b[38;2;207;250;254m";
93+
pub const CYAN200: &str = "\x1b[38;2;165;243;252m";
94+
pub const CYAN300: &str = "\x1b[38;2;103;232;249m";
95+
pub const CYAN400: &str = "\x1b[38;2;34;211;238m";
96+
pub const CYAN500: &str = "\x1b[38;2;6;182;212m";
97+
pub const CYAN600: &str = "\x1b[38;2;8;145;178m";
98+
pub const CYAN700: &str = "\x1b[38;2;14;116;144m";
99+
pub const CYAN800: &str = "\x1b[38;2;21;94;117m";
100+
pub const CYAN900: &str = "\x1b[38;2;22;78;99m";
101+
102+
// Tailwind CSS Colors: Teal
103+
pub const TEAL50: &str = "\x1b[38;2;240;253;250m";
104+
pub const TEAL100: &str = "\x1b[38;2;204;251;241m";
105+
pub const TEAL200: &str = "\x1b[38;2;153;246;228m";
106+
pub const TEAL300: &str = "\x1b[38;2;94;234;212m";
107+
pub const TEAL400: &str = "\x1b[38;2;45;212;191m";
108+
pub const TEAL500: &str = "\x1b[38;2;20;184;166m";
109+
pub const TEAL600: &str = "\x1b[38;2;13;148;136m";
110+
pub const TEAL700: &str = "\x1b[38;2;15;118;110m";
111+
pub const TEAL800: &str = "\x1b[38;2;17;94;89m";
112+
pub const TEAL900: &str = "\x1b[38;2;19;78;74m";
113+
114+
// Tailwind CSS Colors: Emerald
115+
pub const EMERALD50: &str = "\x1b[38;2;236;253;245m";
116+
pub const EMERALD100: &str = "\x1b[38;2;209;250;229m";
117+
pub const EMERALD200: &str = "\x1b[38;2;167;243;208m";
118+
pub const EMERALD300: &str = "\x1b[38;2;110;231;183m";
119+
pub const EMERALD400: &str = "\x1b[38;2;52;211;153m";
120+
pub const EMERALD500: &str = "\x1b[38;2;16;185;129m";
121+
pub const EMERALD600: &str = "\x1b[38;2;5;150;105m";
122+
pub const EMERALD700: &str = "\x1b[38;2;4;120;87m";
123+
pub const EMERALD800: &str = "\x1b[38;2;6;95;70m";
124+
pub const EMERALD900: &str = "\x1b[38;2;6;78;59m";
125+
126+
// Tailwind CSS Colors: Lime
127+
pub const LIME50: &str = "\x1b[38;2;247;254;231m";
128+
pub const LIME100: &str = "\x1b[38;2;236;252;203m";
129+
pub const LIME200: &str = "\x1b[38;2;217;249;157m";
130+
pub const LIME300: &str = "\x1b[38;2;190;242;100m";
131+
pub const LIME400: &str = "\x1b[38;2;163;230;53m";
132+
pub const LIME500: &str = "\x1b[38;2;132;204;22m";
133+
pub const LIME600: &str = "\x1b[38;2;101;163;13m";
134+
pub const LIME700: &str = "\x1b[38;2;77;124;15m";
135+
pub const LIME800: &str = "\x1b[38;2;63;98;18m";
136+
pub const LIME900: &str = "\x1b[38;2;54;83;20m";
137+
138+
// Tailwind CSS Colors: Amber
139+
pub const AMBER50: &str = "\x1b[38;2;255;251;235m";
140+
pub const AMBER100: &str = "\x1b[38;2;254;243;199m";
141+
pub const AMBER200: &str = "\x1b[38;2;253;230;138m";
142+
pub const AMBER300: &str = "\x1b[38;2;252;211;77m";
143+
pub const AMBER400: &str = "\x1b[38;2;251;191;36m";
144+
pub const AMBER500: &str = "\x1b[38;2;245;158;11m";
145+
pub const AMBER600: &str = "\x1b[38;2;217;119;6m";
146+
pub const AMBER700: &str = "\x1b[38;2;180;83;9m";
147+
pub const AMBER800: &str = "\x1b[38;2;146;64;14m";
148+
pub const AMBER900: &str = "\x1b[38;2;120;53;15m";
149+
150+
// Tailwind CSS Colors: Fuchsia
151+
pub const FUCHSIA50: &str = "\x1b[38;2;253;244;255m";
152+
pub const FUCHSIA100: &str = "\x1b[38;2;250;232;255m";
153+
pub const FUCHSIA200: &str = "\x1b[38;2;245;208;254m";
154+
pub const FUCHSIA300: &str = "\x1b[38;2;240;171;252m";
155+
pub const FUCHSIA400: &str = "\x1b[38;2;232;121;249m";
156+
pub const FUCHSIA500: &str = "\x1b[38;2;217;70;239m";

Module03/data_vault/src/main.rs

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use std::collections::HashMap;
2+
pub mod colors;
3+
4+
// A structure to represent our key-value store
5+
struct SearchEngineKV {
6+
store: HashMap<String, Vec<String>>,
7+
}
8+
9+
impl SearchEngineKV {
10+
// Create a new empty store
11+
fn new() -> SearchEngineKV {
12+
SearchEngineKV {
13+
store: HashMap::new(),
14+
}
15+
}
16+
17+
// Insert a URL for a given keyword
18+
fn insert(&mut self, key: String, value: String) {
19+
self.store.entry(key).or_insert_with(Vec::new).push(value);
20+
}
21+
22+
// Retrieve URLs for a given keyword
23+
fn get(&self, key: &str) -> Option<&Vec<String>> {
24+
self.store.get(key)
25+
}
26+
27+
// Remove a URL from a keyword entry
28+
fn remove_url(&mut self, key: &str, url: &str) {
29+
if let Some(urls) = self.store.get_mut(key) {
30+
urls.retain(|u| u != url);
31+
if urls.is_empty() {
32+
self.store.remove(key);
33+
}
34+
}
35+
}
36+
}
37+
38+
fn main() {
39+
let mut engine = SearchEngineKV::new();
40+
41+
// Adding some sample data
42+
engine.insert("Cplusplus".to_string(), "https://cplusplus.com/".to_string());
43+
engine.insert("rust programming".to_string(), "https://doc.rust-lang.org".to_string());
44+
engine.insert("web development".to_string(), "https://developer.mozilla.org".to_string());
45+
46+
// Retrieving data
47+
if let Some(urls) = engine.get("rust programming") {
48+
println!("URLs for 'rust programming': {:?}", urls);
49+
}
50+
51+
// Removing a URL
52+
engine.remove_url("web development", "https://developer.mozilla.org");
53+
54+
// Check if URL was removed // fix the line below
55+
if let Some(urls) = engine.get("web development") {
56+
println!("URLs for 'web development' after removal: {:?}", urls);
57+
} else {
58+
println!("No URLs found for 'web development' after removal");
59+
}
60+
61+
}

Module03/data_vault_ex/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "data_vault_ex"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
4.68 MB
Binary file not shown.

Module03/data_vault_ex/src/main.rs

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
use std::collections::HashMap;
2+
use std::sync::{Arc, RwLock};
3+
4+
// Define a result type for our operations
5+
type Result<T> = std::result::Result<T, String>;
6+
7+
pub struct KeyValueStore {
8+
store: Arc<RwLock<HashMap<String, String>>>,
9+
}
10+
11+
impl KeyValueStore {
12+
// Initialize a new KeyValueStore
13+
pub fn new() -> Self {
14+
KeyValueStore {
15+
store: Arc::new(RwLock::new(HashMap::new())),
16+
}
17+
}
18+
19+
// Insert a key-value pair
20+
pub fn insert(&self, key: String, value: String) -> Result<()> {
21+
match self.store.write() {
22+
Ok(mut guard) => {
23+
guard.insert(key, value);
24+
Ok(())
25+
},
26+
Err(e) => Err(format!("Failed to acquire write lock: {}", e)),
27+
}
28+
}
29+
30+
// Retrieve a value given a key
31+
pub fn get(&self, key: &str) -> Result<Option<String>> {
32+
match self.store.read() {
33+
Ok(guard) => Ok(guard.get(key).cloned()),
34+
Err(e) => Err(format!("Failed to acquire read lock: {}", e)),
35+
}
36+
}
37+
38+
// Remove a key-value pair
39+
pub fn remove(&self, key: &str) -> Result<Option<String>> {
40+
match self.store.write() {
41+
Ok(mut guard) => Ok(guard.remove(key)),
42+
Err(e) => Err(format!("Failed to acquire write lock: {}", e)),
43+
}
44+
}
45+
46+
// Example usage might include checking if a key exists
47+
pub fn contains(&self, key: &str) -> Result<bool> {
48+
self.get(key).map(|v| v.is_some())
49+
}
50+
}
51+
52+
// adding a main function to test the above key value store
53+
54+
fn main() {
55+
// Initialize the key-value store
56+
let store = KeyValueStore::new();
57+
58+
// Insert some key-value pairs
59+
match store.insert("key1".to_string(), "value1".to_string()) {
60+
Ok(_) => println!("Inserted key1 -> value1"),
61+
Err(e) => println!("Error inserting key1: {}", e),
62+
}
63+
64+
match store.insert("key2".to_string(), "value2".to_string()) {
65+
Ok(_) => println!("Inserted key2 -> value2"),
66+
Err(e) => println!("Error inserting key2: {}", e),
67+
}
68+
69+
// Retrieve a value
70+
match store.get("key1") {
71+
Ok(Some(value)) => println!("Retrieved key1 -> {}", value),
72+
Ok(None) => println!("key1 not found"),
73+
Err(e) => println!("Error retrieving key1: {}", e),
74+
}
75+
76+
// Check if a key exists
77+
match store.contains("key2") {
78+
Ok(true) => println!("key2 exists"),
79+
Ok(false) => println!("key2 does not exist"),
80+
Err(e) => println!("Error checking key2: {}", e),
81+
}
82+
83+
// Remove a key-value pair
84+
match store.remove("key1") {
85+
Ok(Some(value)) => println!("Removed key1 -> {}", value),
86+
Ok(None) => println!("key1 not found"),
87+
Err(e) => println!("Error removing key1: {}", e),
88+
}
89+
90+
// Try to retrieve the removed key
91+
match store.get("key1") {
92+
Ok(Some(value)) => println!("Retrieved key1 -> {}", value),
93+
Ok(None) => println!("key1 not found"),
94+
Err(e) => println!("Error retrieving key1: {}", e),
95+
}
96+
}
97+
98+
// Explanation of design choices:
99+
// - `Arc` (Atomic Reference Counting) with `RwLock` allows for shared ownership with safe concurrent access.
100+
// - Using `String` for both key and value for simplicity, but this could be generic in a real-world scenario.
101+
// - Error handling with `Result` allows for clear propagation of errors to the caller.

Module03/data_vault_exx/Cargo.toml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "data_vault_exx"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
argon2 = "0.5.3"
8+
rand = "0.8.5"
9+
serde = { version = "1.0.209", features = ["derive"] }
10+
serde_json = "1.0.127"
11+
thiserror = "1.0.63"
12+

Module03/zip_cracker/src/reader.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pub mod reader {
2+
use std::fs::File;
3+
use std::io::Read;
4+
use zip::ZipArchive;
5+
6+
pub fn read_zip(filename: &str) -> Result<ZipArchive<std::fs::File>, zip::result::ZipError> {
7+
let file = File::open(filename)?;
8+
let archive = ZipArchive::new(file)?;
9+
Ok(archive)
10+
}
11+
}

Module05/cachecomponent/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "cachecomponent"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]

Module05/cachecomponent/Readme.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
The `GetCache` trait and its implementations for `InMemoryCache` and ``Cache`` structs provide a flexible and modular caching system.
2+
3+
Here are some scenarios where such reusable modular components can be useful:
4+
5+
### 1. Web Applications
6+
In web development, caching is often used to improve performance by reducing the number of database queries or computationally expensive operations. Your caching system can be used in web frameworks like Rocket or actix-web to cache frequently accessed data, such as user sessions, configuration data, or intermediate computation results.
7+
8+
### 2. Distributed Systems
9+
In distributed systems, caching can help reduce the load on shared resources and improve overall system performance. Your caching system can be used in distributed systems built with frameworks like Tokio or async-std to cache data that's frequently accessed across multiple nodes.
10+
11+
### 3. Machine Learning and Data Science
12+
In machine learning and data science applications, caching can be used to store intermediate results of computationally expensive operations, such as data preprocessing or model training. Your caching system can be used in Rust libraries like rusty-machine or rusty-nn to cache intermediate results and improve performance.
13+
14+
### 4. Embedded Systems
15+
In embedded systems, caching can be used to improve performance and reduce memory usage. Your caching system can be used in embedded systems built with Rust to cache frequently accessed data, such as sensor readings or configuration data.
16+
17+
### 5. Game Development
18+
In game development, caching can be used to improve performance by reducing the number of computations required for game logic or physics simulations. Your caching system can be used in game engines like Piston or ggez to cache intermediate results and improve performance.

0 commit comments

Comments
 (0)