Skip to content

Commit 19323e6

Browse files
fix(iroh-base)!: remove display impl for SecretKey (#3364)
## Description Closes #3363 ## Breaking Changes - `Display` implementation was removed for `SecretKey`, use `.to_bytes()` and encode as hex to get the previous bytes explicitly
1 parent bc6e9e3 commit 19323e6

File tree

10 files changed

+21
-20
lines changed

10 files changed

+21
-20
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iroh-base/src/key.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,6 @@ impl Debug for SecretKey {
229229
}
230230
}
231231

232-
impl Display for SecretKey {
233-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
234-
// TODO: revivew for security
235-
write!(
236-
f,
237-
"{}",
238-
data_encoding::HEXLOWER.encode(self.secret.as_bytes())
239-
)
240-
}
241-
}
242-
243232
impl FromStr for SecretKey {
244233
type Err = KeyParsingError;
245234

@@ -394,10 +383,12 @@ mod tests {
394383
}
395384

396385
#[test]
397-
fn test_display_from_str() {
386+
fn test_from_str() {
398387
let key = SecretKey::generate(&mut rand::thread_rng());
399388
assert_eq!(
400-
SecretKey::from_str(&key.to_string()).unwrap().to_bytes(),
389+
SecretKey::from_str(&HEXLOWER.encode(&key.to_bytes()))
390+
.unwrap()
391+
.to_bytes(),
401392
key.to_bytes()
402393
);
403394

iroh-dns-server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ z32 = "1.1.1"
6161

6262
[dev-dependencies]
6363
criterion = "0.5.1"
64+
data-encoding = "2.3.3"
6465
hickory-resolver = "0.25.0"
6566
iroh = { path = "../iroh" }
6667
rand = "0.8"

iroh-dns-server/examples/publish.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ async fn main() -> Result<()> {
6565
Err(_) => {
6666
let s = SecretKey::generate(rand::rngs::OsRng);
6767
println!("Generated a new node secret. To reuse, set");
68-
println!("\tIROH_SECRET={s}\n");
68+
println!(
69+
"\tIROH_SECRET={}",
70+
data_encoding::HEXLOWER.encode(&s.to_bytes())
71+
);
6972
s
7073
}
7174
};

iroh/examples/0rtt.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{env, future::Future, str::FromStr, time::Instant};
22

33
use clap::Parser;
4+
use data_encoding::HEXLOWER;
45
use iroh::{
56
endpoint::{Connecting, Connection},
67
SecretKey,
@@ -35,7 +36,10 @@ pub fn get_or_generate_secret_key() -> n0_snafu::Result<SecretKey> {
3536
} else {
3637
// Generate a new random key
3738
let secret_key = SecretKey::generate(&mut thread_rng());
38-
println!("Generated new secret key: {}", secret_key);
39+
println!(
40+
"Generated new secret key: {}",
41+
HEXLOWER.encode(&secret_key.to_bytes())
42+
);
3943
println!("To reuse this key, set the IROH_SECRET environment variable to this value");
4044
Ok(secret_key)
4145
}

iroh/examples/connect-unreliable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async fn main() -> n0_snafu::Result<()> {
3535
println!("\nconnect (unreliable) example!\n");
3636
let args = Cli::parse();
3737
let secret_key = SecretKey::generate(rand::rngs::OsRng);
38-
println!("secret key: {secret_key}");
38+
println!("public key: {}", secret_key.public());
3939

4040
// Build a `Endpoint`, which uses PublicKeys as node identifiers, uses QUIC for directly connecting to other nodes, and uses the relay protocol and relay servers to holepunch direct connections between nodes when there are NATs or firewalls preventing direct connections. If no direct connection can be made, packets are relayed over the relay servers.
4141
let endpoint = Endpoint::builder()

iroh/examples/connect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async fn main() -> Result<()> {
3535
println!("\nconnect example!\n");
3636
let args = Cli::parse();
3737
let secret_key = SecretKey::generate(rand::rngs::OsRng);
38-
println!("secret key: {secret_key}");
38+
println!("public key: {}", secret_key.public());
3939

4040
// Build a `Endpoint`, which uses PublicKeys as node identifiers, uses QUIC for directly connecting to other nodes, and uses the relay protocol and relay servers to holepunch direct connections between nodes when there are NATs or firewalls preventing direct connections. If no direct connection can be made, packets are relayed over the relay servers.
4141
let endpoint = Endpoint::builder()

iroh/examples/listen-unreliable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async fn main() -> Result<()> {
1616
tracing_subscriber::fmt::init();
1717
println!("\nlisten (unreliable) example!\n");
1818
let secret_key = SecretKey::generate(rand::rngs::OsRng);
19-
println!("secret key: {secret_key}");
19+
println!("public key: {}", secret_key.public());
2020

2121
// Build a `Endpoint`, which uses PublicKeys as node identifiers, uses QUIC for directly connecting to other nodes, and uses the relay servers to holepunch direct connections between nodes when there are NATs or firewalls preventing direct connections. If no direct connection can be made, packets are relayed over the relay servers.
2222
let endpoint = Endpoint::builder()

iroh/examples/listen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async fn main() -> n0_snafu::Result<()> {
1818
tracing_subscriber::fmt::init();
1919
println!("\nlisten example!\n");
2020
let secret_key = SecretKey::generate(rand::rngs::OsRng);
21-
println!("secret key: {secret_key}");
21+
println!("public key: {}", secret_key.public());
2222

2323
// Build a `Endpoint`, which uses PublicKeys as node identifiers, uses QUIC for directly connecting to other nodes, and uses the relay protocol and relay servers to holepunch direct connections between nodes when there are NATs or firewalls preventing direct connections. If no direct connection can be made, packets are relayed over the relay servers.
2424
let endpoint = Endpoint::builder()

iroh/examples/transfer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{
55

66
use bytes::Bytes;
77
use clap::{Parser, Subcommand};
8+
use data_encoding::HEXLOWER;
89
use indicatif::HumanBytes;
910
use iroh::{
1011
discovery::{
@@ -184,7 +185,7 @@ impl EndpointArgs {
184185
Err(_) => {
185186
let s = SecretKey::generate(rand::rngs::OsRng);
186187
println!("Generated a new node secret. To reuse, set");
187-
println!("\tIROH_SECRET={s}");
188+
println!("\tIROH_SECRET={}", HEXLOWER.encode(&s.to_bytes()));
188189
s
189190
}
190191
};

0 commit comments

Comments
 (0)