Compare commits

..

9 Commits

Author SHA1 Message Date
Maximilian
462c9326a0 Use string primitive to avoid a heap allocation 2024-11-03 19:41:48 -06:00
Maximilian
8edc65ff4b Update binaries to 1.0.1 2023-01-24 13:40:29 -06:00
Maximilian
cd39cf6a14 Strip symbols when building for release 2023-01-24 13:29:06 -06:00
Maximilian
06f120c050 Build windows binaries with GNU 2023-01-24 13:14:18 -06:00
Maximilian
b84acc83bc Add release profiles 2023-01-24 13:00:46 -06:00
Maximilian
949436dcff Switch version to 1.0.1, given the bug/performance fixes 2023-01-24 12:57:20 -06:00
Maximilian
04f1e48564 Switch from unwrap() to expect() 2023-01-24 12:31:26 -06:00
Maximilian
10411bbdcb Avoid creating a new string every time by using a HashSet for disallowed characters 2023-01-24 12:26:18 -06:00
Maximilian
f832fda590 Cryptographically generate the password 2023-01-24 12:19:53 -06:00
7 changed files with 27 additions and 7 deletions

14
.cargo/config.toml Normal file
View File

@ -0,0 +1,14 @@
[profile.release]
opt-level = "s"
[target.x86_64-pc-windows-gnu]
rustflags = ["-C", "target-cpu=native", "-C", "codegen-units=8", "-C", "debuginfo=0", "-C", "profile-generate", "-C", "inline-threshold=2000", "-C", "link-arg=-s"]
[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "target-cpu=native", "-C", "codegen-units=8", "-C", "debuginfo=0", "-C", "profile-generate", "-C", "inline-threshold=2000", "-C", "link-arg=-s"]
[target.i686-pc-windows-gnu]
rustflags = ["-C", "target-cpu=native", "-C", "codegen-units=4", "-C", "debuginfo=0", "-C", "profile-generate", "-C", "inline-threshold=2000", "-C", "link-arg=-s"]
[target.i686-unknown-linux-gnu]
rustflags = ["-C", "target-cpu=native", "-C", "codegen-units=4", "-C", "debuginfo=0", "-C", "profile-generate", "-C", "inline-threshold=2000", "-C", "link-arg=-s"]

View File

@ -1,6 +1,6 @@
[package] [package]
name = "rust_pass" name = "rust_pass"
version = "1.0.0" version = "1.0.1"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,8 @@
use std::collections::HashSet;
use std::env; use std::env;
use rand::RngCore;
fn main() { fn main() {
// Take in two command line arguments, one i32 and one optional String // Take in two command line arguments, one i32 and one optional String
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
@ -18,15 +21,17 @@ fn main() {
// Disallowed_chars is an optional argument // Disallowed_chars is an optional argument
let disallowed_chars: Option<&String> = args.get(2); let disallowed_chars: Option<&String> = args.get(2);
let mut allowed_chars: String = String::from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=`~!@#$%^&*()_+[]\\{}|;':,./<>?"); let allowed_chars: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=`~!@#$%^&*()_+[]\\{}|;':,./<>?";
let mut allowed_chars_set: HashSet<char> = allowed_chars.chars().collect();
// Remove disallowed characters from allowed_characters if disallowed_chars is specified // Remove disallowed characters from allowed_characters if disallowed_chars is specified
if let Some(disallowed_chars) = disallowed_chars { if let Some(disallowed_chars) = disallowed_chars {
for disallowed_char in disallowed_chars.chars() { for disallowed_char in disallowed_chars.chars() {
allowed_chars = allowed_chars.replace(disallowed_char, ""); allowed_chars_set.remove(&disallowed_char);
} }
if allowed_chars.len() == 0 { // Make sure there are still characters left to use if allowed_chars_set.len() == 0 { // Make sure there are still characters left to use
println!("Error: You have disallowed all characters"); println!("Error: You have disallowed all characters");
println!("The allowed character set includes: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=`~!@#$%^&*()_+[]\\{{}}|;':,./<>?"); println!("The allowed character set includes: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=`~!@#$%^&*()_+[]\\{{}}|;':,./<>?");
return; return;
@ -34,13 +39,14 @@ fn main() {
} }
if let Some(new_password_length) = new_password_length { // Unwrap Option in i32 if let Some(new_password_length) = new_password_length { // Unwrap Option in i32
let mut rng = rand::thread_rng();
// Generate a random string of length n // Generate a random string of length n
let mut new_password = String::new(); let mut new_password = String::new();
for _ in 0..new_password_length { for _ in 0..new_password_length {
new_password.push( new_password.push(
allowed_chars.chars() *allowed_chars_set.iter()
.nth(rand::random::<usize>() % allowed_chars.len()) .nth(rng.next_u32() as usize % allowed_chars_set.len())
.unwrap() .expect("Error: Invalid index")
); );
} }