Skip to content

Commit c6b365b

Browse files
authored
Merge pull request #72 from flatcar/dongsu/fix-clippy-1.88
*: fix clippy issues with Rust 1.88+.
2 parents 308c588 + ce3d340 commit c6b365b

File tree

7 files changed

+40
-45
lines changed

7 files changed

+40
-45
lines changed

omaha/src/response.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl FromStr for ActionEvent {
6767
"postinstall" => ActionEvent::PostInstall,
6868
"update" => ActionEvent::Update,
6969

70-
_ => return Err(format!("unknown success action \"{}\"", s)),
70+
_ => return Err(format!("unknown success action \"{s}\"")),
7171
})
7272
}
7373
}
@@ -98,7 +98,7 @@ impl FromStr for SuccessAction {
9898
"exitsilently" => SuccessAction::ExitSilently,
9999
"exitsilentlyonlaunchcmd" => SuccessAction::ExitSilentlyOnLaunchCommand,
100100

101-
_ => return Err(format!("unknown success action \"{}\"", s)),
101+
_ => return Err(format!("unknown success action \"{s}\"")),
102102
})
103103
}
104104
}

src/bin/download_sysext.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl Package<'_> {
118118
) {
119119
Ok(ok) => ok,
120120
Err(err) => {
121-
error!("Downloading failed with error {}", err);
121+
error!("Downloading failed with error {err}");
122122
self.status = PackageStatus::DownloadFailed;
123123
bail!("unable to download data(url {})", self.url);
124124
}
@@ -130,10 +130,10 @@ impl Package<'_> {
130130

131131
fn verify_checksum(&mut self, calculated_sha256: omaha::Hash<omaha::Sha256>, calculated_sha1: omaha::Hash<omaha::Sha1>) -> bool {
132132
debug!(" expected sha256: {:?}", self.hash_sha256);
133-
debug!(" calculated sha256: {}", calculated_sha256);
133+
debug!(" calculated sha256: {calculated_sha256}");
134134
debug!(" sha256 match? {}", self.hash_sha256 == Some(calculated_sha256.clone()));
135135
debug!(" expected sha1: {:?}", self.hash_sha1);
136-
debug!(" calculated sha1: {}", calculated_sha1);
136+
debug!(" calculated sha1: {calculated_sha1}");
137137
debug!(" sha1 match? {}", self.hash_sha1 == Some(calculated_sha1.clone()));
138138

139139
if self.hash_sha256.is_some() && self.hash_sha256 != Some(calculated_sha256.clone()) || self.hash_sha1.is_some() && self.hash_sha1 != Some(calculated_sha1.clone()) {
@@ -198,7 +198,7 @@ impl Package<'_> {
198198
}
199199
};
200200

201-
println!("Parsed and verified signature data from file {:?}", from_path);
201+
println!("Parsed and verified signature data from file {from_path:?}");
202202

203203
self.status = PackageStatus::Verified;
204204
Ok(datablobspath)
@@ -255,7 +255,7 @@ where
255255
U: reqwest::IntoUrl + From<U> + std::clone::Clone + std::fmt::Debug,
256256
Url: From<U>,
257257
{
258-
let r = ue_rs::download_and_hash(client, input_url.clone(), path, None, None).context(format!("unable to download data(url {:?})", input_url))?;
258+
let r = ue_rs::download_and_hash(client, input_url.clone(), path, None, None).context(format!("unable to download data(url {input_url:?})"))?;
259259

260260
Ok(Package {
261261
name: Cow::Borrowed(path.file_name().unwrap_or(OsStr::new("fakepackage")).to_str().unwrap_or("fakepackage")),
@@ -280,7 +280,7 @@ fn do_download_verify(pkg: &mut Package<'_>, output_filename: Option<String>, ou
280280
let datablobspath = pkg.verify_signature_on_disk(&pkg_unverified, pubkey_file).context(format!("unable to verify signature \"{}\"", pkg.name))?;
281281

282282
// write extracted data into the final data.
283-
debug!("data blobs written into file {:?}", pkg_verified);
283+
debug!("data blobs written into file {pkg_verified:?}");
284284
fs::rename(datablobspath, pkg_verified)?;
285285

286286
Ok(())
@@ -339,7 +339,7 @@ fn main() -> Result<(), Box<dyn Error>> {
339339
env_logger::init();
340340

341341
let args: Args = argh::from_env();
342-
println!("{:?}", args);
342+
println!("{args:?}");
343343

344344
if args.payload_url.is_none() && !args.take_first_match && args.target_filename.is_some() {
345345
return Err("--target-filename can only be specified with --take-first-match".into());
@@ -411,7 +411,7 @@ fn main() -> Result<(), Box<dyn Error>> {
411411
};
412412

413413
let response_text = res_local.ok_or(anyhow!("failed to get response text"))?;
414-
debug!("response_text: {:?}", response_text);
414+
debug!("response_text: {response_text:?}");
415415

416416
////
417417
// parse response
@@ -420,7 +420,7 @@ fn main() -> Result<(), Box<dyn Error>> {
420420

421421
let mut pkgs_to_dl = get_pkgs_to_download(&resp, &glob_set)?;
422422

423-
debug!("pkgs:\n\t{:#?}", pkgs_to_dl);
423+
debug!("pkgs:\n\t{pkgs_to_dl:#?}");
424424
debug!("");
425425

426426
////

src/download.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn hash_on_disk<T: omaha::HashAlgo>(path: &Path, maxlen: Option<usize>) -> R
4949

5050
let mut databuf = vec![0u8; chunklen];
5151

52-
freader.read_exact(&mut databuf).context(format!("failed to read_exact(chunklen {:?})", chunklen))?;
52+
freader.read_exact(&mut databuf).context(format!("failed to read_exact(chunklen {chunklen:?})"))?;
5353

5454
maxlen_to_read -= chunklen;
5555

@@ -97,11 +97,11 @@ where
9797
let calculated_sha256 = hash_on_disk::<omaha::Sha256>(path, None)?;
9898
let calculated_sha1 = hash_on_disk::<omaha::Sha1>(path, None)?;
9999

100-
debug!(" expected sha256: {:?}", expected_sha256);
101-
debug!(" calculated sha256: {}", calculated_sha256);
100+
debug!(" expected sha256: {expected_sha256:?}");
101+
debug!(" calculated sha256: {calculated_sha256}");
102102
debug!(" sha256 match? {}", expected_sha256 == Some(calculated_sha256.clone()));
103-
debug!(" expected sha1: {:?}", expected_sha1);
104-
debug!(" calculated sha1: {}", calculated_sha1);
103+
debug!(" expected sha1: {expected_sha1:?}");
104+
debug!(" calculated sha1: {calculated_sha1}");
105105
debug!(" sha1 match? {}", expected_sha1 == Some(calculated_sha1.clone()));
106106

107107
if expected_sha256.is_some() && expected_sha256 != Some(calculated_sha256.clone()) {

src/request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn perform(client: &reqwest::blocking::Client, parameters: Parameters<'_>) -
7171
};
7272

7373
// TODO: remove
74-
println!("request body:\n\t{}", req_body);
74+
println!("request body:\n\t{req_body}");
7575
println!();
7676

7777
#[rustfmt::skip]

test/crau_verify.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,17 @@ fn main() -> Result<(), Box<dyn Error>> {
5757
let sigdata = match delta_update::parse_signature_data(&sigbytes, hdhashvec.as_slice(), PUBKEY_FILE) {
5858
Ok(data) => data,
5959
_ => {
60-
return Err(format!(
61-
"unable to parse and verify signature, sigbytes ({:?}), hdhash ({:?}), pubkey_path ({:?})",
62-
sigbytes, hdhash, PUBKEY_FILE,
63-
)
64-
.into());
60+
return Err(format!("unable to parse and verify signature, sigbytes ({sigbytes:?}), hdhash ({hdhash:?}), pubkey_path ({PUBKEY_FILE:?})",).into());
6561
}
6662
};
6763

68-
println!("Parsed signature data from file {:?}", srcpath);
64+
println!("Parsed signature data from file {srcpath:?}");
6965

7066
// Store signature into a file.
7167
let mut sigfile = fs::File::create(sigpath.clone())?;
7268
let _ = sigfile.write_all(sigdata.as_slice());
7369

74-
println!("Wrote signature data into file {:?}", sigpath);
70+
println!("Wrote signature data into file {sigpath:?}");
7571

7672
Ok(())
7773
}

update-format-crau/src/delta_update.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ pub fn get_header_data_length(header: &DeltaUpdateFileHeader, manifest: &proto::
114114
// Return path to data blobs, without header, manifest, or signatures.
115115
pub fn get_data_blobs<'a>(f: &'a File, header: &'a DeltaUpdateFileHeader, manifest: &proto::DeltaArchiveManifest, tmpfile: &Path) -> Result<()> {
116116
let tmpdir = tmpfile.parent().ok_or(anyhow!("unable to get parent directory"))?;
117-
fs::create_dir_all(tmpdir).context(format!("failed to create directory {:?}", tmpdir))?;
118-
let mut outfile = File::create(tmpfile).context(format!("failed to create file {:?}", tmpfile))?;
117+
fs::create_dir_all(tmpdir).context(format!("failed to create directory {tmpdir:?}"))?;
118+
let mut outfile = File::create(tmpfile).context(format!("failed to create file {tmpfile:?}"))?;
119119

120120
// Read from the beginning of header, which means buffer including only data blobs.
121121
// It means it is necessary to call header.translate_offset(), in contrast to
@@ -137,21 +137,20 @@ pub fn get_data_blobs<'a>(f: &'a File, header: &'a DeltaUpdateFileHeader, manife
137137

138138
let translated_offset = header.translate_offset(data_offset.into());
139139
f.read_exact_at(&mut partdata, translated_offset).context(format!(
140-
"failed to read data with length {:?} at {:?}",
141-
data_length, translated_offset
140+
"failed to read data with length {data_length:?} at {translated_offset:?}",
142141
))?;
143142

144143
// In case of bzip2-compressed chunks, extract.
145144
if pop.type_.ok_or(anyhow!("unable to get type_ from partition operations"))? == proto::install_operation::Type::REPLACE_BZ.into() {
146145
let mut bzdecoder = BzDecoder::new(&partdata[..]);
147146
let mut partdata_unpacked = Vec::new();
148-
bzdecoder.read_to_end(&mut partdata_unpacked).context(format!("failed to unpack bzip2ed data at offset {:?}", translated_offset))?;
147+
bzdecoder.read_to_end(&mut partdata_unpacked).context(format!("failed to unpack bzip2ed data at offset {translated_offset:?}"))?;
149148

150-
outfile.write_all_at(&partdata_unpacked, start_block).context(format!("failed to copy unpacked data at offset {:?}", translated_offset))?;
149+
outfile.write_all_at(&partdata_unpacked, start_block).context(format!("failed to copy unpacked data at offset {translated_offset:?}"))?;
151150
} else {
152-
outfile.write_all_at(&partdata, start_block).context(format!("failed to copy plain data at offset {:?}", translated_offset))?;
151+
outfile.write_all_at(&partdata, start_block).context(format!("failed to copy plain data at offset {translated_offset:?}"))?;
153152
}
154-
outfile.flush().context(format!("failed to flush at offset {:?}", translated_offset))?;
153+
outfile.flush().context(format!("failed to flush at offset {translated_offset:?}"))?;
155154
}
156155

157156
Ok(())
@@ -204,23 +203,23 @@ pub fn verify_sig_pubkey(digest: &[u8], sig: &Signature, pubkeyfile: &str) -> Re
204203
_ => bail!("empty signature data, nothing to verify"),
205204
};
206205

207-
debug!("digest: {:?}", digest);
206+
debug!("digest: {digest:?}");
208207
debug!("data: {:?}", sig.data());
209208
debug!("special_fields: {:?}", sig.special_fields());
210209

211210
// verify signature with pubkey
212211
let pkcspem_pubkey = match get_public_key_pkcs_pem(pubkeyfile, KeyTypePkcs8) {
213212
Ok(key) => key,
214213
Err(err) => {
215-
bail!("failed to get PKCS8 PEM public key ({:?}) with error {:?}", pubkeyfile, err);
214+
bail!("failed to get PKCS8 PEM public key ({pubkeyfile:?}) with error {err:?}");
216215
}
217216
};
218217

219218
let res_verify = verify_sig::verify_rsa_pkcs_prehash(digest, sig.data(), pkcspem_pubkey);
220219
match res_verify {
221220
Ok(res_verify) => res_verify,
222221
Err(err) => {
223-
bail!("verify_rsa_pkcs signature ({:?}) failed with error {:?}", sig, err);
222+
bail!("verify_rsa_pkcs signature ({sig:?}) failed with error {err:?}");
224223
}
225224
};
226225

update-format-crau/src/verify_sig.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn verify_rsa_pkcs_buf(databuf: &[u8], signature: &[u8], public_key: RsaPubl
4545
databuf,
4646
&pkcs1v15::Signature::try_from(signature).context(anyhow!("unable to convert signature into pkcs1v15::Signature"))?,
4747
)
48-
.context(format!("failed to verify signature ({:?})", signature))
48+
.context(format!("failed to verify signature ({signature:?})"))
4949
}
5050

5151
// Takes a data buffer, signature and a public key, to verify the data
@@ -62,37 +62,37 @@ pub fn verify_rsa_pkcs_prehash(digestbuf: &[u8], signature: &[u8], public_key: R
6262
digestbuf,
6363
&pkcs1v15::Signature::try_from(signature).context(anyhow!("unable to convert signature into pkcs1v15::Signature"))?,
6464
)
65-
.context(format!("failed to verify_prehash signature ({:?})", signature))
65+
.context(format!("failed to verify_prehash signature ({signature:?})"))
6666
}
6767

6868
pub fn get_private_key_pkcs_pem(private_key_path: &str, key_type: KeyType) -> Result<RsaPrivateKey> {
69-
let private_key_buf = fs::read_to_string(private_key_path).context(format!("failed to read private key from path {:?}", private_key_path))?;
69+
let private_key_buf = fs::read_to_string(private_key_path).context(format!("failed to read private key from path {private_key_path:?}"))?;
7070
let out_key = match key_type {
7171
KeyType::KeyTypePkcs1 => RsaPrivateKey::from_pkcs1_pem(private_key_buf.as_str()).or_else(|error| {
72-
bail!("failed to parse PKCS1 PEM message: {:?}", error);
72+
bail!("failed to parse PKCS1 PEM message: {error:?}");
7373
}),
7474
KeyType::KeyTypePkcs8 => RsaPrivateKey::from_pkcs8_pem(private_key_buf.as_str()).or_else(|error| {
75-
bail!("failed to parse PKCS8 PEM message: {:?}", error);
75+
bail!("failed to parse PKCS8 PEM message: {error:?}");
7676
}),
7777
KeyType::KeyTypeNone => {
78-
bail!("invalid key type: {:?}", key_type);
78+
bail!("invalid key type: {key_type:?}");
7979
}
8080
};
8181

8282
out_key
8383
}
8484

8585
pub fn get_public_key_pkcs_pem(public_key_path: &str, key_type: KeyType) -> Result<RsaPublicKey> {
86-
let public_key_buf = fs::read_to_string(public_key_path).context(format!("failed to read public key from path {:?}", public_key_path))?;
86+
let public_key_buf = fs::read_to_string(public_key_path).context(format!("failed to read public key from path {public_key_path:?}"))?;
8787
let out_key = match key_type {
8888
KeyType::KeyTypePkcs1 => RsaPublicKey::from_pkcs1_pem(public_key_buf.as_str()).or_else(|error| {
89-
bail!("failed to parse PKCS1 PEM message: {:?}", error);
89+
bail!("failed to parse PKCS1 PEM message: {error:?}");
9090
}),
9191
KeyType::KeyTypePkcs8 => RsaPublicKey::from_public_key_pem(public_key_buf.as_str()).or_else(|error| {
92-
bail!("failed to parse PKCS8 PEM message: {:?}", error);
92+
bail!("failed to parse PKCS8 PEM message: {error:?}");
9393
}),
9494
KeyType::KeyTypeNone => {
95-
bail!("invalid key type: {:?}", key_type);
95+
bail!("invalid key type: {key_type:?}");
9696
}
9797
};
9898

0 commit comments

Comments
 (0)