Trait ferropassgen::PassGen

source ·
pub trait PassGen<T> {
    // Required methods
    fn new(
        length: usize,
        tokenset: Vec<T>,
        separator: Option<char>,
        word_case: Option<bool>
    ) -> Result<Self, PassGenError>
       where Self: Sized;
    fn generate(&self) -> String;
}
Expand description

Trait for password generators.

This trait defines the common functionality for password generators.

§Type Parameters

  • T: The type of the token set elements.

Required Methods§

source

fn new( length: usize, tokenset: Vec<T>, separator: Option<char>, word_case: Option<bool> ) -> Result<Self, PassGenError>
where Self: Sized,

Creates a new instance of the password generator.

§Arguments
  • length: The desired length of the generated password.
  • tokenset: The set of tokens to choose from when generating the password.
  • separator: An optional separator character for joining tokens (only applicable to passphrases).
  • word_case: An optional boolean indicating whether to use uppercase words (only applicable to passphrases).
§Errors

Returns a PassGenError if the provided length is 0 or the token set is empty.

§Examples
use ferropassgen::{PassGen, PasswordGen};

let length = 8;
let tokenset = vec!['a', 'b', 'c', 'd', 'e'];
let password_gen = PasswordGen::new(length, tokenset, None, None).unwrap();
source

fn generate(&self) -> String

Generates a password using the password generator.

§Examples
use ferropassgen::{PassGen, PasswordGen};

let length = 8;
let tokenset = vec!['a', 'b', 'c', 'd', 'e'];
let password_gen = PasswordGen::new(length, tokenset, None, None).unwrap();
let password = password_gen.generate();
assert_eq!(password.len(), 8);

Implementors§

source§

impl PassGen<char> for PasswordGen

source§

impl PassGen<String> for PassphraseGen

Creates a new instance of the passphrase generator.

§Arguments

  • length: The desired length of the generated passphrase.
  • tokenset: The set of words to choose from when generating the passphrase.
  • separator: An optional separator character for joining the words in the passphrase.
  • word_case: An optional boolean indicating whether to use uppercase words in the passphrase.

§Errors

Returns a PassGenError if the provided length is 0 or the token set is empty.

§Examples

use ferropassgen::{PassGen, PassphraseGen};

let length = 4;
let tokenset = vec!["apple".to_string(), "banana".to_string(), "cherry".to_string()];
let passphrase_gen = PassphraseGen::new(length, tokenset, Some('-'), Some(false)).unwrap();