rusty-diceware

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 97cdc080d7c61d257688d2b58b4c15833ccd3aad
parent 83fdf5c92b8bbca9ffa10999687e7e97fe140f0d
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Sun, 14 Jun 2015 14:31:22 +0300

Moved the diceware logic out into diceware.rs

Diffstat:
Asrc/diceware.rs | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/main.rs | 75+++------------------------------------------------------------------------
2 files changed, 71 insertions(+), 72 deletions(-)

diff --git a/src/diceware.rs b/src/diceware.rs @@ -0,0 +1,68 @@ +extern crate rand; + +use std::fmt; + +include!(concat!(env!("OUT_DIR"), "/diceware.rs")); + +#[derive(Debug,Clone,Eq,PartialEq)] +pub struct BealeWord(&'static str); + +#[derive(Debug,Clone,Eq,PartialEq)] +pub struct ReinholdWord(&'static str); + +#[derive(Debug,Clone,Eq,PartialEq)] +pub struct MiniLockWord(&'static str); + +impl BealeWord { + pub fn new(word: &'static str) -> BealeWord { + BealeWord(word.clone()) + } +} + +impl ReinholdWord { + pub fn new(word: &'static str) -> ReinholdWord { + ReinholdWord(word.clone()) + } +} + +impl rand::Rand for BealeWord { + fn rand<R: rand::Rng>(rng: &mut R) -> BealeWord { + rng.choose(&BEALE_WORDLIST).unwrap().clone() + } +} + +impl fmt::Display for BealeWord { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + &BealeWord(w) => write!(f, "{}", w) + } + } +} + +impl rand::Rand for ReinholdWord { + fn rand<R: rand::Rng>(rng: &mut R) -> ReinholdWord { + rng.choose(&REINHOLD_WORDLIST).unwrap().clone() + } +} + +impl fmt::Display for ReinholdWord { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + &ReinholdWord(w) => write!(f, "{}", w) + } + } +} + +impl rand::Rand for MiniLockWord { + fn rand<R: rand::Rng>(rng: &mut R) -> MiniLockWord { + rng.choose(&MINILOCK_WORDLIST).unwrap().clone() + } +} + +impl fmt::Display for MiniLockWord { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + &MiniLockWord(w) => write!(f, "{}", w) + } + } +} diff --git a/src/main.rs b/src/main.rs @@ -1,7 +1,8 @@ +mod diceware; + extern crate rand; extern crate getopts; - //use std::env; //use std::io::Read; // use std::fs::File; @@ -9,77 +10,7 @@ extern crate getopts; // use getopts::Options; use rand::Rng; -mod diceware { - extern crate rand; - - use std::fmt; - - include!(concat!(env!("OUT_DIR"), "/diceware.rs")); - - #[derive(Debug,Clone,Eq,PartialEq)] - pub struct BealeWord(&'static str); - - #[derive(Debug,Clone,Eq,PartialEq)] - pub struct ReinholdWord(&'static str); - - #[derive(Debug,Clone,Eq,PartialEq)] - pub struct MiniLockWord(&'static str); - - impl BealeWord { - pub fn new(word: &'static str) -> BealeWord { - BealeWord(word.clone()) - } - } - - impl ReinholdWord { - pub fn new(word: &'static str) -> ReinholdWord { - ReinholdWord(word.clone()) - } - } - - impl rand::Rand for BealeWord { - fn rand<R: rand::Rng>(rng: &mut R) -> BealeWord { - rng.choose(&BEALE_WORDLIST).unwrap().clone() - } - } - - impl fmt::Display for BealeWord { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - &BealeWord(w) => write!(f, "{}", w) - } - } - } - - impl rand::Rand for ReinholdWord { - fn rand<R: rand::Rng>(rng: &mut R) -> ReinholdWord { - rng.choose(&REINHOLD_WORDLIST).unwrap().clone() - } - } - - impl fmt::Display for ReinholdWord { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - &ReinholdWord(w) => write!(f, "{}", w) - } - } - } - - impl rand::Rand for MiniLockWord { - fn rand<R: rand::Rng>(rng: &mut R) -> MiniLockWord { - rng.choose(&MINILOCK_WORDLIST).unwrap().clone() - } - } - - impl fmt::Display for MiniLockWord { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - &MiniLockWord(w) => write!(f, "{}", w) - } - } - } -} - +use diceware::{BealeWord, ReinholdWord, MiniLockWord}; /* fn make_options() -> Options { let mut opts = Options::new();