Compare commits

..

No commits in common. "main" and "v0.1.2" have entirely different histories.
main ... v0.1.2

5 changed files with 27 additions and 160 deletions

134
Cargo.lock generated
View File

@ -1,12 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "bitflags"
version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36"
version = 3
[[package]]
name = "byteorder"
@ -22,21 +16,20 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "division_of_one"
version = "0.1.3"
version = "0.1.2"
dependencies = [
"rand",
]
[[package]]
name = "getrandom"
version = "0.3.1"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"libc",
"wasi",
"windows-targets",
]
[[package]]
@ -51,7 +44,7 @@ version = "0.2.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
dependencies = [
"zerocopy 0.7.35",
"zerocopy",
]
[[package]]
@ -74,20 +67,20 @@ dependencies = [
[[package]]
name = "rand"
version = "0.9.0"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
"zerocopy 0.8.18",
]
[[package]]
name = "rand_chacha"
version = "0.9.0"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
@ -95,12 +88,11 @@ dependencies = [
[[package]]
name = "rand_core"
version = "0.9.1"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a88e0da7a2c97baa202165137c158d0a2e824ac465d13d81046727b34cb247d3"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
"zerocopy 0.8.18",
]
[[package]]
@ -122,85 +114,9 @@ checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
[[package]]
name = "wasi"
version = "0.13.3+wasi-0.2.2"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26816d2e1a4a36a2940b96c5296ce403917633dff8f3440e9b236ed6f6bacad2"
dependencies = [
"wit-bindgen-rt",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "wit-bindgen-rt"
version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3268f3d866458b787f390cf61f4bbb563b922d091359f9608842999eaee3943c"
dependencies = [
"bitflags",
]
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "zerocopy"
@ -209,16 +125,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
dependencies = [
"byteorder",
"zerocopy-derive 0.7.35",
]
[[package]]
name = "zerocopy"
version = "0.8.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79386d31a42a4996e3336b0919ddb90f81112af416270cff95b5f5af22b839c2"
dependencies = [
"zerocopy-derive 0.8.18",
"zerocopy-derive",
]
[[package]]
@ -231,14 +138,3 @@ dependencies = [
"quote",
"syn",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76331675d372f91bf8d17e13afbd5fe639200b73d01f0fc748bb059f9cca2db7"
dependencies = [
"proc-macro2",
"quote",
"syn",
]

View File

@ -7,10 +7,10 @@ keywords = ["passphrase", "password"]
license = "AGPL-3.0"
name = "division_of_one"
repository = "https://six-five-six-four.com/git/reactor/division_of_one"
version = "0.1.3"
version = "0.1.2"
[dependencies]
rand = "0.9.0"
rand = "0.8.5"
[profile.release]
codegen-units = 1

View File

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

View File

@ -1,44 +1,15 @@
use rand::{seq::IndexedRandom as _, Rng as _};
pub fn main() -> Result<(), String> {
let mut args = std::env::args();
let _ = args.next();
match args.next().as_deref() {
None => {}
Some("--version") => {
println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
return Ok(());
}
Some(_) => return Err("Unknown CLI arg".to_string()),
}
println!("{}", create_passphrase(" ", 8));
println!("{}", create_pin(9));
println!("{}", create_base32(8));
use rand::{seq::SliceRandom as _, Rng as _};
pub fn main() {
let passphrase = create_passphrase(" ", 8);
println!("{passphrase}");
let pin = create_pin(8);
println!("{pin}");
println!("Press Enter");
let mut input = String::new();
std::io::stdin().read_line(&mut input).ok();
Ok(())
}
/// Generates a Base32 string per RFC 4648, Section 6.
///
/// Wikipedia says this is the most popular encoding, and it's what
/// `base32` in GNU coreutils uses.
/// <https://en.wikipedia.org/wiki/Base32#Base_32_Encoding_per_%C2%A76>
///
/// This is useful for short IDs, e.g. bugs that aren't living in an issue
/// tracker. 8 characters of Base32 is 40 bits of entropy, which is
/// not enough for a password
pub fn create_base32(len: usize) -> String {
let encoding: Vec<_> = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567".chars().collect();
assert_eq!(encoding.len(), 32);
let chars = (0..len).map(|_| *encoding.choose(&mut rand::rng()).unwrap());
String::from_iter(chars)
}
/// Generates a diceware passphrase
pub fn create_passphrase(separator: &str, len: usize) -> String {
let dice = Dice::default();
let words: Vec<_> = (0..len).map(|_| dice.pick_word()).collect();
@ -50,7 +21,7 @@ pub fn create_passphrase(separator: &str, len: usize) -> String {
/// PINs are returned as a String because you do not do math with PINs, therefore they are not numbers.
pub fn create_pin(len: usize) -> String {
let digits: Vec<_> = (0..len)
.map(|_| format!("{}", rand::rng().random_range(0..=9)))
.map(|_| format!("{}", rand::thread_rng().gen_range(0..=9)))
.collect();
digits.join("")
}
@ -76,7 +47,7 @@ impl Default for Dice {
impl Dice {
pub fn pick_word(&self) -> &str {
self.words
.choose(&mut rand::rng())
.choose(&mut rand::thread_rng())
.expect("`choose` should always return `Some`")
}
}

View File

@ -1,3 +1,3 @@
fn main() -> Result<(), String> {
fn main() {
division_of_one::main()
}