initial commit

main
_ 2024-10-01 23:20:35 +00:00
commit 27a6c614d5
8 changed files with 1467 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

140
Cargo.lock generated Normal file
View File

@ -0,0 +1,140 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "division_of_one"
version = "0.1.0"
dependencies = [
"rand",
]
[[package]]
name = "getrandom"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "libc"
version = "0.2.159"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5"
[[package]]
name = "ppv-lite86"
version = "0.2.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
dependencies = [
"zerocopy",
]
[[package]]
name = "proc-macro2"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "syn"
version = "2.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "zerocopy"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
dependencies = [
"byteorder",
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]

16
Cargo.toml Normal file
View File

@ -0,0 +1,16 @@
[package]
authors = ["ReactorScram"]
description = "A diceware passphrase generator"
edition = "2021"
license = "AGPL-3.0"
name = "division_of_one"
repository = "https://six-five-six-four.com/git/reactor/division_of_one"
version = "0.1.0"
[dependencies]
rand = "0.8.5"
[profile.release]
codegen-units = 1
lto = "fat"
strip = true

11
README.md Normal file
View File

@ -0,0 +1,11 @@
`division_of_one`
A diceware passphrase generator, e.g. `correct horse battery staple`
# Why this and not another generator?
It's easier to write 40 lines of Rust than to audit it.
# What if 8 words is too long?
Ignore some of the words :)

2
rust-toolchain.toml Normal file
View File

@ -0,0 +1,2 @@
[toolchain]
channel = "1.81.0"

1253
src/eff_short_wordlist_1.txt Normal file

File diff suppressed because it is too large Load Diff

41
src/lib.rs Normal file
View File

@ -0,0 +1,41 @@
use rand::seq::SliceRandom as _;
pub fn main() {
let passphrase = create_passphrase(" ", 8);
println!("{passphrase}");
println!("Press Enter");
let mut input = String::new();
std::io::stdin().read_line(&mut input).ok();
}
pub fn create_passphrase(separator: &str, len: usize) -> String {
let dice = Dice::default();
let words: Vec<_> = (0..len).map(|_| dice.pick_word()).collect();
words.join(separator)
}
pub struct Dice {
words: Vec<String>,
}
impl Default for Dice {
fn default() -> Self {
let wordlist = include_str!("eff_short_wordlist_1.txt");
let words: Vec<_> = wordlist.split('\n').map(|s| s.to_string()).collect();
assert_eq!(words.len(), 1253);
assert_eq!(words[0], "acid");
assert_eq!(words[600], "large");
assert_eq!(words[1252], "zoom");
Self {
words,
}
}
}
impl Dice {
pub fn pick_word(&self) -> &str {
self.words.choose(&mut rand::thread_rng ()).expect("`choose` should always return `Some`")
}
}

3
src/main.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
division_of_one::main()
}