From 81457941ac2f2b2f1793dee97f8b34c60bd1022e Mon Sep 17 00:00:00 2001 From: Xander Bil Date: Thu, 22 Aug 2024 17:06:05 +0200 Subject: [PATCH] fix all clippy warnings --- zns-cli/src/main.rs | 16 ++++++------- zns-daemon/src/config.rs | 2 +- zns-daemon/src/db/models.rs | 24 ++++++++----------- zns-daemon/src/handlers/mod.rs | 4 ++-- zns-daemon/src/handlers/query.rs | 8 +++---- .../src/handlers/update/authenticate.rs | 6 ++--- zns-daemon/src/handlers/update/mod.rs | 2 +- zns-daemon/src/handlers/update/pubkeys/mod.rs | 2 +- zns-daemon/src/resolver.rs | 2 +- zns/src/message.rs | 4 ++-- 10 files changed, 33 insertions(+), 37 deletions(-) diff --git a/zns-cli/src/main.rs b/zns-cli/src/main.rs index 492ba01..90e62a3 100644 --- a/zns-cli/src/main.rs +++ b/zns-cli/src/main.rs @@ -48,7 +48,7 @@ struct RSAKeyPair { enum KeyPair { ED255519(Ed25519KeyPair), - RSA(RSAKeyPair), + Rsa(RSAKeyPair), } #[allow(dead_code)] @@ -63,7 +63,7 @@ fn read_string(reader: &mut Reader) -> Result { let length = reader.read_u32()?; let data = reader.read(length as usize)?; let result = from_utf8(&data).map_err(|e| ZNSError::Key { - message: format!("Wrong ciphername format: {}", e.to_string()), + message: format!("Wrong ciphername format: {}", e), })?; Ok(result.to_owned()) } @@ -190,7 +190,7 @@ impl KeyTransformer for OpenSSHKey { let buf = reader.read(14)?; let magic = from_utf8(&buf).map_err(|e| ZNSError::Key { - message: format!("Not valid ASCII: {}", e.to_string()), + message: format!("Not valid ASCII: {}", e), })?; if magic != "openssh-key-v1" { @@ -232,7 +232,7 @@ impl KeyTransformer for OpenSSHKey { let keypair = match keytype.as_str() { "ssh-ed25519" => Ok(KeyPair::ED255519(Ed25519KeyPair::from_openssh(reader)?)), - "ssh-rsa" => Ok(KeyPair::RSA(RSAKeyPair::from_openssh(reader)?)), + "ssh-rsa" => Ok(KeyPair::Rsa(RSAKeyPair::from_openssh(reader)?)), other => Err(ZNSError::Key { message: format!("Invalid public keytype {}", other), }), @@ -252,7 +252,7 @@ impl KeyTransformer for OpenSSHKey { fn to_dnskey(&self, username: &str) -> (String, String) { match &self.keypair { KeyPair::ED255519(keypair) => keypair.to_dnskey(username), - KeyPair::RSA(keypair) => keypair.to_dnskey(username), + KeyPair::Rsa(keypair) => keypair.to_dnskey(username), } } } @@ -272,7 +272,7 @@ fn ssh_to_dnskey(file_content: &str, username: &str) -> Result<(), Box Result<(), Box, } -sql_function! { +define_sql_function! { fn lower(x: Text) -> Text; } @@ -121,7 +119,7 @@ pub fn insert_into_database(rr: &RR, connection: &mut PgConnection) -> Result<() } pub fn get_from_database( - name: &Vec, + name: &[String], _type: Option, class: Class, connection: &mut PgConnection, @@ -138,22 +136,20 @@ pub fn get_from_database( Ok(records .into_iter() - .filter_map(|record| { - Some(RR { - name: record.name.split(".").map(str::to_string).collect(), - _type: Type::from(record._type as u16), - class: Class::from(record.class as u16), - ttl: record.ttl, - rdlength: record.rdlength as u16, - rdata: record.rdata, - }) + .map(|record| RR { + name: record.name.split('.').map(str::to_string).collect(), + _type: Type::from(record._type as u16), + class: Class::from(record.class as u16), + ttl: record.ttl, + rdlength: record.rdlength as u16, + rdata: record.rdata, }) .collect()) } //TODO: cleanup models pub fn delete_from_database( - name: &Vec, + name: &[String], _type: Option, class: Class, rdata: Option>, diff --git a/zns-daemon/src/handlers/mod.rs b/zns-daemon/src/handlers/mod.rs index 0b3ddcc..79f856f 100644 --- a/zns-daemon/src/handlers/mod.rs +++ b/zns-daemon/src/handlers/mod.rs @@ -29,8 +29,8 @@ impl ResponseHandler for Handler { match message.get_opcode() { //TODO: implement this in Opcode Ok(opcode) => match opcode { - Opcode::QUERY => QueryHandler::handle(&message, raw, connection).await, - Opcode::UPDATE => UpdateHandler::handle(&message, raw, connection).await, + Opcode::QUERY => QueryHandler::handle(message, raw, connection).await, + Opcode::UPDATE => UpdateHandler::handle(message, raw, connection).await, }, Err(e) => Err(ZNSError::Formerr { message: e.to_string(), diff --git a/zns-daemon/src/handlers/query.rs b/zns-daemon/src/handlers/query.rs index 24035d3..e687d23 100644 --- a/zns-daemon/src/handlers/query.rs +++ b/zns-daemon/src/handlers/query.rs @@ -30,9 +30,9 @@ impl ResponseHandler for QueryHandler { match answers { Ok(mut rrs) => { - if rrs.len() == 0 { + if rrs.is_empty() { rrs.extend(try_wildcard(question, connection)?); - if rrs.len() == 0 { + if rrs.is_empty() { return Err(ZNSError::NXDomain { domain: question.qname.join("."), qtype: question.qtype.clone(), @@ -57,7 +57,7 @@ impl ResponseHandler for QueryHandler { fn try_wildcard(question: &Question, connection: &mut PgConnection) -> Result, ZNSError> { let records = get_from_database(&question.qname, None, question.qclass.clone(), connection)?; - if records.len() > 0 || question.qname.len() == 0 { + if !records.is_empty() || question.qname.is_empty() { Ok(vec![]) } else { let mut qname = question.qname.clone(); @@ -70,7 +70,7 @@ fn try_wildcard(question: &Question, connection: &mut PgConnection) -> Result, + zone: &[String], connection: &mut PgConnection, ) -> Result { if zone.len() >= Config::get().authoritative_zone.len() { @@ -53,7 +53,7 @@ async fn validate_ssh(username: &String, sig: &Sig) -> Result>() .await? .iter() - .any(|key| match sig.verify_ssh(&key) { + .any(|key| match sig.verify_ssh(key) { Ok(value) => value, Err(e) => { eprintln!("{}", e); @@ -63,7 +63,7 @@ async fn validate_ssh(username: &String, sig: &Sig) -> Result, + zone: &[String], sig: &Sig, connection: &mut PgConnection, ) -> Result { diff --git a/zns-daemon/src/handlers/update/mod.rs b/zns-daemon/src/handlers/update/mod.rs index 57f9ae2..8478f41 100644 --- a/zns-daemon/src/handlers/update/mod.rs +++ b/zns-daemon/src/handlers/update/mod.rs @@ -96,7 +96,7 @@ impl ResponseHandler for UpdateHandler { for rr in &message.authority { if rr.class == zone.qclass { - let _ = insert_into_database(&rr, connection)?; + insert_into_database(rr, connection)?; } else if rr.class == Class::Class(RRClass::ANY) { if rr._type == Type::Type(RRType::ANY) { if rr.name == zone.qname { diff --git a/zns-daemon/src/handlers/update/pubkeys/mod.rs b/zns-daemon/src/handlers/update/pubkeys/mod.rs index b3788cc..a525ef2 100644 --- a/zns-daemon/src/handlers/update/pubkeys/mod.rs +++ b/zns-daemon/src/handlers/update/pubkeys/mod.rs @@ -19,7 +19,7 @@ pub trait PublicKey { let algo_type = from_utf8(&read).map_err(|e| ZNSError::Key { message: format!( "Could not convert type name bytes to string: {}", - e.to_string() + e ), })?; diff --git a/zns-daemon/src/resolver.rs b/zns-daemon/src/resolver.rs index 53936c3..a1f43ba 100644 --- a/zns-daemon/src/resolver.rs +++ b/zns-daemon/src/resolver.rs @@ -51,7 +51,7 @@ async fn get_response(bytes: &[u8]) -> Vec { response } Err(e) => { - eprintln!("{}", e.to_string()); + eprintln!("{}", e); message.set_response(e.rcode()); message } diff --git a/zns/src/message.rs b/zns/src/message.rs index ca952dc..1946183 100644 --- a/zns/src/message.rs +++ b/zns/src/message.rs @@ -2,8 +2,8 @@ use crate::structs::{Message, Opcode, RCODE}; impl Message { pub fn set_response(&mut self, rcode: RCODE) { - self.header.flags = (self.header.flags | 0b1_0000_1_0_0_0_000_0000 | rcode as u16) - & 0b1_1111_1_0_1_0_111_1111 + self.header.flags = + (self.header.flags | 0b1000_0100_0000_0000 | rcode as u16) & 0b1111_1101_0111_1111 } pub fn get_opcode(&self) -> Result {