Skip to content

Commit 5933197

Browse files
mmartinvclaude
andcommitted
fix: remove redundant borrows in format! and refactor match to use ?
Remove unnecessary `&` references in format! macro arguments across multiple crates, and simplify a match expression in device_credential_locations.rs to use the `?` operator. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Miguel Martín <mmartinv@redhat.com>
1 parent 21000e5 commit 5933197

6 files changed

Lines changed: 31 additions & 30 deletions

File tree

http-wrapper/src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl ServiceClient {
214214

215215
let url = format!(
216216
"{}/fdo/{}/msg/{}",
217-
&self.base_url,
217+
self.base_url,
218218
self.protocol_version,
219219
OM::message_type() as u8
220220
);

manufacturing-client/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,9 +748,9 @@ impl KeyReference {
748748
let hmac_key_path = env::var("DI_HMAC_KEY_PATH").context("No DI HMAC key path set")?;
749749

750750
let sign_key = fs::read(&sign_key_path)
751-
.with_context(|| format!("Error reading sign key from {}", &sign_key_path))?;
751+
.with_context(|| format!("Error reading sign key from {}", sign_key_path))?;
752752
let hmac_key = fs::read(&hmac_key_path)
753-
.with_context(|| format!("Error reading HMAC key from {}", &hmac_key_path))?;
753+
.with_context(|| format!("Error reading HMAC key from {}", hmac_key_path))?;
754754

755755
let sign_key = PKey::private_key_from_der(&sign_key).context("Error loading sign key")?;
756756

owner-onboarding-server/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ async fn main() -> Result<()> {
408408
.map(|path| -> Result<X5Bag, anyhow::Error> {
409409
let trusted_device_keys = {
410410
let contents = std::fs::read(path)
411-
.with_context(|| format!("Error reading trusted device keys at {}", &path))?;
411+
.with_context(|| format!("Error reading trusted device keys at {}", path))?;
412412
X509::stack_from_pem(&contents).context("Error parsing trusted device keys")?
413413
};
414414

@@ -422,14 +422,14 @@ async fn main() -> Result<()> {
422422
let owner_key = load_private_key(&settings.owner_private_key_path).with_context(|| {
423423
format!(
424424
"Error loading owner key from {}",
425-
&settings.owner_private_key_path
425+
settings.owner_private_key_path
426426
)
427427
})?;
428428
let owner_pubkey = {
429429
let contents = std::fs::read(&settings.owner_public_key_path).with_context(|| {
430430
format!(
431431
"Error reading owner public key from {}",
432-
&settings.owner_public_key_path
432+
settings.owner_public_key_path
433433
)
434434
})?;
435435
PublicKey::try_from(X509::from_pem(&contents).context("Error parsing owner public key")?)

owner-tool/src/main.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ async fn export_manufacturer_vouchers(args: &ExportManufacturerVouchersArguments
647647
let ov = client
648648
.get(format!(
649649
"{}/ov/{}",
650-
&args.manufacturer_server_url, device_guid
650+
args.manufacturer_server_url, device_guid
651651
))
652652
.send()
653653
.await?
@@ -659,7 +659,7 @@ async fn export_manufacturer_vouchers(args: &ExportManufacturerVouchersArguments
659659
let ovs_tar_path = path.join("export.tar");
660660
let mut ovs_tar = File::create(ovs_tar_path)?;
661661
let ovs = client
662-
.post(format!("{}/export", &args.manufacturer_server_url))
662+
.post(format!("{}/export", args.manufacturer_server_url))
663663
.send()
664664
.await?
665665
.bytes()
@@ -682,14 +682,14 @@ fn import_ownership_vouchers(args: &ImportOwnershipVouchersArguments) -> Result<
682682
let ov_path = match &path {
683683
Ok(path) => path.path(),
684684
Err(e) => {
685-
error_buff.push(format!("Error {e} with path {:?}", &path));
685+
error_buff.push(format!("Error {e} with path {:?}", path));
686686
continue;
687687
}
688688
};
689689
let content = match fs::read(&ov_path) {
690690
Ok(value) => value,
691691
Err(e) => {
692-
error_buff.push(format!("Error {e} reading path {:?}", &ov_path));
692+
error_buff.push(format!("Error {e} reading path {:?}", ov_path));
693693
continue;
694694
}
695695
};
@@ -698,7 +698,7 @@ fn import_ownership_vouchers(args: &ImportOwnershipVouchersArguments) -> Result<
698698
Err(e) => {
699699
error_buff.push(format!(
700700
"Error {e} serializing OV contents at path {:?}",
701-
&ov_path
701+
ov_path
702702
));
703703
continue;
704704
}
@@ -712,7 +712,7 @@ fn import_ownership_vouchers(args: &ImportOwnershipVouchersArguments) -> Result<
712712
error_buff.push(format!(
713713
"Error {e} getting a connection from the DB pool with OV {} from path {:?}",
714714
ov.header().guid(),
715-
&ov_path
715+
ov_path
716716
));
717717
continue;
718718
}
@@ -727,7 +727,7 @@ fn import_ownership_vouchers(args: &ImportOwnershipVouchersArguments) -> Result<
727727
error_buff.push(format!(
728728
"Error {e} getting a connection from the DB pool with OV {} from path {:?}",
729729
ov.header().guid(),
730-
&ov_path
730+
ov_path
731731
));
732732
continue;
733733
}
@@ -740,7 +740,7 @@ fn import_ownership_vouchers(args: &ImportOwnershipVouchersArguments) -> Result<
740740
"Error {:?} inserting OV {} from path {:?}",
741741
ret.err(),
742742
ov.header().guid(),
743-
&ov_path
743+
ov_path
744744
));
745745
}
746746
}

rendezvous-server/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ async fn main() -> Result<()> {
9393
.map(|path| -> Result<X5Bag, anyhow::Error> {
9494
let trusted_manufacturer_keys = {
9595
let contents = std::fs::read(&path).with_context(|| {
96-
format!("Error reading trusted manufacturer keys at {}", &path)
96+
format!("Error reading trusted manufacturer keys at {}", path)
9797
})?;
9898
X509::stack_from_pem(&contents)
9999
.context("Error parsing trusted manufacturer keys")?
@@ -111,7 +111,7 @@ async fn main() -> Result<()> {
111111
.map(|path| -> Result<X5Bag, anyhow::Error> {
112112
let trusted_device_keys = {
113113
let contents = std::fs::read(path)
114-
.with_context(|| format!("Error reading trusted device keys at {}", &path))?;
114+
.with_context(|| format!("Error reading trusted device keys at {}", path))?;
115115
X509::stack_from_pem(&contents).context("Error parsing trusted device keys")?
116116
};
117117
X5Bag::with_certs(trusted_device_keys)

util/src/device_credential_locations.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl DeviceCredentialLocation for FileSystemPath {
6060
if Path::new(&self.path).exists() {
6161
Some(Ok(Box::new(self.clone())))
6262
} else {
63-
log::trace!("No (device credential) file exists at {}", &self.path);
63+
log::trace!("No (device credential) file exists at {}", self.path);
6464
None
6565
}
6666
}
@@ -69,17 +69,17 @@ impl DeviceCredentialLocation for FileSystemPath {
6969
impl UsableDeviceCredentialLocation for FileSystemPath {
7070
fn read(&self) -> Result<Box<dyn DeviceCredential>> {
7171
let contents = fs::read(&self.path)
72-
.with_context(|| format!("Error reading (device credential) file at {}", &self.path))?;
72+
.with_context(|| format!("Error reading (device credential) file at {}", self.path))?;
7373
let fdc = FileDeviceCredential::deserialize_data(&contents)
74-
.with_context(|| format!("Error parsing device credential from {}", &self.path))?;
74+
.with_context(|| format!("Error parsing device credential from {}", self.path))?;
7575
Ok(Box::new(fdc))
7676
}
7777

7878
fn deactivate(&self) -> Result<()> {
7979
match self.deactivation_method {
8080
DeactivationMethod::None => Ok(()),
8181
DeactivationMethod::Delete => fs::remove_file(&self.path)
82-
.with_context(|| format!("Error deleting file at {}", &self.path)),
82+
.with_context(|| format!("Error deleting file at {}", self.path)),
8383
DeactivationMethod::Deactivate => self.perform_deactivation(),
8484
}
8585
}
@@ -88,9 +88,9 @@ impl UsableDeviceCredentialLocation for FileSystemPath {
8888
impl FileSystemPath {
8989
fn perform_deactivation(&self) -> Result<()> {
9090
let contents = fs::read(&self.path)
91-
.with_context(|| format!("Error reading (device credential) file at {}", &self.path))?;
91+
.with_context(|| format!("Error reading (device credential) file at {}", self.path))?;
9292
let mut fdc = FileDeviceCredential::deserialize_data(&contents)
93-
.with_context(|| format!("Error parsing device credential from {}", &self.path))?;
93+
.with_context(|| format!("Error parsing device credential from {}", self.path))?;
9494

9595
fdc.active = false;
9696
let new_dc_contents = fdc
@@ -102,7 +102,7 @@ impl FileSystemPath {
102102

103103
fn write(&self, new_contents: Vec<u8>) -> Result<()> {
104104
fs::write(&self.path, new_contents)
105-
.with_context(|| format!("Error writing to file at {}", &self.path))
105+
.with_context(|| format!("Error writing to file at {}", self.path))
106106
}
107107
}
108108

@@ -113,23 +113,24 @@ struct FileSystemPathEnv {
113113

114114
impl DeviceCredentialLocation for FileSystemPathEnv {
115115
fn resolve(&self) -> Option<Result<Box<dyn UsableDeviceCredentialLocation>>> {
116-
let env_val = match env::var_os(&self.env_var) {
117-
None => return None,
118-
Some(v) => match v.into_string() {
116+
let env_val = {
117+
let v = env::var_os(&self.env_var)?;
118+
match v.into_string() {
119119
Ok(s) => s,
120120
Err(_) => return Some(Err(anyhow!("Invalid environment variable value"))),
121-
},
121+
}
122122
};
123-
let deactivation_method = match env::var_os(format!("{}_DELETE", &self.env_var)) {
124-
None => match env::var_os(format!("{}_DEACTIVATE", &self.env_var)) {
123+
124+
let deactivation_method = match env::var_os(format!("{}_DELETE", self.env_var)) {
125+
None => match env::var_os(format!("{}_DEACTIVATE", self.env_var)) {
125126
None => DeactivationMethod::None,
126127
Some(_) => DeactivationMethod::Deactivate,
127128
},
128129
Some(_) => DeactivationMethod::Delete,
129130
};
130131
log::trace!(
131132
"Resolved environment variable {} to filesystem path {} (deactivation method {:?})",
132-
&self.env_var,
133+
self.env_var,
133134
&env_val,
134135
&deactivation_method,
135136
);

0 commit comments

Comments
 (0)