rusty-diceware

Commandline diceware, with or without dice, written in Rustlang.
git clone https://kaka.farm/~git/rusty-diceware
Log | Files | Refs | README | LICENSE

lib.rs (1303B)


      1 use std::str::FromStr;
      2 
      3 include!(concat!(env!("OUT_DIR"), "/diceware.rs"));
      4 
      5 #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
      6 #[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
      7 #[derive(Clone)]
      8 pub enum Wordlist {
      9     Beale,
     10     Reinhold,
     11     Minilock,
     12     EffLong,
     13     EffShort1,
     14     EffShort2,
     15 }
     16 
     17 impl Wordlist {
     18     pub fn get_list(&self) -> &'static [&'static str] {
     19         match self {
     20             Self::Beale => &BEALE_WORDLIST,
     21             Self::Reinhold => &REINHOLD_WORDLIST,
     22             Self::Minilock => &MINILOCK_WORDLIST,
     23             Self::EffLong => &EFF_LONG_WORDLIST,
     24             Self::EffShort1 => &EFF_SHORT_WORDLIST_1,
     25             Self::EffShort2 => &EFF_SHORT_WORDLIST_2_0,
     26         }
     27     }
     28 }
     29 
     30 impl FromStr for Wordlist {
     31     type Err = &'static str;
     32 
     33     fn from_str(s: &str) -> Result<Self, Self::Err> {
     34         match s {
     35             "efflong" => Ok(Self::EffLong),
     36             "reinhold" => Ok(Self::Reinhold),
     37             "beale" => Ok(Self::Beale),
     38             "minilock" => Ok(Self::Minilock),
     39             "effshort1" => Ok(Self::EffShort1),
     40             "effshort2" => Ok(Self::EffShort2),
     41             _ => Err("Unknown Wordlist"),
     42         }
     43     }
     44 }
     45 
     46 impl Default for Wordlist {
     47     fn default() -> Self {
     48         Self::EffLong
     49     }
     50 }