Skip to content

Commit

Permalink
chore: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuhvi committed Nov 22, 2023
1 parent 75cf8da commit 0a18184
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
3 changes: 1 addition & 2 deletions pkarr/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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 @@ -102,7 +101,7 @@ impl Debug for Keypair {

impl Debug for PublicKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "PublicKey({})", self.to_string())
write!(f, "PublicKey({})", self)
}
}

Expand Down
8 changes: 7 additions & 1 deletion pkarr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl PkarrClient {
}
let bytes = response.bytes().await?;

Ok(SignedPacket::from_bytes(public_key, bytes)?)
SignedPacket::from_bytes(public_key, bytes)
}

/// Publishes a [SignedPacket](crate::SignedPacket) through a [relay](https://github.com/Nuhvi/pkarr/blob/main/design/relays.md).
Expand All @@ -85,6 +85,12 @@ impl PkarrClient {
}
}

impl Default for PkarrClient {
fn default() -> Self {
Self::new()
}
}

fn format_relay_url(url: &Url, public_key: &PublicKey) -> Url {
let mut url = url.to_owned();
url.set_path(&public_key.to_z32());
Expand Down
23 changes: 11 additions & 12 deletions pkarr/src/signed_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ use simple_dns::{
Name, Packet, ResourceRecord,
};
use std::{
char,
fmt::{self, Display, Formatter},
net::{Ipv4Addr, Ipv6Addr},
time::SystemTime,
};

const DOT: char = '.';

self_cell!(
struct PacketBytes {
owner: Bytes,
Expand Down Expand Up @@ -143,10 +146,7 @@ impl SignedPacket {
bytes.extend_from_slice(&timestamp.to_be_bytes());
bytes.extend_from_slice(&encoded_packet);

Ok(SignedPacket::from_bytes(
keypair.public_key(),
bytes.into(),
)?)
SignedPacket::from_bytes(keypair.public_key(), bytes.into())
}
}

Expand All @@ -164,7 +164,7 @@ impl From<SignedPacket> for Bytes {

impl AsRef<[u8]> for SignedPacket {
fn as_ref(&self) -> &[u8] {
&self.packet_bytes.borrow_owner()
self.packet_bytes.borrow_owner()
}
}

Expand All @@ -179,16 +179,15 @@ impl Display for SignedPacket {
)?;

for answer in &self.packet().answers {
write!(
writeln!(
f,
" {} IN {} {}\n",
&answer.name,
&answer.ttl,
match &answer.rdata {
RData::A(A { address }) =>
format!("A {}", Ipv4Addr::from(*address).to_string()),
RData::AAAA(AAAA { address }) =>
format!("AAAA {}", Ipv6Addr::from(*address).to_string()),
RData::A(A { address }) => format!("A {}", Ipv4Addr::from(*address)),
RData::AAAA(AAAA { address }) => format!("AAAA {}", Ipv6Addr::from(*address)),
#[allow(clippy::to_string_in_format_args)]
RData::CNAME(name) => format!("CNAME {}", name.to_string()),
RData::TXT(txt) => {
format!(
Expand All @@ -203,14 +202,14 @@ impl Display for SignedPacket {
)?;
}

write!(f, "\n")?;
writeln!(f)?;

Ok(())
}
}

fn normalize_name(origin: &str, name: String) -> String {
let name = if name.ends_with(".") {
let name = if name.ends_with(DOT) {
name[..name.len() - 1].to_string()
} else {
name
Expand Down

0 comments on commit 0a18184

Please sign in to comment.