-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use z32 encoding for pkarr domain names
- Loading branch information
Showing
6 changed files
with
34 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,18 @@ | ||
use anyhow::{anyhow, Result}; | ||
use iroh_net::NodeId; | ||
|
||
pub mod discovery; | ||
pub mod packet; | ||
pub mod publish; | ||
pub mod resolve; | ||
|
||
pub fn to_z32(node_id: &NodeId) -> String { | ||
z32::encode(node_id.as_bytes()) | ||
} | ||
|
||
pub fn from_z32(s: &str) -> Result<NodeId> { | ||
let bytes = z32::decode(s.as_bytes()).map_err(|_| anyhow!("invalid z32"))?; | ||
let bytes: &[u8; 32] = &bytes.try_into().map_err(|_| anyhow!("not 32 bytes long"))?; | ||
let node_id = NodeId::from_bytes(bytes)?; | ||
Ok(node_id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters