mirror of
https://github.com/ZeusWPI/ZNS.git
synced 2024-11-21 21:41:10 +01:00
fix all clippy warnings
This commit is contained in:
parent
58ad3ca707
commit
81457941ac
10 changed files with 33 additions and 37 deletions
|
@ -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<String, ZNSError> {
|
|||
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<dyn Error
|
|||
}
|
||||
|
||||
let key_encoded = &file_content[OPENSSH_START.len()..file_content.len() - OPENSSH_END.len()]
|
||||
.replace("\n", "");
|
||||
.replace('\n', "");
|
||||
|
||||
let bin = BASE64_STANDARD.decode(key_encoded)?;
|
||||
let mut reader = Reader::new(&bin);
|
||||
|
@ -282,8 +282,8 @@ fn ssh_to_dnskey(file_content: &str, username: &str) -> Result<(), Box<dyn Error
|
|||
let mut file_public = File::create(format!("{}.key", FILENAME))?;
|
||||
|
||||
let (private, public) = key.to_dnskey(username);
|
||||
file_private.write(private.as_bytes())?;
|
||||
file_public.write(public.as_bytes())?;
|
||||
file_private.write_all(private.as_bytes())?;
|
||||
file_public.write_all(public.as_bytes())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ impl Config {
|
|||
zauth_url: env::var("ZAUTH_URL").expect("ZAUTH_URL must be set"),
|
||||
authoritative_zone: env::var("ZONE")
|
||||
.expect("ZONE must be set")
|
||||
.split(".")
|
||||
.split('.')
|
||||
.map(str::to_string)
|
||||
.collect(),
|
||||
port: env::var("ZNS_PORT")
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use std::fmt::format;
|
||||
|
||||
use diesel::prelude::*;
|
||||
use diesel::sql_types::Text;
|
||||
use zns::{
|
||||
|
@ -34,7 +32,7 @@ struct Record {
|
|||
pub rdata: Vec<u8>,
|
||||
}
|
||||
|
||||
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<String>,
|
||||
name: &[String],
|
||||
_type: Option<Type>,
|
||||
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<String>,
|
||||
name: &[String],
|
||||
_type: Option<Type>,
|
||||
class: Class,
|
||||
rdata: Option<Vec<u8>>,
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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<Vec<RR>, 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<Ve
|
|||
)?
|
||||
.into_iter()
|
||||
.map(|mut rr| {
|
||||
rr.name = question.qname.clone();
|
||||
rr.name.clone_from(&question.qname);
|
||||
rr
|
||||
})
|
||||
.collect())
|
||||
|
|
|
@ -14,7 +14,7 @@ use super::{dnskey::DNSKeyRData, sig::Sig};
|
|||
|
||||
pub async fn authenticate(
|
||||
sig: &Sig,
|
||||
zone: &Vec<String>,
|
||||
zone: &[String],
|
||||
connection: &mut PgConnection,
|
||||
) -> Result<bool, ZNSError> {
|
||||
if zone.len() >= Config::get().authoritative_zone.len() {
|
||||
|
@ -53,7 +53,7 @@ async fn validate_ssh(username: &String, sig: &Sig) -> Result<bool, reqwest::Err
|
|||
.json::<Vec<String>>()
|
||||
.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<bool, reqwest::Err
|
|||
}
|
||||
|
||||
async fn validate_dnskey(
|
||||
zone: &Vec<String>,
|
||||
zone: &[String],
|
||||
sig: &Sig,
|
||||
connection: &mut PgConnection,
|
||||
) -> Result<bool, ZNSError> {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
),
|
||||
})?;
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ async fn get_response(bytes: &[u8]) -> Vec<u8> {
|
|||
response
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("{}", e.to_string());
|
||||
eprintln!("{}", e);
|
||||
message.set_response(e.rcode());
|
||||
message
|
||||
}
|
||||
|
|
|
@ -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<Opcode, String> {
|
||||
|
|
Loading…
Reference in a new issue