Skip to content

Commit

Permalink
clean up clippy a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
doy committed Dec 27, 2024
1 parent c2c7e03 commit fd03616
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 97 deletions.
20 changes: 20 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ urlencoding = "2.1.3"
uuid = { version = "1.11.0", features = ["v4"] }
zeroize = "1.8.1"

[lints.clippy]
cargo = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }
nursery = { level = "warn", priority = -1 }
as_conversions = "warn"
get_unwrap = "warn"
cognitive_complexity = "allow"
missing_const_for_fn = "allow"
similar_names = "allow"
struct_excessive_bools = "allow"
too_many_arguments = "allow"
too_many_lines = "allow"
type_complexity = "allow"
multiple_crate_versions = "allow"
large_enum_variant = "allow"
must_use_candidate = "allow"
missing_errors_doc = "allow"
missing_panics_doc = "allow"
significant_drop_tightening = "allow"

[package.metadata.deb]
depends = "pinentry"
license-file = ["LICENSE"]
Expand Down
4 changes: 0 additions & 4 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ pub enum TwoFactorProviderType {
}

impl TwoFactorProviderType {
#[must_use]
pub fn message(&self) -> &str {
match *self {
Self::Authenticator => "Enter the 6 digit verification code from your authenticator app.",
Expand All @@ -70,7 +69,6 @@ impl TwoFactorProviderType {
}
}

#[must_use]
pub fn header(&self) -> &str {
match *self {
Self::Authenticator => "Authenticator App",
Expand All @@ -80,7 +78,6 @@ impl TwoFactorProviderType {
}
}

#[must_use]
pub fn grab(&self) -> bool {
!matches!(self, Self::Email)
}
Expand Down Expand Up @@ -775,7 +772,6 @@ pub struct Client {
}

impl Client {
#[must_use]
pub fn new(
base_url: &str,
identity_url: &str,
Expand Down
17 changes: 0 additions & 17 deletions src/bin/rbw-agent/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#![warn(clippy::cargo)]
#![warn(clippy::pedantic)]
#![warn(clippy::nursery)]
#![warn(clippy::as_conversions)]
#![warn(clippy::get_unwrap)]
#![allow(clippy::cognitive_complexity)]
#![allow(clippy::missing_const_for_fn)]
#![allow(clippy::similar_names)]
#![allow(clippy::struct_excessive_bools)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::too_many_lines)]
#![allow(clippy::type_complexity)]
#![allow(clippy::multiple_crate_versions)]
#![allow(clippy::large_enum_variant)]
// this one looks plausibly useful, but currently has too many bugs
#![allow(clippy::significant_drop_tightening)]

use anyhow::Context as _;

mod actions;
Expand Down
15 changes: 0 additions & 15 deletions src/bin/rbw/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
#![warn(clippy::cargo)]
#![warn(clippy::pedantic)]
#![warn(clippy::nursery)]
#![warn(clippy::as_conversions)]
#![warn(clippy::get_unwrap)]
#![allow(clippy::cognitive_complexity)]
#![allow(clippy::missing_const_for_fn)]
#![allow(clippy::similar_names)]
#![allow(clippy::struct_excessive_bools)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::too_many_lines)]
#![allow(clippy::type_complexity)]
#![allow(clippy::multiple_crate_versions)]
#![allow(clippy::large_enum_variant)]

use std::io::Write as _;

use anyhow::Context as _;
Expand Down
10 changes: 0 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,19 @@ impl Default for Config {
}
}

#[must_use]
pub fn default_lock_timeout() -> u64 {
3600
}

#[must_use]
pub fn default_sync_interval() -> u64 {
3600
}

#[must_use]
pub fn default_pinentry() -> String {
"pinentry".to_string()
}

impl Config {
#[must_use]
pub fn new() -> Self {
Self::default()
}
Expand Down Expand Up @@ -147,7 +143,6 @@ impl Config {
Ok(())
}

#[must_use]
pub fn base_url(&self) -> String {
self.base_url.clone().map_or_else(
|| "https://api.bitwarden.com".to_string(),
Expand All @@ -162,7 +157,6 @@ impl Config {
)
}

#[must_use]
pub fn identity_url(&self) -> String {
self.identity_url.clone().unwrap_or_else(|| {
self.base_url.clone().map_or_else(
Expand All @@ -179,15 +173,13 @@ impl Config {
})
}

#[must_use]
pub fn ui_url(&self) -> String {
// TODO: default to either vault.bitwarden.com or vault.bitwarden.eu based on the base_url?
self.ui_url
.clone()
.unwrap_or_else(|| "https://vault.bitwarden.com".to_string())
}

#[must_use]
pub fn notifications_url(&self) -> String {
self.notifications_url.clone().unwrap_or_else(|| {
self.base_url.clone().map_or_else(
Expand All @@ -204,12 +196,10 @@ impl Config {
})
}

#[must_use]
pub fn client_cert_path(&self) -> Option<&std::path::Path> {
self.client_cert_path.as_deref()
}

#[must_use]
pub fn server_name(&self) -> String {
self.base_url
.clone()
Expand Down
2 changes: 0 additions & 2 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ pub struct Db {
}

impl Db {
#[must_use]
pub fn new() -> Self {
Self::default()
}
Expand Down Expand Up @@ -295,7 +294,6 @@ impl Db {
Ok(())
}

#[must_use]
pub fn needs_login(&self) -> bool {
self.access_token.is_none()
|| self.refresh_token.is_none()
Expand Down
12 changes: 0 additions & 12 deletions src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,68 +38,57 @@ pub fn make_all() -> Result<()> {
Ok(())
}

#[must_use]
pub fn config_file() -> std::path::PathBuf {
config_dir().join("config.json")
}

const INVALID_PATH: &percent_encoding::AsciiSet =
&percent_encoding::CONTROLS.add(b'/').add(b'%').add(b':');
#[must_use]
pub fn db_file(server: &str, email: &str) -> std::path::PathBuf {
let server =
percent_encoding::percent_encode(server.as_bytes(), INVALID_PATH)
.to_string();
cache_dir().join(format!("{server}:{email}.json"))
}

#[must_use]
pub fn pid_file() -> std::path::PathBuf {
runtime_dir().join("pidfile")
}

#[must_use]
pub fn agent_stdout_file() -> std::path::PathBuf {
data_dir().join("agent.out")
}

#[must_use]
pub fn agent_stderr_file() -> std::path::PathBuf {
data_dir().join("agent.err")
}

#[must_use]
pub fn device_id_file() -> std::path::PathBuf {
data_dir().join("device_id")
}

#[must_use]
pub fn socket_file() -> std::path::PathBuf {
runtime_dir().join("socket")
}

#[must_use]
fn config_dir() -> std::path::PathBuf {
let project_dirs =
directories::ProjectDirs::from("", "", &profile()).unwrap();
project_dirs.config_dir().to_path_buf()
}

#[must_use]
fn cache_dir() -> std::path::PathBuf {
let project_dirs =
directories::ProjectDirs::from("", "", &profile()).unwrap();
project_dirs.cache_dir().to_path_buf()
}

#[must_use]
fn data_dir() -> std::path::PathBuf {
let project_dirs =
directories::ProjectDirs::from("", "", &profile()).unwrap();
project_dirs.data_dir().to_path_buf()
}

#[must_use]
fn runtime_dir() -> std::path::PathBuf {
let project_dirs =
directories::ProjectDirs::from("", "", &profile()).unwrap();
Expand All @@ -117,7 +106,6 @@ fn runtime_dir() -> std::path::PathBuf {
)
}

#[must_use]
pub fn profile() -> String {
match std::env::var("RBW_PROFILE") {
Ok(profile) if !profile.is_empty() => format!("rbw-{profile}"),
Expand Down
18 changes: 0 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
#![warn(clippy::cargo)]
#![warn(clippy::pedantic)]
#![warn(clippy::nursery)]
#![warn(clippy::as_conversions)]
#![warn(clippy::get_unwrap)]
#![allow(clippy::cognitive_complexity)]
#![allow(clippy::missing_const_for_fn)]
#![allow(clippy::similar_names)]
#![allow(clippy::struct_excessive_bools)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::too_many_lines)]
#![allow(clippy::type_complexity)]
#![allow(clippy::multiple_crate_versions)]
#![allow(clippy::large_enum_variant)]
// we aren't really documenting apis anyway
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::missing_panics_doc)]

pub mod actions;
pub mod api;
pub mod base64;
Expand Down
14 changes: 0 additions & 14 deletions src/locked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ impl Default for Vec {
}

impl Vec {
#[must_use]
pub fn new() -> Self {
Self::default()
}

#[must_use]
pub fn data(&self) -> &[u8] {
self.data.as_slice()
}
Expand Down Expand Up @@ -85,12 +83,10 @@ pub struct Password {
}

impl Password {
#[must_use]
pub fn new(password: Vec) -> Self {
Self { password }
}

#[must_use]
pub fn password(&self) -> &[u8] {
self.password.data()
}
Expand All @@ -102,17 +98,14 @@ pub struct Keys {
}

impl Keys {
#[must_use]
pub fn new(keys: Vec) -> Self {
Self { keys }
}

#[must_use]
pub fn enc_key(&self) -> &[u8] {
&self.keys.data()[0..32]
}

#[must_use]
pub fn mac_key(&self) -> &[u8] {
&self.keys.data()[32..64]
}
Expand All @@ -124,12 +117,10 @@ pub struct PasswordHash {
}

impl PasswordHash {
#[must_use]
pub fn new(hash: Vec) -> Self {
Self { hash }
}

#[must_use]
pub fn hash(&self) -> &[u8] {
self.hash.data()
}
Expand All @@ -141,12 +132,10 @@ pub struct PrivateKey {
}

impl PrivateKey {
#[must_use]
pub fn new(private_key: Vec) -> Self {
Self { private_key }
}

#[must_use]
pub fn private_key(&self) -> &[u8] {
self.private_key.data()
}
Expand All @@ -159,20 +148,17 @@ pub struct ApiKey {
}

impl ApiKey {
#[must_use]
pub fn new(client_id: Password, client_secret: Password) -> Self {
Self {
client_id,
client_secret,
}
}

#[must_use]
pub fn client_id(&self) -> &[u8] {
self.client_id.password()
}

#[must_use]
pub fn client_secret(&self) -> &[u8] {
self.client_secret.password()
}
Expand Down
Loading

0 comments on commit fd03616

Please sign in to comment.