make clippy happy

This commit is contained in:
Ryan Heywood 2023-09-25 21:16:33 -05:00
parent 97f9a57e08
commit c4882f2d21
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
12 changed files with 24 additions and 11 deletions

View File

@ -1,6 +1,6 @@
use crate::client::Client; use crate::client::Client;
use clap::Parser; use clap::Parser;
use keyfork_derive_util::{request::*, DerivationPath}; use keyfork_derive_util::{request::{DerivationAlgorithm, DerivationRequest, DerivationResponse}, DerivationPath};
#[derive(Parser, Clone, Debug)] #[derive(Parser, Clone, Debug)]
pub struct Command { pub struct Command {

View File

@ -1,6 +1,6 @@
use crate::Result; use crate::Result;
use keyfork_derive_util::request::*; use keyfork_derive_util::request::{DerivationRequest, DerivationResponse};
use keyfork_frame::*; use keyfork_frame::{try_decode_from, try_encode_to};
use std::os::unix::net::UnixStream; use std::os::unix::net::UnixStream;
#[derive(Debug)] #[derive(Debug)]

View File

@ -3,6 +3,7 @@ use clap::Parser;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
#[allow(clippy::wildcard_imports)]
use keyfork_derive_key::*; use keyfork_derive_key::*;
fn main() -> Result<()> { fn main() -> Result<()> {

View File

@ -1,6 +1,7 @@
use super::Error; use super::Error;
use std::{collections::HashMap, os::unix::net::UnixStream, path::PathBuf}; use std::{collections::HashMap, os::unix::net::UnixStream, path::PathBuf};
#[allow(clippy::module_name_repetitions)]
pub fn get_socket() -> Result<UnixStream, Error> { pub fn get_socket() -> Result<UnixStream, Error> {
let socket_vars = std::env::vars() let socket_vars = std::env::vars()
.filter(|(key, _)| ["XDG_RUNTIME_DIR", "KEYFORKD_SOCKET_PATH"].contains(&key.as_str())) .filter(|(key, _)| ["XDG_RUNTIME_DIR", "KEYFORKD_SOCKET_PATH"].contains(&key.as_str()))

View File

@ -35,7 +35,7 @@ pub trait PublicKey: Sized {
let hash = Sha256::new().chain_update(self.to_bytes()).finalize(); let hash = Sha256::new().chain_update(self.to_bytes()).finalize();
let hash = Ripemd160::new().chain_update(hash).finalize(); let hash = Ripemd160::new().chain_update(hash).finalize();
// Note: Safety assured by type returned from Ripemd160 // Note: Safety assured by type returned from Ripemd160
hash[..4].try_into().unwrap() hash[..4].try_into().expect("Ripemd160 returned too little data")
} }
} }
@ -73,8 +73,9 @@ impl PublicKey for k256::PublicKey {
*/ */
fn to_bytes(&self) -> PublicKeyBytes { fn to_bytes(&self) -> PublicKeyBytes {
// Note: Safety assured by type returned from EncodedPoint let mut result = [0u8; 33];
self.to_encoded_point(true).as_bytes().try_into().unwrap() result[..].copy_from_slice(self.to_encoded_point(true).as_bytes());
result
} }
fn derive_child(&self, other: PrivateKeyBytes) -> Result<Self, Self::Err> { fn derive_child(&self, other: PrivateKeyBytes) -> Result<Self, Self::Err> {

View File

@ -37,7 +37,7 @@ fn ensure_offline() {
.expect("Unable to decode UTF-8 filepath") .expect("Unable to decode UTF-8 filepath")
.split('/') .split('/')
.last() .last()
.unwrap() .expect("No data in file path")
== "lo" == "lo"
{ {
continue; continue;

View File

@ -1,3 +1,4 @@
#[allow(clippy::wildcard_imports)]
use keyfork_mnemonic_from_seed::*; use keyfork_mnemonic_from_seed::*;
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {

View File

@ -25,6 +25,7 @@ const ED25519_512: &str = "fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b
9f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542"; 9f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542";
// Note: This should never error. // Note: This should never error.
#[allow(clippy::too_many_lines)]
pub fn test_data() -> Result<HashMap<String, Vec<TestData>>, Box<dyn std::error::Error>> { pub fn test_data() -> Result<HashMap<String, Vec<TestData>>, Box<dyn std::error::Error>> {
// Format: // Format:
let mut map = HashMap::new(); let mut map = HashMap::new();

View File

@ -1,3 +1,5 @@
#![allow(clippy::module_name_repetitions)]
use clap::Parser; use clap::Parser;
mod cli; mod cli;
@ -5,5 +7,5 @@ mod cli;
fn main() { fn main() {
let opts = cli::Keyfork::parse(); let opts = cli::Keyfork::parse();
opts.command.handle(&opts).unwrap(); opts.command.handle(&opts).expect("Unable to handle command");
} }

View File

@ -1,7 +1,7 @@
use thiserror::Error; use thiserror::Error;
#[derive(Debug, Clone, Error)] #[derive(Debug, Clone, Error)]
pub enum KeyforkdError { pub enum Keyforkd {
#[error("Neither KEYFORKD_SOCKET_PATH nor XDG_RUNTIME_DIR were set, nowhere to mount socket")] #[error("Neither KEYFORKD_SOCKET_PATH nor XDG_RUNTIME_DIR were set, nowhere to mount socket")]
NoSocketPath, NoSocketPath,
} }

View File

@ -13,7 +13,7 @@ pub mod error;
pub mod middleware; pub mod middleware;
pub mod server; pub mod server;
pub mod service; pub mod service;
pub use error::KeyforkdError; pub use error::Keyforkd as KeyforkdError;
pub use server::UnixServer; pub use server::UnixServer;
pub use service::Keyforkd; pub use service::Keyforkd;

View File

@ -19,6 +19,12 @@ impl<'a, Request> BincodeLayer<'a, Request> {
} }
} }
impl<'a, Request> Default for BincodeLayer<'a, Request> {
fn default() -> Self {
Self::new()
}
}
impl<'a, S: 'a, Request> Layer<S> for BincodeLayer<'a, Request> { impl<'a, S: 'a, Request> Layer<S> for BincodeLayer<'a, Request> {
type Service = BincodeService<S, Request>; type Service = BincodeService<S, Request>;
@ -137,7 +143,7 @@ mod tests {
async fn can_serde_responses() { async fn can_serde_responses() {
let content = serialize(&Test::new()).unwrap(); let content = serialize(&Test::new()).unwrap();
let mut service = ServiceBuilder::new() let mut service = ServiceBuilder::new()
.layer(BincodeLayer::<Test>::new()) .layer(BincodeLayer::<Test>::default())
.service(App); .service(App);
let result = service let result = service
.ready() .ready()