From 93cddf69d2f2648fe6e8c00e5c7df51ef79b16de Mon Sep 17 00:00:00 2001 From: Michaël Ball Date: Sun, 18 Nov 2018 12:04:33 +0000 Subject: Formatting improvements from cargo fmt --- src/main.rs | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/src/main.rs b/src/main.rs index c78441e..c8a1e01 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,17 +4,19 @@ extern crate rand; use getopts::Options; use rand::{thread_rng, Rng}; use std::env; -use std::vec::Vec; use std::fs::File; use std::io::{self, BufRead, BufReader}; use std::path::Path; +use std::vec::Vec; fn lines_from_file

(filename: &P) -> Result, io::Error> - where P: AsRef +where + P: AsRef, { let file = try!(File::open(filename)); let buf = BufReader::new(file); - Ok(buf.lines() + Ok(buf + .lines() .map(|l| l.expect("Could not parse line")) .collect()) } @@ -40,11 +42,13 @@ fn random_words_from_dictionary(dictionary: &Vec, words: &usize) -> Vec< #[test] fn test_random_words_from_dictionary() { - let test_dict = vec!["This".to_string(), - "is".to_string(), - "a".to_string(), - "test".to_string(), - "vector".to_string()]; + let test_dict = vec![ + "This".to_string(), + "is".to_string(), + "a".to_string(), + "test".to_string(), + "vector".to_string(), + ]; let num_words = 3; let new_vec = random_words_from_dictionary(&test_dict, &num_words); @@ -56,10 +60,12 @@ fn main() { let program = args[0].clone(); let mut opts = Options::new(); - opts.optopt("w", - "", - "number of words to use in passphrase, default is 4", - "WORDS"); + opts.optopt( + "w", + "", + "number of words to use in passphrase, default is 4", + "WORDS", + ); let matches = match opts.parse(&args[1..]) { Ok(m) => m, @@ -77,15 +83,13 @@ fn main() { let num_words; match words_opt { - Some(x) => { - match x.parse::() { - Ok(n) => num_words = n, - Err(_e) => { - println!("Please enter an integer for the -w flag"); - return; - } + Some(x) => match x.parse::() { + Ok(n) => num_words = n, + Err(_e) => { + println!("Please enter an integer for the -w flag"); + return; } - } + }, None => num_words = 4, } @@ -94,9 +98,11 @@ fn main() { match lines_from_file(&input) { Ok(n) => lines = n, Err(_e) => { - println!("Cannot read file {}. Please ensure it exists and you have permission to \ - read it.", - input); + println!( + "Cannot read file {}. Please ensure it exists and you have permission to \ + read it.", + input + ); return; } } -- cgit v1.2.3 From 40df2f617ef9a29c89ebadb571f39f230be23581 Mon Sep 17 00:00:00 2001 From: Michaël Ball Date: Sun, 18 Nov 2018 12:14:26 +0000 Subject: Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..43e5801 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Michaël Ball + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. -- cgit v1.2.3 From c7e59c4143077b9e15e3d6dc3fe1a3523cd0eebb Mon Sep 17 00:00:00 2001 From: Michaël Ball Date: Sun, 18 Nov 2018 12:16:55 +0000 Subject: Create README.md --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..5bf31bd --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# rust-passphrasegen +A passphrase generator written in Rust. + +## Usage +Build by running `cargo build --release`. + +Generate a passphrase by running `passphrasegen`. + +Required arguments: +* Path to words file (eg. /usr/share/dict/words) + +### Example + +Generate a passphrase of 5 words using the american english wordlist: + + $ passphrasegen -w 5 /usr/share/dict/american-english -- cgit v1.2.3