Skip to content

Commit 1797512

Browse files
authored
Merge pull request #76 from pubky/feat/drop-z32
feat(pkarr): replace z32 with base32
2 parents e1ca797 + 12c88a0 commit 1797512

File tree

5 files changed

+23
-36
lines changed

5 files changed

+23
-36
lines changed

Cargo.lock

+7-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkarr/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ repository = "https://git.pkarr.org"
99
keywords = ["mainline", "dht", "dns", "decentralized", "identity"]
1010

1111
[dependencies]
12+
base32 = "0.5.0"
1213
bytes = "1.7.1"
1314
document-features = "0.2.8"
1415
ed25519-dalek = "2.0.0"
1516
self_cell = "1.0.2"
1617
simple-dns = "0.6.1"
1718
thiserror = "1.0.49"
1819
tracing = "0.1.40"
19-
z32 = "1.1.1"
2020
rand = { version = "0.8.5", optional = true }
2121
lru = { version = "0.12.3", default-features = false }
2222
flume = { version = "0.11.0", features = ["select", "eventual-fairness"], default-features = false }

pkarr/src/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ pub enum Error {
2525
#[error("Invalid Ed25519 signature")]
2626
InvalidEd25519Signature,
2727

28-
#[error(transparent)]
29-
InvalidPublicKeyEncoding(#[from] z32::Z32Error),
28+
#[error("Invalid PublicKey encoding")]
29+
InvalidPublicKeyEncoding,
3030

3131
// === Packets errors ===
3232
#[error(transparent)]

pkarr/src/keys.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ impl Keypair {
5959

6060
/// Ed25519 public key to verify a signature over dns [Packet](crate::SignedPacket)s.
6161
///
62-
/// It can formatted to and parsed from a [zbase32](z32) string.
62+
/// It can formatted to and parsed from a z-base32 string.
6363
#[derive(Clone, Eq, PartialEq, Hash)]
6464
pub struct PublicKey(VerifyingKey);
6565

6666
impl PublicKey {
67-
/// Format the public key as [zbase32](z32) string.
67+
/// Format the public key as z-base32 string.
6868
pub fn to_z32(&self) -> String {
6969
self.to_string()
7070
}
@@ -185,7 +185,11 @@ impl TryFrom<&str> for PublicKey {
185185
}
186186
}
187187

188-
let bytes = z32::decode(s.as_bytes())?;
188+
let bytes = if let Some(v) = base32::decode(base32::Alphabet::Z, s) {
189+
Ok(v)
190+
} else {
191+
Err(Error::InvalidPublicKeyEncoding)
192+
}?;
189193

190194
let verifying_key = VerifyingKey::try_from(bytes.as_slice())
191195
.map_err(|_| Error::InvalidPublicKeyLength(bytes.len()))?;
@@ -204,7 +208,11 @@ impl TryFrom<String> for PublicKey {
204208

205209
impl Display for PublicKey {
206210
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
207-
write!(f, "{}", z32::encode(self.0.as_bytes()))
211+
write!(
212+
f,
213+
"{}",
214+
base32::encode(base32::Alphabet::Z, self.0.as_bytes())
215+
)
208216
}
209217
}
210218

pkarr/src/signed_packet.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl SignedPacket {
133133
/// Creates a new [SignedPacket] from a [Keypair] and a DNS [Packet].
134134
///
135135
/// It will also normalize the names of the [ResourceRecord]s to be relative to the origin,
136-
/// which would be the [zbase32](z32) encoded [PublicKey] of the [Keypair] used to sign the Packet.
136+
/// which would be the z-base32 encoded [PublicKey] of the [Keypair] used to sign the Packet.
137137
///
138138
/// # Errors
139139
/// - Returns [crate::Error::DnsError] if the packet is invalid or it failed to compress or encode it.

0 commit comments

Comments
 (0)