Skip to content

Commit

Permalink
Merge pull request #31 from Nuhvi/z32
Browse files Browse the repository at this point in the history
feat: switch to z32 to avoid GPL license
  • Loading branch information
Nuhvi authored Oct 25, 2023
2 parents 0e144af + 824cf47 commit cf16beb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions pkarr/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pkarr"
version = "0.2.2"
version = "0.3.0"
authors = ["Nuh <[email protected]>"]
edition = "2021"
description = "Public-Key Addressable Resource Records (Pkarr); publish and resolve DNS records over Mainline DHT"
Expand All @@ -18,7 +18,7 @@ self_cell = "1.0.1"
simple-dns = "0.5.6"
thiserror = "1.0.49"
url = "2.4.1"
zbase32 = "0.1.2"
z32 = "1.0.0"

[dev-dependencies]
tokio = { version = "1.32.0", features = ["tokio-macros", "macros", "rt-multi-thread"] }
11 changes: 6 additions & 5 deletions pkarr/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{Error, Result};
use ed25519_dalek::{SecretKey, Signature, Signer, SigningKey, Verifier, VerifyingKey};
use rand::rngs::OsRng;
use std::fmt::{self, Debug, Display, Formatter};
use z32;

/// Ed25519 keypair to sign dns [Packet](crate::SignedPacket)s.
pub struct Keypair(SigningKey);
Expand Down Expand Up @@ -44,12 +45,12 @@ impl Keypair {

/// Ed25519 public key to verify a signature over dns [Packet](crate::SignedPacket)s.
///
/// It can formatted to and parsed from a `zbase32` string.
/// It can formatted to and parsed from a [zbase32](z32) string.
#[derive(Clone, Eq, PartialEq)]
pub struct PublicKey(VerifyingKey);

impl PublicKey {
/// Format the public key as zbase32 string.
/// Format the public key as [zbase32](z32) string.
pub fn to_z32(&self) -> String {
self.to_string()
}
Expand All @@ -72,8 +73,8 @@ impl TryFrom<&str> for PublicKey {
type Error = Error;

fn try_from(s: &str) -> Result<PublicKey> {
let bytes = zbase32::decode_full_bytes_str(s)
.map_err(|_| Error::Static("Invalid zbase32 encoding"))?;
let bytes =
z32::decode(s.as_bytes()).map_err(|_| Error::Static("Invalid zbase32 encoding"))?;

let verifying_key = VerifyingKey::try_from(bytes.as_slice())?;

Expand All @@ -83,7 +84,7 @@ impl TryFrom<&str> for PublicKey {

impl Display for PublicKey {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", zbase32::encode_full_bytes(self.0.as_bytes()))
write!(f, "{}", z32::encode(self.0.as_bytes()))
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkarr/src/signed_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl SignedPacket {
/// Creates a new [SignedPacket] from a [Keypair] and a DNS [Packet].
///
/// It will also normalize the names of the [ResourceRecord]s to be relative to the origin,
/// which would be the zbase32 encoded [PublicKey] of the [Keypair] used to sign the Packet.
/// which would be the [zbase32](z32) encoded [PublicKey] of the [Keypair] used to sign the Packet.
pub fn from_packet(keypair: &Keypair, packet: &Packet) -> Result<SignedPacket> {
// Normalize names to the origin TLD
let mut inner = Packet::new_reply(0);
Expand Down

0 comments on commit cf16beb

Please sign in to comment.