Skip to content

Commit 9f4749d

Browse files
committed
Linter fixes.
1 parent 09f1fad commit 9f4749d

File tree

13 files changed

+94
-81
lines changed

13 files changed

+94
-81
lines changed

src/base32.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ impl BitBuffer {
88
BitBuffer { bit_offset: 0u8, bytes: Vec::new() }
99
}
1010

11-
fn write(&mut self, data: u8, bits: u8) -> () {
11+
fn write(&mut self, data: u8, bits: u8) {
1212
assert!(bits <= 8);
1313
if self.bit_offset + bits > 8 {
1414
let second_write_bits = (self.bit_offset + bits) % 8;
@@ -27,7 +27,7 @@ impl BitBuffer {
2727
}
2828
}
2929

30-
fn to_bytes(mut self) -> Vec<u8> {
30+
fn into_bytes(mut self) -> Vec<u8> {
3131
if self.bit_offset != 0 {
3232
self.bytes.pop();
3333
self.bytes
@@ -50,7 +50,7 @@ pub fn decode(base32: &str) -> Option<Vec<u8>> {
5050
};
5151
buffer.write(bits, 5);
5252
};
53-
Some(buffer.to_bytes())
53+
Some(buffer.into_bytes())
5454
}
5555

5656
#[cfg(test)]
@@ -115,7 +115,7 @@ mod tests {
115115
buf.write(1u8, 1);
116116
buf.write(64u8, 7);
117117
assert_eq!(
118-
buf.to_bytes(),
118+
buf.into_bytes(),
119119
vec![0xc0],
120120
);
121121
}
@@ -127,7 +127,7 @@ mod tests {
127127
buf.write(72u8, 8);
128128
buf.write(1u8, 4);
129129
assert_eq!(
130-
buf.to_bytes(),
130+
buf.into_bytes(),
131131
vec![0x14, 0x81],
132132
);
133133
}
@@ -137,7 +137,7 @@ mod tests {
137137
let mut buf = BitBuffer::new();
138138
buf.write(1u8, 1);
139139
assert_eq!(
140-
buf.to_bytes(),
140+
buf.into_bytes(),
141141
vec![],
142142
);
143143

@@ -146,7 +146,7 @@ mod tests {
146146
buf.write(0u8, 7);
147147
buf.write(1u8, 1);
148148
assert_eq!(
149-
buf.to_bytes(),
149+
buf.into_bytes(),
150150
vec![0x80],
151151
);
152152
}

src/commands/init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn needs_root(cfg_path: &Path, config: &Config, user: &str, local: bool, exe_ins
9292
log::info!("does not need root because we're doing local init");
9393
return false;
9494
}
95-
let totpm_user_id = get_user_id(&user).unwrap();
95+
let totpm_user_id = get_user_id(user).unwrap();
9696
if !is_effective_user(totpm_user_id) {
9797
log::info!("needs root because we're not the totpm user");
9898
return true;
@@ -136,7 +136,7 @@ fn can_create_file(uid: u32, path: &Path) -> bool {
136136
}
137137
match longest_existing_prefix(path) {
138138
Some(p) => can_create_dir(uid, &p),
139-
None => return false,
139+
None => false,
140140
}
141141
}
142142

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Config {
3636
presence_verification: Option<PresenceVerificationMethod>,
3737
) -> Self {
3838
Config {
39-
tpm: tpm,
39+
tpm,
4040
system_data_path: system_data_path.as_deref().map(absolute_path).unwrap_or(
4141
if local {
4242
local_path(&PathBuf::from(".local/state/totpm/system"))

src/db/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn ensure_db_file_exists<P : AsRef<Path>>(db_path: P) -> Result<()> {
116116
let db_dir = db_path.as_ref().parent().unwrap();
117117
if !db_dir.exists() {
118118
log::info!("creating secrets database directory with permissions 0700 at {}", db_dir.to_str().unwrap());
119-
std::fs::create_dir_all(&db_dir)?;
119+
std::fs::create_dir_all(db_dir)?;
120120
}
121121
if !db_dir.is_dir() {
122122
return Err(Error::DbDirIsNotADir);

src/db/model.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ impl Secret {
2424
) -> Self {
2525
Secret {
2626
id: 0,
27-
service: service,
28-
account: account,
27+
service,
28+
account,
2929
digits: digits.unwrap_or(6),
3030
interval: interval.unwrap_or(30),
31-
public_data: public_data,
32-
private_data: private_data
31+
public_data,
32+
private_data,
3333
}
3434
}
3535
}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{path::{Path, PathBuf}, process::exit};
1+
use std::{path::{Path, PathBuf}, process::exit, str::FromStr};
22

33
use clap::Parser;
44
use serde::Deserialize;

src/presence_verification/fprintd.rs

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{str::FromStr, sync::{Arc, Mutex}, time::{self, Duration}};
1+
use std::{fmt::Display, str::FromStr, sync::{Arc, Mutex}, time::{self, Duration}};
22

33
use dbus::{arg::ReadAll, blocking::{Connection, Proxy}, message::SignalArgs, Message, Path};
44

@@ -56,18 +56,18 @@ impl FromStr for Status {
5656
}
5757
}
5858

59-
impl ToString for Status {
60-
fn to_string(&self) -> String {
59+
impl Display for Status {
60+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6161
match self {
62-
Status::Match => "verify-match",
63-
Status::NoMatch => "verify-no-match",
64-
Status::RetryScan => "verify-retry-scan",
65-
Status::SwipeTooShort => "verify-swipe-too-short",
66-
Status::FingerNotCentered => "verify-finger-not-entered",
67-
Status::RemoveAndRetry => "verify-remove-and-retry",
68-
Status::Disconnected => "verify-disconnected",
69-
Status::UnknownError => "verify-unknown-error",
70-
}.to_string()
62+
Status::Match => f.write_str("verify-match"),
63+
Status::NoMatch => f.write_str("verify-no-match"),
64+
Status::RetryScan => f.write_str("verify-retry-scan"),
65+
Status::SwipeTooShort => f.write_str("verify-swipe-too-short"),
66+
Status::FingerNotCentered => f.write_str("verify-finger-not-entered"),
67+
Status::RemoveAndRetry => f.write_str("verify-remove-and-retry"),
68+
Status::Disconnected => f.write_str("verify-disconnected"),
69+
Status::UnknownError => f.write_str("verify-unknown-error"),
70+
}
7171
}
7272
}
7373

@@ -126,37 +126,34 @@ impl <'a> FprintDevice<'a> {
126126
let t1 = time::Instant::now();
127127
time_left -= (t1 - t0).as_millis() as i64;
128128

129-
match *scan_status_clone.lock().unwrap() {
130-
Some(status) => {
131-
match status {
132-
Status::Match => {
133-
self.proxy.method_call(FPRINTD_DEVICE_IFACE, "VerifyStop", ())
134-
.or(fail("fprintd: unable to stop fingerprint verification"))?;
135-
return Ok(true)
136-
},
137-
Status::NoMatch => {
138-
eprintln!("fingerprint not recognized, try again");
139-
self.proxy.method_call(FPRINTD_DEVICE_IFACE, "VerifyStop", ())
140-
.or(fail("fprintd: unable to stop fingerprint verification"))?;
141-
self.proxy.method_call(FPRINTD_DEVICE_IFACE, "VerifyStart", ("any",))
142-
.or(fail("fprintd: unable to restart fingerprint verification"))?;
143-
},
144-
Status::RetryScan | Status::SwipeTooShort | Status::FingerNotCentered | Status::RemoveAndRetry => {
145-
eprintln!("fingerprint not recognized, try again")
146-
// scan is still ongoing, keep waiting for status updates
147-
},
148-
Status::Disconnected => {
149-
return fail("fprintd: fingerprint reader disconnected")
150-
},
151-
Status::UnknownError => {
152-
self.proxy.method_call(FPRINTD_DEVICE_IFACE, "VerifyStop", ())
153-
.or(fail("fprintd: unable to stop fingerprint verification"))?;
154-
return fail("fprintd: fingerprint scan failed with unknown error")
155-
},
156-
}
157-
158-
},
159-
None => {},
129+
if let Some(status) = *scan_status_clone.lock().unwrap() {
130+
match status {
131+
Status::Match => {
132+
self.proxy.method_call(FPRINTD_DEVICE_IFACE, "VerifyStop", ())
133+
.or(fail("fprintd: unable to stop fingerprint verification"))?;
134+
return Ok(true)
135+
},
136+
Status::NoMatch => {
137+
eprintln!("fingerprint not recognized, try again");
138+
self.proxy.method_call(FPRINTD_DEVICE_IFACE, "VerifyStop", ())
139+
.or(fail("fprintd: unable to stop fingerprint verification"))?;
140+
self.proxy.method_call(FPRINTD_DEVICE_IFACE, "VerifyStart", ("any",))
141+
.or(fail("fprintd: unable to restart fingerprint verification"))?;
142+
},
143+
Status::RetryScan | Status::SwipeTooShort | Status::FingerNotCentered | Status::RemoveAndRetry => {
144+
eprintln!("fingerprint not recognized, try again")
145+
// scan is still ongoing, keep waiting for status updates
146+
},
147+
Status::Disconnected => {
148+
return fail("fprintd: fingerprint reader disconnected")
149+
},
150+
Status::UnknownError => {
151+
self.proxy.method_call(FPRINTD_DEVICE_IFACE, "VerifyStop", ())
152+
.or(fail("fprintd: unable to stop fingerprint verification"))?;
153+
return fail("fprintd: fingerprint scan failed with unknown error")
154+
},
155+
}
156+
160157
}
161158
}
162159
self.proxy.method_call(FPRINTD_DEVICE_IFACE, "VerifyStop", ())
@@ -180,7 +177,7 @@ impl <'a> FprintDevice<'a> {
180177
);
181178
proxy.method_call(FPRINTD_DEVICE_IFACE, "Claim", ("",))
182179
.or(Err(super::Error::ImplementationSpecificError("fprintd: unable to claim device".to_owned())))?;
183-
Ok(FprintDevice { proxy: proxy, connection: conn })
180+
Ok(FprintDevice { proxy, connection: conn })
184181
}
185182
}
186183

src/presence_verification/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::str::FromStr;
2+
13
use serde::{de::IntoDeserializer, Deserialize, Serialize};
24

35
pub mod fprintd;
@@ -18,11 +20,13 @@ pub enum PresenceVerificationMethod {
1820
None,
1921
}
2022

21-
impl PresenceVerificationMethod {
22-
pub fn from_str(s: &str) -> crate::result::Result<Self> {
23+
impl FromStr for PresenceVerificationMethod {
24+
fn from_str(s: &str) -> crate::result::Result<Self> {
2325
Self::deserialize(s.into_deserializer())
2426
.map_err(|_: serde::de::value::Error| crate::result::Error::InvalidPVMethod(s.to_string()))
2527
}
28+
29+
type Err = crate::result::Error;
2630
}
2731

2832
pub trait PresenceVerifier {

src/term.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ mod tests {
7575
#[test]
7676
fn pick_one_returns_none_on_non_terminal_input() {
7777
assert_eq!(
78-
pick_one(&mut VecDeque::new(), &mut Vec::new(), "hello", vec![1,2,3].iter()),
78+
pick_one(&mut VecDeque::new(), &mut Vec::new(), "hello", [1,2,3].iter()),
7979
None,
8080
)
8181
}
@@ -85,7 +85,7 @@ mod tests {
8585
let mut term = MockTerminal::new();
8686
let (mut inp, mut out) = term.stdin_stdout();
8787
assert_eq!(
88-
pick_one(&mut inp, &mut out, "hello", vec![].iter()),
88+
pick_one(&mut inp, &mut out, "hello", [].iter()),
8989
None as Option<&u32>,
9090
)
9191
}
@@ -95,7 +95,7 @@ mod tests {
9595
let mut term = MockTerminal::new().write_stdin("0");
9696
let (mut inp, mut out) = term.stdin_stdout();
9797
assert_eq!(
98-
pick_one(&mut inp, &mut out, "hello", vec![1, 2, 3].iter()),
98+
pick_one(&mut inp, &mut out, "hello", [1, 2, 3].iter()),
9999
None as Option<&u32>,
100100
)
101101
}
@@ -106,11 +106,11 @@ mod tests {
106106
let (mut inp, mut out) = term.stdin_stdout();
107107
let mut non_terminal_stdout = Vec::new();
108108
assert_eq!(
109-
pick_one(&mut inp, &mut out, "hello", vec!["x"].iter()),
109+
pick_one(&mut inp, &mut out, "hello", ["x"].iter()),
110110
Some(&"x"),
111111
);
112112
assert_eq!(
113-
pick_one(&mut inp, &mut non_terminal_stdout, "hello", vec!["x"].iter()),
113+
pick_one(&mut inp, &mut non_terminal_stdout, "hello", ["x"].iter()),
114114
Some(&"x"),
115115
);
116116
}
@@ -129,7 +129,7 @@ mod tests {
129129
.write_stdin("1");
130130
let (mut inp, mut out) = term.stdin_stdout();
131131
assert_eq!(
132-
pick_one(&mut inp, &mut out, "hello", vec!["foo", "bar"].iter()),
132+
pick_one(&mut inp, &mut out, "hello", ["foo", "bar"].iter()),
133133
None as Option<&&str>,
134134
);
135135
}
@@ -146,14 +146,14 @@ mod tests {
146146
.write_stdin("0");
147147
let (mut inp, mut out) = term.stdin_stdout();
148148
assert_eq!(
149-
pick_one(&mut inp, &mut out, "hello", vec!["foo", "bar", "baz"].iter()),
149+
pick_one(&mut inp, &mut out, "hello", ["foo", "bar", "baz"].iter()),
150150
None as Option<&&str>,
151151
);
152152
}
153153

154154
#[test]
155155
fn pick_one_returns_chosen_input() {
156-
let items = vec![1, 2, 3, 4, 5];
156+
let items = [1, 2, 3, 4, 5];
157157
let mut term = MockTerminal::new()
158158
.wait_stdout()
159159
.write_stdin("1") // First item

src/totp_store.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ pub struct WithoutTPM;
5757

5858
impl <P> TotpStore<P> {
5959
pub fn del(&mut self, secret_id: i64) -> Result<()> {
60-
let result = self.with_db(|db| {
60+
self.with_db(|db| {
6161
db.del_secret(secret_id)
6262
})?;
63-
Ok(result)
63+
Ok(())
6464
}
6565

6666
pub fn list(&self, service: Option<&str>, account: Option<&str>) -> Result<Vec<Secret>> {
@@ -71,7 +71,7 @@ impl <P> TotpStore<P> {
7171
}
7272

7373
fn with_db<T, F: FnOnce(&db::DB) -> db::Result<T>>(&self, f: F) -> db::Result<T> {
74-
Ok(db::with_db(self.config.secrets_db_path(), f)?)
74+
db::with_db(self.config.secrets_db_path(), f)
7575
}
7676
}
7777

@@ -81,7 +81,7 @@ impl TotpStore<WithoutTPM> {
8181
pub fn without_tpm(config: Config) -> TotpStore<WithoutTPM> {
8282
drop_privileges();
8383
TotpStore {
84-
config: config,
84+
config,
8585
tpm: None,
8686
primary_key: None,
8787
phantom: PhantomData,
@@ -203,7 +203,7 @@ impl TotpStore<WithTPM> {
203203
drop_privileges();
204204

205205
Ok(TotpStore {
206-
config: config,
206+
config,
207207
tpm: Some(tpm),
208208
primary_key: Some(primary_key),
209209
phantom: PhantomData,

0 commit comments

Comments
 (0)