Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ testresult = "0.4.1"
tracing-subscriber = { version = "0.3.19", features = ["fmt"] }
tracing-test = "0.2.5"
walkdir = "2.5.0"
iroh = { version = "0.90", features = ["discovery-local-network"]}

[features]
hide-proto-docs = []
Expand Down
35 changes: 35 additions & 0 deletions examples/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#![allow(dead_code)]
use anyhow::Result;
use iroh::SecretKey;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};

/// Gets a secret key from the IROH_SECRET environment variable or generates a new random one.
/// If the environment variable is set, it must be a valid string representation of a secret key.
pub fn get_or_generate_secret_key() -> Result<SecretKey> {
use std::{env, str::FromStr};

use anyhow::Context;
use rand::thread_rng;
if let Ok(secret) = env::var("IROH_SECRET") {
// Parse the secret key from string
SecretKey::from_str(&secret).context("Invalid secret key format")
} else {
// Generate a new random key
let secret_key = SecretKey::generate(&mut thread_rng());
println!(
"Generated new secret key: {}",
hex::encode(secret_key.to_bytes())
);
println!("To reuse this key, set the IROH_SECRET environment variable to this value");
Ok(secret_key)
}
}

// set the RUST_LOG env var to one of {debug,info,warn} to see logging info
pub fn setup_logging() {
tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer().with_writer(std::io::stderr))
.with(EnvFilter::from_default_env())
.try_init()
.ok();
}
Loading
Loading