diff --git a/Cargo.lock b/Cargo.lock index be42305..39a8b49 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -90,6 +90,18 @@ dependencies = [ "rand", ] +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + [[package]] name = "blake2" version = "0.10.6" @@ -224,6 +236,27 @@ dependencies = [ "subtle", ] +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -259,6 +292,7 @@ dependencies = [ "bessie", "bytes", "clap", + "dirs-next", "rand", "thiserror", "z32", @@ -270,6 +304,17 @@ version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" +[[package]] +name = "libredox" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" +dependencies = [ + "bitflags 2.4.1", + "libc", + "redox_syscall", +] + [[package]] name = "password-hash" version = "0.5.0" @@ -335,6 +380,26 @@ dependencies = [ "getrandom", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "redox_users" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + [[package]] name = "strsim" version = "0.10.0" @@ -408,6 +473,28 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-sys" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index 42eb34c..ecba9db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] members = [ - "kytes", + "kytz", ] # See: https://github.com/rust-lang/rust/issues/90148#issuecomment-949194352 diff --git a/README.md b/README.md index c41d630..eddb7f3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -# Kytes +# Kytz > Soaring in the Cloud, but you pull the strings. +Kytz (pronounced Kites) is a set of tools and standards to enable user agency and credible exit. diff --git a/design/seed.md b/design/seed.md index 931fc58..1673709 100644 --- a/design/seed.md +++ b/design/seed.md @@ -1,9 +1,9 @@ # Seed -Kytes seed is an encrypted seed encoded as URI as follows: +Kytz seed is an encrypted seed encoded as URI as follows: ``` -kytes:seed: +kytz:seed: ``` The `suffix` is a `z-base32` encoded bytes as follows: diff --git a/kytes/src/lib.rs b/kytes/src/lib.rs deleted file mode 100644 index e76471b..0000000 --- a/kytes/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![allow(unused)] -mod crypto; -mod error; - -// Exports -pub use crate::error::Error; - -// Alias Result to be the crate Result. -pub type Result = core::result::Result; diff --git a/kytes/Cargo.toml b/kytz/Cargo.toml similarity index 84% rename from kytes/Cargo.toml rename to kytz/Cargo.toml index 88e770f..86f0163 100644 --- a/kytes/Cargo.toml +++ b/kytz/Cargo.toml @@ -6,19 +6,20 @@ description = "Soaring in the Cloud, but you pull the strings." license = "MIT" [dependencies] +argon2 = "0.5.2" +bessie = "0.0.1" bytes = "1.5.0" rand = "0.8.5" +thiserror = "1.0.50" z32 = "1.0.2" # cli clap = { version = "4.4.11", optional = true, features = ["derive"] } -argon2 = "0.5.2" -thiserror = "1.0.50" -bessie = "0.0.1" +dirs-next = { version = "2.0.0", optional = true } [features] default = ["cli"] -cli = ["clap"] +cli = ["clap", "dirs-next"] [[bin]] name = "kytes" diff --git a/kytz/src/cli/config.rs b/kytz/src/cli/config.rs new file mode 100644 index 0000000..a21d741 --- /dev/null +++ b/kytz/src/cli/config.rs @@ -0,0 +1,25 @@ +//! Configuration for the Kytz CLI. + +use std::path::{Path, PathBuf}; + +use crate::{Error, Result}; + +/// Name of directory that wraps all kytz files in a given application directory +const KYTZ_DIR: &str = "kytz"; + +/// Returns the path to the user's kytz config directory. +pub fn kytz_config_root() -> Result { + // if let Some(val) = env::var_os("IROH_CONFIG_DIR") { + // return Ok(PathBuf::from(val)); + // } + let cfg = dirs_next::config_dir().ok_or_else(|| { + Error::Generic("operating environment provides no directory for configuration".to_string()) + })?; + Ok(cfg.join(KYTZ_DIR)) +} + +/// Path that leads to a file in the iroh config directory. +pub fn kytz_config_path(file_name: impl AsRef) -> Result { + let path = kytz_config_root()?.join(file_name); + Ok(path) +} diff --git a/kytz/src/cli/mod.rs b/kytz/src/cli/mod.rs new file mode 100644 index 0000000..ef68c36 --- /dev/null +++ b/kytz/src/cli/mod.rs @@ -0,0 +1 @@ +pub mod config; diff --git a/kytes/src/crypto/encryption.rs b/kytz/src/crypto/encryption.rs similarity index 100% rename from kytes/src/crypto/encryption.rs rename to kytz/src/crypto/encryption.rs diff --git a/kytes/src/crypto/keys.rs b/kytz/src/crypto/keys.rs similarity index 100% rename from kytes/src/crypto/keys.rs rename to kytz/src/crypto/keys.rs diff --git a/kytes/src/crypto/mod.rs b/kytz/src/crypto/mod.rs similarity index 100% rename from kytes/src/crypto/mod.rs rename to kytz/src/crypto/mod.rs diff --git a/kytes/src/crypto/passphrase.rs b/kytz/src/crypto/passphrase.rs similarity index 100% rename from kytes/src/crypto/passphrase.rs rename to kytz/src/crypto/passphrase.rs diff --git a/kytes/src/crypto/seed.rs b/kytz/src/crypto/seed.rs similarity index 93% rename from kytes/src/crypto/seed.rs rename to kytz/src/crypto/seed.rs index 49ca59b..18e1a6f 100644 --- a/kytes/src/crypto/seed.rs +++ b/kytz/src/crypto/seed.rs @@ -1,4 +1,4 @@ -//! Manage Kytes seed files. +//! Manage Kytz seed files. //! //! Seed file contains a seed encrypted with a strong passphrase. @@ -15,7 +15,7 @@ use crate::{ Error, Result, }; -const SEED_SCHEME: &[u8] = b"kytes:seed:"; +const SEED_SCHEME: &[u8] = b"kytz:seed:"; const VERSION: u8 = 0; const KNOWN_VERSIONS: [u8; 1] = [0]; @@ -41,7 +41,7 @@ pub fn encrypt_seed(seed: &Key, passphrase: &str) -> Bytes { pub fn decrypt_seed(seed_file: Bytes, passphrase: &str) -> Result> { if !seed_file.starts_with(SEED_SCHEME) { - return Err(Error::Generic("Not a Kytes seed".to_string())); + return Err(Error::Generic("Not a Kytz seed".to_string())); } let suffix = z32::decode(&seed_file[SEED_SCHEME.len()..]) @@ -51,9 +51,7 @@ pub fn decrypt_seed(seed_file: Bytes, passphrase: &str) -> Result> { match version { 0 => decrypted_seed_v0(&suffix, passphrase), - _ => Err(Error::Generic( - "Unknown kytes seed file version".to_string(), - )), + _ => Err(Error::Generic("Unknown Kytz seed file version".to_string())), } } diff --git a/kytes/src/error.rs b/kytz/src/error.rs similarity index 58% rename from kytes/src/error.rs rename to kytz/src/error.rs index 28339e4..5a50c37 100644 --- a/kytes/src/error.rs +++ b/kytz/src/error.rs @@ -1,7 +1,10 @@ //! Main Crate Error +// Alias Result to be the crate Result. +pub type Result = core::result::Result; + #[derive(thiserror::Error, Debug)] -/// Kytes crate error enum. +/// Kytz crate error enum. pub enum Error { /// For starter, to remove as code matures. #[error("Generic error: {0}")] diff --git a/kytz/src/lib.rs b/kytz/src/lib.rs new file mode 100644 index 0000000..0f986dd --- /dev/null +++ b/kytz/src/lib.rs @@ -0,0 +1,5 @@ +#![allow(unused)] +mod crypto; +mod error; + +pub use crate::error::{Error, Result}; diff --git a/kytes/src/main.rs b/kytz/src/main.rs similarity index 93% rename from kytes/src/main.rs rename to kytz/src/main.rs index 12e3a91..d3952f6 100644 --- a/kytes/src/main.rs +++ b/kytz/src/main.rs @@ -1,5 +1,10 @@ use clap::{Parser, Subcommand}; +mod cli; +mod error; + +pub use crate::error::{Error, Result}; + #[derive(Parser)] #[command(author, version, about, long_about = None)] struct Cli { @@ -29,6 +34,7 @@ enum Commands { } fn main() { + dbg!(cli::config::kytz_config_path("seed.kytz").unwrap()); let cli = Cli::parse(); // You can check the value provided by positional arguments, or option arguments