Skip to content

Commit 0917471

Browse files
authored
Merge pull request #178 from replydev/fix_clippy_1.67
Fix clippy 1.67 warnings
2 parents c0c109a + 9e14f6d commit 0917471

19 files changed

+44
-49
lines changed

src/argument_functions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn import(matches: &ArgMatches, database: &mut OTPDatabase) -> Result<String
3838
let elements = match result {
3939
Ok(result) => result,
4040
Err(e) => {
41-
return Err(format!("An error occurred: {}", e));
41+
return Err(format!("An error occurred: {e}"));
4242
}
4343
};
4444

@@ -132,7 +132,7 @@ pub fn edit(matches: &ArgMatches, database: &mut OTPDatabase) -> Result<String,
132132
}
133133
database.edit_element(index, element);
134134
}
135-
None => return Err(format!("No element found at index {}", index)),
135+
None => return Err(format!("No element found at index {index}")),
136136
}
137137

138138
secret.zeroize();
@@ -145,15 +145,15 @@ pub fn export(matches: &ArgMatches, database: &mut OTPDatabase) -> Result<String
145145
"Database was successfully exported at {}",
146146
export_result.to_str().unwrap_or("**Invalid path**")
147147
)),
148-
Err(e) => Err(format!("An error occurred while exporting database: {}", e)),
148+
Err(e) => Err(format!("An error occurred while exporting database: {e}")),
149149
}
150150
}
151151

152152
pub fn change_password(database: &mut OTPDatabase) -> Result<String, String> {
153153
let mut new_password = utils::verified_password("New password: ", 8);
154154
let r = match database.save_with_pw(&new_password) {
155155
Ok(()) => Ok(String::from("Password changed")),
156-
Err(e) => Err(format!("An error has occurred: {}", e)),
156+
Err(e) => Err(format!("An error has occurred: {e}")),
157157
};
158158
new_password.zeroize();
159159
r

src/crypto/cryptography.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ pub fn argon_derive_key(password_bytes: &[u8], salt: &[u8]) -> Result<Vec<u8>, S
3232
pub fn gen_salt() -> Result<[u8; ARGON2ID_SALT_LENGTH], String> {
3333
let mut salt: [u8; ARGON2ID_SALT_LENGTH] = [0; ARGON2ID_SALT_LENGTH];
3434
if let Err(e) = getrandom::getrandom(&mut salt) {
35-
//return Err(format!("Error during salt generation: {}", e));
36-
return Err(format!("Error during salt generation: {}", e));
35+
return Err(format!("Error during salt generation: {e}"));
3736
}
3837
Ok(salt)
3938
}
@@ -49,7 +48,7 @@ pub fn encrypt_string_with_key(
4948
let mut nonce_bytes: [u8; XCHACHA20_POLY1305_NONCE_LENGTH] =
5049
[0; XCHACHA20_POLY1305_NONCE_LENGTH];
5150
if let Err(e) = getrandom::getrandom(&mut nonce_bytes) {
52-
return Err(format!("Error during nonce generation: {}", e));
51+
return Err(format!("Error during nonce generation: {e}"));
5352
}
5453
let nonce = XNonce::from_slice(&nonce_bytes);
5554
let cipher_text = aead
@@ -72,8 +71,7 @@ pub fn decrypt_string(
7271
Ok(result) => result,
7372
Err(e) => {
7473
return Err(format!(
75-
"Error during encrypted database deserialization: {}",
76-
e
74+
"Error during encrypted database deserialization: {e}"
7775
))
7876
}
7977
};
@@ -100,7 +98,7 @@ pub fn decrypt_string(
10098
};
10199
match String::from_utf8(decrypted) {
102100
Ok(result) => Ok((result, key, salt)),
103-
Err(e) => Err(format!("Error during UTF-8 string conversion: {}", e)),
101+
Err(e) => Err(format!("Error during UTF-8 string conversion: {e}")),
104102
}
105103
}
106104

src/importers/aegis.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct AegisInfo {
4747
pub fn import(filepath: &str) -> Result<Vec<OTPElement>, String> {
4848
let file_to_import_contents = match read_to_string(filepath) {
4949
Ok(result) => result,
50-
Err(e) => return Err(format!("Error during file reading: {:?}", e)),
50+
Err(e) => return Err(format!("Error during file reading: {e:?}")),
5151
};
5252
import_from_string(file_to_import_contents.as_str())
5353
}
@@ -58,7 +58,7 @@ pub fn import_from_string(file_to_import_contents: &str) -> Result<Vec<OTPElemen
5858
Err(_) => {
5959
let aegis_db: AegisDb = match serde_json::from_str(file_to_import_contents) {
6060
Ok(element) => element,
61-
Err(e) => return Err(format!("{:?}", e)),
61+
Err(e) => return Err(format!("{e:?}")),
6262
};
6363
// maybe we are importing from an encrypted aegis database, so we don
6464
Ok(map_entries(aegis_db.entries))

src/importers/aegis_encrypted.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ struct AegisEncryptedSlot {
4949
pub fn import(filepath: &str, password: &str) -> Result<Vec<OTPElement>, String> {
5050
let file_to_import_contents = match read_to_string(filepath) {
5151
Ok(result) => result,
52-
Err(e) => return Err(format!("Error during file reading: {:?}", e)),
52+
Err(e) => return Err(format!("Error during file reading: {e:?}")),
5353
};
5454
let aegis_encrypted: AegisEncryptedDatabase =
5555
match serde_json::from_str(&file_to_import_contents) {
5656
Ok(result) => result,
57-
Err(e) => return Err(format!("Error during deserialization: {:?}", e)),
57+
Err(e) => return Err(format!("Error during deserialization: {e:?}")),
5858
};
5959

6060
let mut master_key: Option<Vec<u8>> = None;
@@ -70,15 +70,15 @@ pub fn import(filepath: &str, password: &str) -> Result<Vec<OTPElement>, String>
7070
master_key = Some(value);
7171
break;
7272
}
73-
Err(e) => println!("{}", e),
73+
Err(e) => println!("{e}"),
7474
}
7575
}
7676

7777
match master_key {
7878
Some(mut master_key) => {
7979
let content = match BASE64.decode(aegis_encrypted.db.as_bytes()) {
8080
Ok(result) => result,
81-
Err(e) => return Err(format!("Error during base64 decoding: {:?}", e)),
81+
Err(e) => return Err(format!("Error during base64 decoding: {e:?}")),
8282
};
8383

8484
let key = GenericArray::clone_from_slice(master_key.as_slice());
@@ -100,12 +100,12 @@ pub fn import(filepath: &str, password: &str) -> Result<Vec<OTPElement>, String>
100100
.as_slice(),
101101
) {
102102
Ok(result) => result,
103-
Err(e) => return Err(format!("Failed to derive master key: {:?}", e)),
103+
Err(e) => return Err(format!("Failed to derive master key: {e:?}")),
104104
};
105105

106106
let json = match String::from_utf8(decrypted_db) {
107107
Ok(result) => result,
108-
Err(e) => return Err(format!("Failed to decode from utf-8 bytes: {:?}", e)),
108+
Err(e) => return Err(format!("Failed to decode from utf-8 bytes: {e:?}")),
109109
};
110110

111111
aegis::import_from_string(json.as_str())
@@ -121,7 +121,7 @@ fn get_params(slot: &AegisEncryptedSlot) -> Result<Params, String> {
121121

122122
match Params::new((n as f32).log2() as u8, r, p) {
123123
Ok(result) => Ok(result),
124-
Err(e) => Err(format!("Error during scrypt params creation: {:?}", e)),
124+
Err(e) => Err(format!("Error during scrypt params creation: {e:?}")),
125125
}
126126
}
127127

@@ -139,7 +139,7 @@ fn get_master_key(slot: &AegisEncryptedSlot, password: &str) -> Result<Vec<u8>,
139139
&params,
140140
output.as_mut_slice(),
141141
) {
142-
return Err(format!("Error during scrypt key derivation: {:?}", e));
142+
return Err(format!("Error during scrypt key derivation: {e:?}"));
143143
}
144144
let key = GenericArray::clone_from_slice(output.as_slice());
145145
output.zeroize();
@@ -160,6 +160,6 @@ fn get_master_key(slot: &AegisEncryptedSlot, password: &str) -> Result<Vec<u8>,
160160
cipher_text.as_slice(),
161161
) {
162162
Ok(result) => Ok(result),
163-
Err(e) => Err(format!("Failed to derive master key: {:?}", e)),
163+
Err(e) => Err(format!("Failed to derive master key: {e:?}")),
164164
}
165165
}

src/importers/and_otp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use crate::otp::otp_element::OTPElement;
66
pub fn import(filepath: &str) -> Result<Vec<OTPElement>, String> {
77
let file_to_import_contents = match read_to_string(filepath) {
88
Ok(result) => result,
9-
Err(e) => return Err(format!("Error during file reading: {:?}", e)),
9+
Err(e) => return Err(format!("Error during file reading: {e:?}")),
1010
};
1111

1212
match serde_json::from_str::<Vec<OTPElement>>(&file_to_import_contents) {
1313
Ok(elements) => Ok(elements),
14-
Err(e) => Err(format!("Failed to serialize file: {}", e)),
14+
Err(e) => Err(format!("Failed to serialize file: {e}")),
1515
}
1616
}

src/importers/authy_remote_debug.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ impl AuthyExportedJsonElement {
6767
pub fn import(file_path: &str) -> Result<Vec<OTPElement>, String> {
6868
let json = match read_to_string(file_path) {
6969
Ok(r) => r,
70-
Err(e) => return Err(format!("{:?}", e)),
70+
Err(e) => return Err(format!("{e:?}")),
7171
};
7272
let elements: Vec<AuthyExportedJsonElement> = match serde_json::from_str(json.as_str()) {
7373
Ok(r) => r,
74-
Err(e) => return Err(format!("Error during deserializing: {:?}", e)),
74+
Err(e) => return Err(format!("Error during deserializing: {e:?}")),
7575
};
7676

7777
Ok(elements

src/importers/converted.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ struct ConvertedJson {
2020
pub fn import(filepath: &str) -> Result<Vec<OTPElement>, String> {
2121
let file_to_import_contents = match read_to_string(filepath) {
2222
Ok(result) => result,
23-
Err(e) => return Err(format!("Error during file reading: {:?}", e)),
23+
Err(e) => return Err(format!("Error during file reading: {e:?}")),
2424
};
2525
let result: Result<Vec<ConvertedJson>, serde_json::Error> =
2626
serde_json::from_str(&file_to_import_contents);
2727
let vector: Vec<ConvertedJson> = match result {
2828
Ok(r) => r,
29-
Err(e) => return Err(format!("{}", e)),
29+
Err(e) => return Err(format!("{e}")),
3030
};
3131

3232
Ok(vector

src/importers/cotp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use crate::otp::otp_element::{OTPDatabase, OTPElement};
55
pub fn import(filepath: &str) -> Result<Vec<OTPElement>, String> {
66
let file_to_import_contents = match read_to_string(filepath) {
77
Ok(result) => result,
8-
Err(e) => return Err(format!("Error during file reading: {:?}", e)),
8+
Err(e) => return Err(format!("Error during file reading: {e:?}")),
99
};
1010

1111
match serde_json::from_str::<OTPDatabase>(&file_to_import_contents) {
1212
Ok(database) => Ok(database.elements),
1313
Err(_e) => match serde_json::from_str::<Vec<OTPElement>>(&file_to_import_contents) {
1414
Ok(elements) => Ok(elements),
15-
Err(e) => Err(format!("Failed to serialize file: {}", e)),
15+
Err(e) => Err(format!("Failed to serialize file: {e}")),
1616
},
1717
}
1818
}

src/importers/freeotp_plus.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ struct FreeOTPElement {
3131
pub fn import(file_path: &str) -> Result<Vec<OTPElement>, String> {
3232
let json = match read_to_string(file_path) {
3333
Ok(r) => r,
34-
Err(e) => return Err(format!("{:?}", e)),
34+
Err(e) => return Err(format!("{e:?}")),
3535
};
3636

3737
let freeotp: FreeOTPPlusJson = match serde_json::from_str(json.as_str()) {
3838
Ok(r) => r,
39-
Err(e) => return Err(format!("Error during deserializing: {:?}", e)),
39+
Err(e) => return Err(format!("Error during deserializing: {e:?}")),
4040
};
4141

4242
Ok(freeotp

src/interface/handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ fn copy_selected_code_to_clipboard(app: &mut App) -> String {
227227
}
228228
None => "Cannot get OTP Code column".to_string(),
229229
},
230-
None => format!("Cannot fetch element from index: {}", selected),
230+
None => format!("Cannot fetch element from index: {selected}"),
231231
},
232232
None => "No code selected".to_string(),
233233
}

src/interface/table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn fill_table(table: &mut StatefulTable, elements: &[OTPElement]) {
6060
let label = match element.type_ {
6161
OTPType::Hotp => match element.counter {
6262
Some(result) => {
63-
element.label.to_owned() + (format!(" ({} counter)", result).as_str())
63+
element.label.to_owned() + (format!(" ({result} counter)").as_str())
6464
}
6565
None => element.label.to_owned(),
6666
},

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn main() -> AppResult<()> {
5151
let mut result = match init() {
5252
Ok(v) => v,
5353
Err(e) => {
54-
println!("{}", e);
54+
println!("{e}");
5555
std::process::exit(-1);
5656
}
5757
};
@@ -78,7 +78,7 @@ fn main() -> AppResult<()> {
7878
std::process::exit(0)
7979
}
8080
Err(e) => {
81-
eprintln!("{}", e);
81+
eprintln!("{e}");
8282
std::process::exit(-2);
8383
}
8484
},

src/otp/algorithms/hotp_maker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ where
3737
// decode the base32 secret
3838
let secret_decoded = match BASE32_NOPAD.decode(secret.as_bytes()) {
3939
Ok(result) => result,
40-
Err(e) => return Err(format!("{:?}", e)),
40+
Err(e) => return Err(format!("{e:?}")),
4141
};
4242

4343
let hash = hotp_hash::<D>(&secret_decoded, counter);

src/otp/algorithms/motp_maker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn get_motp_code(
2121
// TODO MOTP Secrets are hex encoded, so do not use BASE32 at all
2222
let hex_secret = secret;
2323
let counter = seconds / period;
24-
let data = format!("{}{}{}", counter, hex_secret, pin);
24+
let data = format!("{counter}{hex_secret}{pin}");
2525

2626
let mut md5_hasher = Md5::new();
2727
md5_hasher.update(data.as_bytes());

src/otp/otp_algorithm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub enum OTPAlgorithm {
1313

1414
impl fmt::Display for OTPAlgorithm {
1515
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
16-
write!(f, "{:?}", self)
16+
write!(f, "{self:?}")
1717
}
1818
}
1919

src/otp/otp_element.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl OTPDatabase {
5252
migrate(self)?;
5353
match self.overwrite_database_key(key, salt) {
5454
Ok(()) => Ok(()),
55-
Err(e) => Err(format!("{:?}", e)),
55+
Err(e) => Err(format!("{e:?}")),
5656
}
5757
}
5858

@@ -99,7 +99,7 @@ impl OTPDatabase {
9999
contents.zeroize();
100100
Ok(exported_path)
101101
}
102-
Err(e) => Err(format!("{:?}", e)),
102+
Err(e) => Err(format!("{e:?}")),
103103
}
104104
}
105105

src/otp/otp_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub enum OTPType {
2424

2525
impl fmt::Display for OTPType {
2626
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27-
write!(f, "{:?}", self)
27+
write!(f, "{self:?}")
2828
}
2929
}
3030

src/reading.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn get_elements() -> Result<ReadResult, String> {
1111
let mut pw = utils::password("Password: ", 8);
1212
let (elements, key, salt) = match read_from_file(&pw) {
1313
Ok((result, key, salt)) => (result, key, salt),
14-
Err(e) => return Err(format!("Cannot decrypt existing database: {}", e)),
14+
Err(e) => return Err(format!("Cannot decrypt existing database: {e}")),
1515
};
1616
pw.zeroize();
1717
Ok((elements, key, salt))
@@ -22,7 +22,7 @@ pub fn read_decrypted_text(password: &str) -> Result<(String, Vec<u8>, Vec<u8>),
2222
Ok(result) => result,
2323
Err(e) => {
2424
// no need to zeroize since contents are encrypted
25-
return Err(format!("Error during file reading: {:?}", e));
25+
return Err(format!("Error during file reading: {e:?}"));
2626
}
2727
};
2828
if encrypted_contents.is_empty() {
@@ -49,7 +49,7 @@ pub fn read_from_file(password: &str) -> Result<ReadResult, String> {
4949
Ok(r) => r,
5050
Err(e) => {
5151
contents.zeroize();
52-
return Err(format!("Failed to deserialize database: {:?}", e));
52+
return Err(format!("Failed to deserialize database: {e:?}"));
5353
}
5454
};
5555
OTPDatabase {

src/utils.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn get_default_db_path() -> PathBuf {
3535
None => {
3636
let current_dir = PathBuf::from(".");
3737
if let Some(str_dir) = current_dir.to_str() {
38-
eprintln!("Cannot get home folder, using: {}", str_dir);
38+
eprintln!("Cannot get home folder, using: {str_dir}");
3939
} else {
4040
eprintln!("Cannot get home folder, using");
4141
}
@@ -76,10 +76,7 @@ pub fn password(message: &str, minimum_length: usize) -> String {
7676
loop {
7777
let password = rpassword::prompt_password(message).unwrap();
7878
if password.chars().count() < minimum_length {
79-
println!(
80-
"Please insert a password with at least {} digits.",
81-
minimum_length
82-
);
79+
println!("Please insert a password with at least {minimum_length} digits.");
8380
continue;
8481
}
8582
return password;

0 commit comments

Comments
 (0)