aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgabrielgio <gabriel.giovanini@pm.me>2022-03-25 23:14:04 +0100
committergabrielgio <gabriel.giovanini@pm.me>2022-03-25 23:14:04 +0100
commitd6a9e6e46f2c2574ec0665e73b64f0d6c700557a (patch)
tree14acd8c4137b3c1ec8df58a2a517d1c88bf7c734 /src
parentb7c2d331b264605643fb2b11b1b75096558dbfdb (diff)
downloadgenpass-d6a9e6e46f2c2574ec0665e73b64f0d6c700557a.tar.gz
genpass-d6a9e6e46f2c2574ec0665e73b64f0d6c700557a.tar.bz2
genpass-d6a9e6e46f2c2574ec0665e73b64f0d6c700557a.zip
feat: Add extended ASCII
Add more chars...
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index e8999d4..a05a1ac 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -16,8 +16,8 @@ extern {
#[wasm_bindgen]
-pub fn generate(len: usize, lower: bool, upper: bool, number: bool, special: bool) -> String {
- if len == 0 ||!lower && !upper && !number && !special {
+pub fn generate(len: usize, lower: bool, upper: bool, number: bool, special: bool, extended: bool) -> String {
+ if len == 0 || !lower && !upper && !number && !special {
return "".to_string();
}
@@ -25,6 +25,8 @@ pub fn generate(len: usize, lower: bool, upper: bool, number: bool, special: boo
let mut lower_charset: Vec<char> = String::from("abcdefghijklmnopqrstuvwxyz").chars().collect();
let mut number_charset: Vec<char> = String::from("1234567890").chars().collect();
let mut special_charset: Vec<char> = String::from("!@#$%^&*()+{}[]><:|+=;-.,'?_~\\/`\"").chars().collect();
+ let mut extended_charset: Vec<char> = String::from("®û´¢æ«æëàñîêáö½¬èñý¹áúóâªò×ä¸ÿ¦ù°º±¨åûïøí»§÷î¤ã¡òþ¿³óùçâüëíõôéðìö¶þ¾úý·êéãߣüèðµå¥õïà¼øäô©²¯çì").chars().collect();
+
let mut result: Vec<char> = Vec::new();
let mut rng = rand::thread_rng();
@@ -45,6 +47,10 @@ pub fn generate(len: usize, lower: bool, upper: bool, number: bool, special: boo
result.append(&mut special_charset);
}
+ if extended {
+ result.append(&mut extended_charset);
+ }
+
(0..len)
.map(|_| {
let idx = rng.gen_range(0..result.len());