Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds option for user to use their own, "custom" word list #14

Merged
merged 14 commits into from
Oct 27, 2023
Merged

Conversation

sts10
Copy link
Owner

@sts10 sts10 commented Oct 26, 2023

Addresses #9.

Also implements a (case-sensitive) check for duplicates, plus a check for non-uniform Unicode Normalization, on the user-provided lists, hopefully removing some footguns.

I got generate_passphrase to take both &' static [&str] when using a built-in list and Vec<String> when handling a user-provided list, thanks to some Ugly Rust trickery:

pub fn generate_passphrase<T: AsRef<str> + std::fmt::Display>(
    number_of_words_to_put_in_passphrase: usize,
    separator: &str,
    title_case: bool,
    list: &[T],
) -> String {
    // ...
}

What I'd like to improve in this PR

The bummer with this PR as it stands is how ugly src/main.rs is now.

    // I'd like to have this be one variable (one `let`), but I can't figure out what to type to
    // make it?
    let custom_list = opt
        .custom_list_file_path
        .map(|custom_list_file_path| read_in_custom_list(&custom_list_file_path));
    let built_in_list = fetch_list(opt.list_choice);

    // Since I can't have just one list variable yet,
    // I need to do this to get the legnth of the list
    let list_length = match custom_list {
        Some(ref custom_list) => custom_list.len(),
        None => built_in_list.len(),
    };

and later

 // Generate and print passphrase
        // Again, we have more code than we should because of this pesky list type situation...
        let passphrase = match custom_list {
            Some(ref custom_list) => generate_passphrase(
                number_of_words_to_put_in_passphrase,
                &opt.separator,
                opt.title_case,
                custom_list,
            ),
            None => generate_passphrase(
                number_of_words_to_put_in_passphrase,
                &opt.separator,
                opt.title_case,
                built_in_list,
            ),
        };
        println!("{}", passphrase);

I'd love to have one type List that can handle both &' static [&str] when using a built-in list and Vec<String> when handling a user-provided list.

I'm guessing I'll need to implement a trait of some kind? I'm trying to sketch out the problem in a Rust playground, but it's hard going for me!

@sts10
Copy link
Owner Author

sts10 commented Oct 27, 2023

Should we merge this, adding code complexity but also the ability for users to use their own word list?

Pros (of merging)

  • Allows non-English speakers a way to use Phraze
  • Makes Phraze more robust and impressive, thus perhaps attracting more users and more contributors, etc.?

Cons

  • Adds to code complexity
  • Adds new dependencies

Note: Pgen doesn't accept custom word lists, but passphraseme does.

@sts10 sts10 merged commit f042f0f into main Oct 27, 2023
@sts10 sts10 deleted the custom branch October 27, 2023 23:06
@sts10 sts10 mentioned this pull request Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant