Update dependencies and fix most pedantic clippy warnings

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
This commit is contained in:
Andrew Gunnerson
2024-12-08 18:45:47 -05:00
parent 421b0a5207
commit b351d47f28
26 changed files with 184 additions and 185 deletions
+1 -1
View File
@@ -13,4 +13,4 @@ jobs:
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Run cargo-deny
uses: EmbarkStudios/cargo-deny-action@2d8c9929d8f9f42bedba73f1287cb0b479f07acb # v2.0.3
uses: EmbarkStudios/cargo-deny-action@e2f4ede4a4e60ea15ff31bc0647485d80c66cfba # v2.0.4
Generated
+61 -61
View File
@@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4
[[package]]
name = "adler2"
@@ -85,9 +85,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.93"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775"
checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7"
[[package]]
name = "arbitrary"
@@ -153,14 +153,14 @@ dependencies = [
"sha1",
"sha2",
"tempfile",
"thiserror 2.0.3",
"thiserror 2.0.6",
"toml_edit",
"topological-sort",
"tracing",
"tracing-subscriber",
"x509-cert",
"zerocopy 0.8.11",
"zerocopy-derive 0.8.11",
"zerocopy 0.8.13",
"zerocopy-derive 0.8.13",
"zip",
]
@@ -253,9 +253,9 @@ dependencies = [
[[package]]
name = "cap-primitives"
version = "3.4.1"
version = "3.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82fa6c3f9773feab88d844aa50035a33fb6e7e7426105d2f4bb7aadc42a5f89a"
checksum = "8fc15faeed2223d8b8e8cc1857f5861935a06d06713c4ac106b722ae9ce3c369"
dependencies = [
"ambient-authority",
"fs-set-times",
@@ -264,15 +264,15 @@ dependencies = [
"ipnet",
"maybe-owned",
"rustix",
"windows-sys 0.52.0",
"windows-sys 0.59.0",
"winx",
]
[[package]]
name = "cap-std"
version = "3.4.1"
version = "3.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f71b70818556b4fe2a10c7c30baac3f5f45e973f49fc2673d7c75c39d0baf5b"
checksum = "c3dbd3e8e8d093d6ccb4b512264869e1281cdb032f7940bd50b2894f96f25609"
dependencies = [
"cap-primitives",
"io-extras",
@@ -282,9 +282,9 @@ dependencies = [
[[package]]
name = "cap-tempfile"
version = "3.4.1"
version = "3.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "200812b29d9de495a9ba97dee1737f7def8907de53a0962843b6a955df921e22"
checksum = "1ffa1c0edc4958d742bab2e903e52f93ccee482072680e08d6ce0784873e65b1"
dependencies = [
"cap-std",
"rand",
@@ -303,9 +303,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.2.2"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f34d93e62b03caf570cccc334cbc6c2fceca82f39211051345108adcba3eebdc"
checksum = "27f657647bcff5394bf56c7317665bbf790a137a50eaaa5c6bfbb9e27a518f2d"
dependencies = [
"jobserver",
"libc",
@@ -336,9 +336,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.5.21"
version = "4.5.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f"
checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84"
dependencies = [
"clap_builder",
"clap_derive",
@@ -346,9 +346,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.5.21"
version = "4.5.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec"
checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838"
dependencies = [
"anstream",
"anstyle",
@@ -379,9 +379,9 @@ dependencies = [
[[package]]
name = "clap_lex"
version = "0.7.3"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7"
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
[[package]]
name = "cms"
@@ -604,9 +604,9 @@ checksum = "cfc25fd417983cc7f203394ebb89eba18e2df1b0ac1be2673091b5aca52b595f"
[[package]]
name = "fastrand"
version = "2.2.0"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4"
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]]
name = "fixedbitset"
@@ -638,13 +638,13 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "fs-set-times"
version = "0.20.1"
version = "0.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "033b337d725b97690d86893f9de22b67b80dcc4e9ad815f348254c38119db8fb"
checksum = "5e2e6123af26f0f2c51cc66869137080199406754903cc926a7690401ce09cb4"
dependencies = [
"io-lifetimes",
"rustix",
"windows-sys 0.52.0",
"windows-sys 0.59.0",
]
[[package]]
@@ -769,19 +769,19 @@ dependencies = [
[[package]]
name = "io-extras"
version = "0.18.3"
version = "0.18.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d45fd7584f9b67ac37bc041212d06bfac0700b36456b05890d36a3b626260eb"
checksum = "2285ddfe3054097ef4b2fe909ef8c3bcd1ea52a8f0d274416caebeef39f04a65"
dependencies = [
"io-lifetimes",
"windows-sys 0.52.0",
"windows-sys 0.59.0",
]
[[package]]
name = "io-lifetimes"
version = "2.0.3"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a611371471e98973dbcab4e0ec66c31a10bc356eeb4d54a0e05eac8158fe38c"
checksum = "06432fb54d3be7964ecd3649233cddf80db2832f47fec34c01f65b3d9d774983"
[[package]]
name = "ipnet"
@@ -883,9 +883,9 @@ dependencies = [
[[package]]
name = "logos-codegen"
version = "0.14.2"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b32eb6b5f26efacd015b000bfc562186472cd9b34bdba3f6b264e2a052676d10"
checksum = "5f3303189202bb8a052bcd93d66b6c03e6fe70d9c7c47c0ea5e974955e54c876"
dependencies = [
"beef",
"fnv",
@@ -893,14 +893,15 @@ dependencies = [
"proc-macro2",
"quote",
"regex-syntax",
"rustc_version",
"syn 2.0.90",
]
[[package]]
name = "logos-derive"
version = "0.14.2"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e5d0c5463c911ef55624739fc353238b4e310f0144be1f875dc42fec6bfd5ec"
checksum = "774a1c225576486e4fdf40b74646f672c542ca3608160d348749693ae9d456e6"
dependencies = [
"logos-codegen",
]
@@ -1057,9 +1058,9 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "passterm"
version = "2.0.4"
version = "2.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1e7a4c22a6cce262e8c126b3052e6baf05d4dd5699ef23ed6dadd85c2a1194a"
checksum = "150ca2316c7813c688677784f20bb0a9efab639415ae1961869863ee99a81e51"
dependencies = [
"libc",
]
@@ -1215,9 +1216,9 @@ dependencies = [
[[package]]
name = "prost"
version = "0.13.3"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b0487d90e047de87f984913713b85c601c05609aad5b0df4b4573fbf69aa13f"
checksum = "2c0fef6c4230e4ccf618a35c59d7ede15dea37de8427500f50aff708806e42ec"
dependencies = [
"bytes",
"prost-derive",
@@ -1225,11 +1226,10 @@ dependencies = [
[[package]]
name = "prost-build"
version = "0.13.3"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c1318b19085f08681016926435853bbf7858f9c082d0999b80550ff5d9abe15"
checksum = "d0f3e5beed80eb580c68e2c600937ac2c4eedabdfd5ef1e5b7ea4f3fba84497b"
dependencies = [
"bytes",
"heck",
"itertools",
"log",
@@ -1246,9 +1246,9 @@ dependencies = [
[[package]]
name = "prost-derive"
version = "0.13.3"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5"
checksum = "157c5a9d7ea5c2ed2d9fb8f495b64759f7816c7eaea54ba3978f0d63000162e3"
dependencies = [
"anyhow",
"itertools",
@@ -1259,9 +1259,9 @@ dependencies = [
[[package]]
name = "prost-reflect"
version = "0.14.2"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b7535b02f0e5efe3e1dbfcb428be152226ed0c66cad9541f2274c8ba8d4cd40"
checksum = "20ae544fca2892fd4b7e9ff26cba1090cedf1d4d95c2aded1af15d2f93f270b8"
dependencies = [
"logos",
"miette",
@@ -1272,9 +1272,9 @@ dependencies = [
[[package]]
name = "prost-types"
version = "0.13.3"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4759aa0d3a6232fb8dbdb97b61de2c20047c68aca932c7ed76da9d788508d670"
checksum = "cc2f1e56baa61e93533aebc21af4d2134b70f66275e0fcdf3cbe43d77ff7e8fc"
dependencies = [
"prost",
]
@@ -1655,11 +1655,11 @@ dependencies = [
[[package]]
name = "thiserror"
version = "2.0.3"
version = "2.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa"
checksum = "8fec2a1820ebd077e2b90c4df007bebf344cd394098a13c563957d0afc83ea47"
dependencies = [
"thiserror-impl 2.0.3",
"thiserror-impl 2.0.6",
]
[[package]]
@@ -1675,9 +1675,9 @@ dependencies = [
[[package]]
name = "thiserror-impl"
version = "2.0.3"
version = "2.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568"
checksum = "d65750cab40f4ff1929fb1ba509e9914eb756131cef4210da8d5d700d26f6312"
dependencies = [
"proc-macro2",
"quote",
@@ -1982,12 +1982,12 @@ dependencies = [
[[package]]
name = "winx"
version = "0.36.3"
version = "0.36.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9643b83820c0cd246ecabe5fa454dd04ba4fa67996369466d0747472d337346"
checksum = "3f3fd376f71958b862e7afb20cfe5a22830e1963462f3a17f49d82a6c1d1f42d"
dependencies = [
"bitflags",
"windows-sys 0.52.0",
"windows-sys 0.59.0",
]
[[package]]
@@ -2026,11 +2026,11 @@ dependencies = [
[[package]]
name = "zerocopy"
version = "0.8.11"
version = "0.8.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cce3b5629d87654b53a49002acc2ce64aa5aa7255f5c718374a37ac7fd98c218"
checksum = "67914ab451f3bfd2e69e5e9d2ef3858484e7074d63f204fd166ec391b54de21d"
dependencies = [
"zerocopy-derive 0.8.11",
"zerocopy-derive 0.8.13",
]
[[package]]
@@ -2046,9 +2046,9 @@ dependencies = [
[[package]]
name = "zerocopy-derive"
version = "0.8.11"
version = "0.8.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74a82c26c3986af2623ec9eb890ff4aa19c006e30a1133dc9bd1830ec1612e20"
checksum = "7988d73a4303ca289df03316bc490e934accf371af6bc745393cf3c2c5c4f25d"
dependencies = [
"proc-macro2",
"quote",
+8
View File
@@ -8,3 +8,11 @@ version = "3.9.0"
license = "GPL-3.0-only"
edition = "2021"
repository = "https://github.com/chenxiaolong/avbroot"
[workspace.lints.clippy]
cast_lossless = "deny"
missing_fields_in_debug = "warn"
redundant_clone = "deny"
[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(fuzzing)'] }
+2 -2
View File
@@ -86,5 +86,5 @@ assert_matches = "1.5.0"
[features]
static = ["bzip2/static", "liblzma/static"]
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(fuzzing)'] }
[lints]
workspace = true
+9 -14
View File
@@ -340,7 +340,13 @@ fn sign_or_clear(info: &mut AvbInfo, orig_header: &Header, key_group: &KeyGroup)
}
let originally_signed = !info.header.signature.is_empty();
let mut sign_action = if originally_signed && &info.header != orig_header {
let sign_action = if key_group.force {
if key_group.key.is_some() {
SignAction::Sign
} else {
SignAction::Clear
}
} else if originally_signed && &info.header != orig_header {
SignAction::Sign
} else {
// If the original image was signed, we can preserve the existing
@@ -349,14 +355,6 @@ fn sign_or_clear(info: &mut AvbInfo, orig_header: &Header, key_group: &KeyGroup)
SignAction::None
};
if key_group.force {
sign_action = if key_group.key.is_some() {
SignAction::Sign
} else {
SignAction::Clear
};
}
match sign_action {
SignAction::None => {
if originally_signed {
@@ -521,10 +519,7 @@ fn verify_and_repair(
cancel_signal: &AtomicBool,
) -> Result<()> {
let _span = debug_span!("image", name = name.unwrap_or_default()).entered();
let suffix = match name {
Some(n) => format!(" for: {n}"),
None => String::new(),
};
let suffix = name.map_or_else(String::new, |n| format!(" for: {n}"));
match descriptor {
AppendedDescriptorRef::HashTree(d) => {
@@ -538,7 +533,7 @@ fn verify_and_repair(
d.repair(&file, &file, cancel_signal)
.with_context(|| format!("Failed to repair data{suffix}"))?;
d.verify(&file, cancel_signal).map(|_| {
d.verify(&file, cancel_signal).inspect(|()| {
info!("Successfully repaired data{suffix}");
})
}
+10 -13
View File
@@ -129,22 +129,19 @@ fn split_extents(extents: &[Extent]) -> Vec<CopyExtent> {
/// Use the CLI-specified slot or automatically select one if all slots are
/// identical.
fn get_slot_number(metadata: &Metadata, cli_slot: Option<u32>) -> Result<usize> {
match cli_slot {
Some(n) => {
let n = n as usize;
if n >= metadata.slots.len() {
bail!("Slot out of range: {n}");
}
Ok(n)
if let Some(n) = cli_slot {
let n = n as usize;
if n >= metadata.slots.len() {
bail!("Slot out of range: {n}");
}
None => {
if metadata.slots.windows(2).any(|w| w[0] != w[1]) {
bail!("A slot must be specified because they are not all identical");
}
Ok(0)
Ok(n)
} else {
if metadata.slots.windows(2).any(|w| w[0] != w[1]) {
bail!("A slot must be specified because they are not all identical");
}
Ok(0)
}
}
+9 -11
View File
@@ -8,7 +8,6 @@ use std::{
fmt::Display,
fs::{self, File},
io::{self, BufReader, BufWriter, Read, Seek, SeekFrom, Write},
mem,
ops::Range,
path::{Path, PathBuf},
sync::{atomic::AtomicBool, Mutex},
@@ -193,7 +192,7 @@ fn open_input_files(
fn patch_boot_images<'a, 'b: 'a>(
required_images: &'b RequiredImages,
input_files: &mut HashMap<String, InputFile>,
boot_patchers: Vec<Box<dyn BootImagePatch + Sync>>,
boot_patchers: &[Box<dyn BootImagePatch + Sync>],
key_avb: &RsaSigningKey,
cancel_signal: &AtomicBool,
) -> Result<()> {
@@ -219,7 +218,7 @@ fn patch_boot_images<'a, 'b: 'a>(
WriteSeekReopen::reopen_boxed(&input_file.file)
},
key_avb,
&boot_patchers,
boot_patchers,
cancel_signal,
)
.with_context(|| {
@@ -348,7 +347,7 @@ fn ensure_partitions_protected(
/// determine the order to patch the vbmeta images so that it can be done in a
/// single pass.
fn get_vbmeta_patch_order(
images: &mut HashMap<String, InputFile>,
images: &HashMap<String, InputFile>,
vbmeta_headers: &HashMap<String, Header>,
) -> Result<Vec<(String, HashSet<String>)>> {
let mut dep_graph = HashMap::<&str, HashSet<String>>::new();
@@ -722,7 +721,7 @@ fn patch_ota_payload(
payload: &(dyn ReadSeekReopen + Sync),
writer: impl Write,
external_images: &HashMap<String, PathBuf>,
boot_patchers: Vec<Box<dyn BootImagePatch + Sync>>,
boot_patchers: &[Box<dyn BootImagePatch + Sync>],
clear_vbmeta_flags: bool,
key_avb: &RsaSigningKey,
key_ota: &RsaSigningKey,
@@ -794,7 +793,7 @@ fn patch_ota_payload(
ensure_partitions_protected(&required_images, &vbmeta_headers)?;
let mut vbmeta_order = get_vbmeta_patch_order(&mut input_files, &vbmeta_headers)?;
let mut vbmeta_order = get_vbmeta_patch_order(&input_files, &vbmeta_headers)?;
info!(
"Patching vbmeta images: {}",
@@ -914,7 +913,7 @@ fn patch_ota_zip(
zip_reader: &mut ZipArchive<impl Read + Seek>,
mut zip_writer: &mut ZipWriter<impl Write>,
external_images: &HashMap<String, PathBuf>,
mut boot_patchers: Vec<Box<dyn BootImagePatch + Sync>>,
boot_patchers: &[Box<dyn BootImagePatch + Sync>],
clear_vbmeta_flags: bool,
zip_mode: ZipMode,
key_avb: &RsaSigningKey,
@@ -1036,8 +1035,7 @@ fn patch_ota_zip(
&payload_reader,
&mut writer,
external_images,
// There's only one payload in the OTA.
mem::take(&mut boot_patchers),
boot_patchers,
clear_vbmeta_flags,
key_avb,
key_ota,
@@ -1347,7 +1345,7 @@ pub fn patch_subcommand(cli: &PatchCli, cancel_signal: &AtomicBool) -> Result<()
&mut zip_reader,
&mut zip_writer,
&external_images,
boot_patchers,
&boot_patchers,
cli.clear_vbmeta_flags,
cli.zip_mode,
&key_avb,
@@ -1633,7 +1631,7 @@ pub fn verify_subcommand(cli: &VerifyCli, cancel_signal: &AtomicBool) -> Result<
);
} else if let Some(p) = &cli.cert_ota {
let verify_cert = crypto::read_pem_cert_file(p)
.with_context(|| format!("Failed to load certificate: {:?}", p))?;
.with_context(|| format!("Failed to load certificate: {p:?}"))?;
if embedded_cert != verify_cert {
bail!("OTA has a valid signature, but was not signed with: {p:?}");
+5 -5
View File
@@ -28,7 +28,7 @@ use crate::{
struct CompactView<'a, T>(&'a [T]);
impl<'a, T: fmt::Debug> fmt::Debug for CompactView<'a, T> {
impl<T: fmt::Debug> fmt::Debug for CompactView<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut list = f.debug_list();
@@ -110,7 +110,7 @@ fn split_chunks(chunks: &[Chunk], block_size: u32) -> Vec<Chunk> {
#[cfg(any(target_os = "linux", target_os = "android"))]
fn find_allocated_regions(
path: &Path,
reader: &mut File,
reader: &File,
cancel_signal: &AtomicBool,
) -> Result<Vec<Range<u64>>> {
use rustix::{fs::SeekFrom, io::Errno};
@@ -122,13 +122,13 @@ fn find_allocated_regions(
loop {
stream::check_cancel(cancel_signal)?;
start = match rustix::fs::seek(&*reader, SeekFrom::Data(end as i64)) {
start = match rustix::fs::seek(reader, SeekFrom::Data(end as i64)) {
Ok(offset) => offset,
Err(e) if e == Errno::NXIO => break,
Err(e) => return Err(e).with_context(|| format!("Failed to seek to data: {path:?}")),
};
end = rustix::fs::seek(&*reader, SeekFrom::Hole(start as i64))
end = rustix::fs::seek(reader, SeekFrom::Hole(start as i64))
.with_context(|| format!("Failed to seek to hole: {path:?}"))?;
result.push(start..end);
@@ -375,7 +375,7 @@ fn pack_subcommand(
} else {
#[cfg(any(target_os = "linux", target_os = "android"))]
{
let regions = find_allocated_regions(&cli.input, &mut reader, cancel_signal)?;
let regions = find_allocated_regions(&cli.input, &reader, cancel_signal)?;
(regions, false)
}
+2 -2
View File
@@ -235,8 +235,8 @@ impl RsaSigningKey {
/// Get the public key portion of the signing key.
pub fn to_public_key(&self) -> RsaPublicKey {
match self {
RsaSigningKey::Internal(key) => key.to_public_key(),
RsaSigningKey::External { public_key, .. } => public_key.clone(),
Self::Internal(key) => key.to_public_key(),
Self::External { public_key, .. } => public_key.clone(),
}
}
+1 -1
View File
@@ -66,7 +66,7 @@ where
{
struct EscapedStrVisitor<T>(PhantomData<T>);
impl<'de, T> Visitor<'de> for EscapedStrVisitor<T>
impl<T> Visitor<'_> for EscapedStrVisitor<T>
where
T: FromEscaped,
<T as FromEscaped>::Error: fmt::Display,
+13 -16
View File
@@ -534,27 +534,24 @@ impl HashTreeDescriptor {
let parity: u8 = util::try_cast(self.fec_num_roots)
.map_err(|e| Error::IntOutOfBounds("HashTreeDescriptor::fec_num_roots", e))?;
let fec_data = match ranges {
Some(r) => {
let mut r_with_hash_tree = r.to_vec();
r_with_hash_tree.push(self.tree_offset..self.tree_offset + tree_size);
let fec_data = if let Some(r) = ranges {
let mut r_with_hash_tree = r.to_vec();
r_with_hash_tree.push(self.tree_offset..self.tree_offset + tree_size);
let (fec, fec_size) = self.get_fec()?;
let (fec, fec_size) = self.get_fec()?;
let mut reader = input.reopen_boxed()?;
reader.seek(SeekFrom::Start(self.fec_offset))?;
let mut reader = input.reopen_boxed()?;
reader.seek(SeekFrom::Start(self.fec_offset))?;
let mut fec_data = reader.read_vec_exact(fec_size)?;
let mut fec_data = reader.read_vec_exact(fec_size)?;
fec.update(input, &r_with_hash_tree, &mut fec_data, cancel_signal)?;
fec.update(input, &r_with_hash_tree, &mut fec_data, cancel_signal)?;
fec_data
}
None => {
// The FEC covers the hash tree as well.
let fec = Fec::new(self.image_size + tree_size, self.data_block_size, parity)?;
fec.generate(input, cancel_signal)?
}
fec_data
} else {
// The FEC covers the hash tree as well.
let fec = Fec::new(self.image_size + tree_size, self.data_block_size, parity)?;
fec.generate(input, cancel_signal)?
};
// Already seeked to FEC.
+2 -2
View File
@@ -218,7 +218,7 @@ impl CpioEntryData {
}
fn is_size(&self) -> bool {
matches!(self, CpioEntryData::Size(_))
matches!(self, Self::Size(_))
}
}
@@ -680,7 +680,7 @@ pub fn load(
stream::check_cancel(cancel_signal)?;
if entry.file_type != CpioEntryType::Directory && entry.nlink > 1 {
return Err(Error::HardLinksNotSupported(entry.path.clone()));
return Err(Error::HardLinksNotSupported(entry.path));
}
if let CpioEntryData::Size(s) = entry.data {
+1 -1
View File
@@ -97,7 +97,7 @@ impl Codeword {
&mut self.data[..usize::from(self.rs_k)]
}
fn parity(&mut self) -> &[u8] {
fn parity(&self) -> &[u8] {
&self.data[usize::from(self.rs_k)..]
}
+5 -4
View File
@@ -189,7 +189,7 @@ impl HashTree {
cancel_signal: &AtomicBool,
) -> io::Result<()> {
assert!(
size > self.block_size as u64,
size > u64::from(self.block_size),
"Images smaller than block size must use a normal hash",
);
@@ -329,7 +329,7 @@ impl HashTree {
cancel_signal: &AtomicBool,
) -> Result<(Vec<u8>, Vec<u8>)> {
let offsets = self.compute_level_offsets(image_size)?;
let hash_tree_size = offsets.first().map(|r| r.end).unwrap_or(0);
let hash_tree_size = offsets.first().map_or(0, |r| r.end);
let mut hash_tree_data = vec![0u8; hash_tree_size];
let root_digest = self.calculate(
@@ -355,7 +355,7 @@ impl HashTree {
cancel_signal: &AtomicBool,
) -> Result<Vec<u8>> {
let offsets = self.compute_level_offsets(image_size)?;
let hash_tree_size = offsets.first().map(|r| r.end).unwrap_or(0);
let hash_tree_size = offsets.first().map_or(0, |r| r.end);
if hash_tree_data.len() != hash_tree_size {
return Err(Error::InvalidHashTreeSize {
input: image_size,
@@ -384,7 +384,7 @@ impl HashTree {
cancel_signal: &AtomicBool,
) -> Result<()> {
let offsets = self.compute_level_offsets(image_size)?;
let hash_tree_size = offsets.first().map(|r| r.end).unwrap_or(0);
let hash_tree_size = offsets.first().map_or(0, |r| r.end);
if hash_tree_data.len() != hash_tree_size {
return Err(Error::InvalidHashTreeSize {
input: image_size,
@@ -468,6 +468,7 @@ pub struct HashTreeImage {
impl fmt::Debug for HashTreeImage {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("HashTreeImage")
.field("image_size", &self.image_size)
.field("block_size", &self.block_size)
.field("algorithm", &self.algorithm)
.field("salt", &hex::encode(&self.salt))
+12 -15
View File
@@ -586,10 +586,10 @@ impl fmt::Debug for PartitionName {
impl PartitionName {
fn split(&self) -> (&[u8], &[u8]) {
match self.0.iter().position(|b| *b == 0) {
Some(i) => self.0.split_at(i),
None => (&self.0, &[]),
}
self.0
.iter()
.position(|b| *b == 0)
.map_or((&self.0, &[]), |i| self.0.split_at(i))
}
fn validate(&self) -> Result<()> {
@@ -1071,18 +1071,15 @@ impl RawMetadata {
let mut geometry = RawGeometry::ref_from_prefix(&buf).unwrap().0;
match geometry.validate() {
Ok(_) => {
// Skip the backup copy.
reader.read_discard_exact(GEOMETRY_SIZE.into())?;
}
Err(_) => {
// Try to parse the backup copy.
reader.read_exact(&mut buf)?;
if geometry.validate().is_ok() {
// Skip the backup copy.
reader.read_discard_exact(GEOMETRY_SIZE.into())?;
} else {
// Try to parse the backup copy.
reader.read_exact(&mut buf)?;
geometry = RawGeometry::ref_from_prefix(&buf).unwrap().0;
geometry.validate()?;
}
geometry = RawGeometry::ref_from_prefix(&buf).unwrap().0;
geometry.validate()?;
}
geometry
+5 -5
View File
@@ -135,7 +135,7 @@ pub fn parse_legacy_metadata(data: &str) -> Result<OtaMetadata> {
}
"ota-wipe" => metadata.wipe = parse_yes()?,
"ota-retrofit-dynamic-partitions" => {
metadata.retrofit_dynamic_partitions = parse_yes()?
metadata.retrofit_dynamic_partitions = parse_yes()?;
}
"ota-downgrade" => metadata.downgrade = parse_yes()?,
"ota-required-cache" => {
@@ -190,7 +190,7 @@ pub fn parse_legacy_metadata(data: &str) -> Result<OtaMetadata> {
/// Generate the legacy plain-text and modern protobuf serializations of the
/// given metadata instance.
fn serialize_metadata(metadata: &OtaMetadata) -> Result<(String, Vec<u8>)> {
fn serialize_metadata(metadata: &OtaMetadata) -> (String, Vec<u8>) {
use std::fmt::Write;
let mut pairs = BTreeMap::<String, String>::new();
@@ -254,7 +254,7 @@ fn serialize_metadata(metadata: &OtaMetadata) -> Result<(String, Vec<u8>)> {
});
let modern_metadata = metadata.encode_to_vec();
Ok((legacy_metadata, modern_metadata))
(legacy_metadata, modern_metadata)
}
#[derive(Clone, Debug)]
@@ -426,7 +426,7 @@ pub fn add_metadata(
// Add the placeholders to a temporary zip to compute final property files.
let (temp_legacy_offset, temp_modern_offset) = {
let (legacy_raw, modern_raw) = serialize_metadata(&metadata)?;
let (legacy_raw, modern_raw) = serialize_metadata(&metadata);
let raw_writer = Cursor::new(Vec::new());
let mut writer = match zip_mode {
ZipMode::Streaming => ZipWriter::new_streaming(raw_writer),
@@ -462,7 +462,7 @@ pub fn add_metadata(
// Add the final metadata files to the real zip.
{
let (legacy_raw, modern_raw) = serialize_metadata(&metadata)?;
let (legacy_raw, modern_raw) = serialize_metadata(&metadata);
zip_writer.start_file_with_extra_data(PATH_METADATA, options)?;
let legacy_offset = zip_writer.end_extra_data()?;
+4 -7
View File
@@ -218,7 +218,7 @@ fn verify_digest(digest: &[u8], signatures: &Signatures, cert: &Certificate) ->
let without_padding = &data[..size];
match public_key.verify_sig(SignatureAlgorithm::Sha256WithRsa, digest, without_padding) {
Ok(_) => return Ok(()),
Ok(()) => return Ok(()),
Err(e) => last_error = Some(e),
}
}
@@ -902,7 +902,7 @@ impl VabcAlgo {
}
}
fn compressed_size(&self, mut raw_data: &[u8], block_size: u32) -> u64 {
fn compressed_size(self, mut raw_data: &[u8], block_size: u32) -> u64 {
let mut total = 0;
while !raw_data.is_empty() {
@@ -1011,11 +1011,8 @@ pub fn compress_image(
.map(
|(raw_offset, raw_data)| -> Result<(Vec<u8>, InstallOperation, u64)> {
let (data, digest_compressed) = compress_chunk(&raw_data, cancel_signal)?;
let cow_size = if let Some(algo) = vabc_algo {
algo.compressed_size(&raw_data, block_size)
} else {
0
};
let cow_size =
vabc_algo.map_or(0, |a| a.compressed_size(&raw_data, block_size));
let extent = Extent {
start_block: Some(raw_offset / u64::from(block_size)),
+1 -1
View File
@@ -26,7 +26,7 @@ fn main() -> ExitCode {
}
match avbroot::cli::args::main(&LOGGING_INITIALIZED, &cancel_signal) {
Ok(_) => ExitCode::SUCCESS,
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
if LOGGING_INITIALIZED.load(Ordering::SeqCst) {
error!("{e:?}");
+1 -1
View File
@@ -28,7 +28,7 @@ where
{
struct OctalStrVisitor<T>(PhantomData<T>);
impl<'de, T> Visitor<'de> for OctalStrVisitor<T>
impl<T> Visitor<'_> for OctalStrVisitor<T>
where
T: PrimInt,
<T as Num>::FromStrRadixErr: fmt::Display,
+3 -4
View File
@@ -610,7 +610,6 @@ impl OtaCertPatcher {
}
fn patch_ramdisk(
&self,
ramdisk: &mut Vec<u8>,
zip: &[u8],
cancel_signal: &AtomicBool,
@@ -681,7 +680,7 @@ impl BootImagePatch for OtaCertPatcher {
continue;
}
if self.patch_ramdisk(ramdisk, &new_zip, cancel_signal)? {
if Self::patch_ramdisk(ramdisk, &new_zip, cancel_signal)? {
return Ok(());
}
}
@@ -794,7 +793,7 @@ impl BootImagePatch for DsuPubKeyPatcher {
// For builds that don't trust any DSU keys, pick the first boot
// image that contains a first stage ramdisk directory.
if !first_stage_targets.is_empty() {
first_stage_targets.sort();
first_stage_targets.sort_unstable();
first_stage_targets.resize(1, "");
}
@@ -1228,5 +1227,5 @@ pub fn patch_boot_images<'a>(
})
.collect::<Result<()>>()?;
Ok(groups.keys().cloned().collect())
Ok(groups.keys().copied().collect())
}
+3
View File
@@ -1,3 +1,6 @@
#![allow(clippy::nursery)]
#![allow(clippy::pedantic)]
pub mod build {
pub mod tools {
pub mod releasetools {
+3 -5
View File
@@ -153,13 +153,13 @@ pub trait Reopen: Sized {
impl<R: Read + Reopen> Reopen for BufReader<R> {
fn reopen(&self) -> io::Result<Self> {
Ok(BufReader::new(self.get_ref().reopen()?))
Ok(Self::new(self.get_ref().reopen()?))
}
}
impl<W: Write + Reopen> Reopen for BufWriter<W> {
fn reopen(&self) -> io::Result<Self> {
Ok(BufWriter::new(self.get_ref().reopen()?))
Ok(Self::new(self.get_ref().reopen()?))
}
}
@@ -499,9 +499,7 @@ pub struct SharedCursor {
impl SharedCursor {
pub fn new() -> Self {
Self {
..Default::default()
}
Self::default()
}
}
+14 -14
View File
@@ -351,23 +351,23 @@ mod tests {
#[test]
fn test_ranges_overlaps() {
assert_eq!(ranges_overlaps(&[0..4], &(0..0)), false);
assert_eq!(ranges_overlaps(&[0..4], &(0..4)), true);
assert_eq!(ranges_overlaps(&[0..4], &(1..4)), true);
assert_eq!(ranges_overlaps(&[0..4], &(0..3)), true);
assert_eq!(ranges_overlaps(&[0..4], &(4..5)), false);
assert_eq!(ranges_overlaps(&[5..8], &(5..9)), true);
assert_eq!(ranges_overlaps(&[5..8], &(4..8)), true);
assert_eq!(ranges_overlaps(&[5..8], &(4..9)), true);
assert_eq!(ranges_overlaps(&[0..4, 5..8], &(4..5)), true);
assert_eq!(ranges_overlaps(&[0..4, 5..8], &(0..9)), true);
assert!(!ranges_overlaps(&[0..4], &(0..0)));
assert!(ranges_overlaps(&[0..4], &(0..4)));
assert!(ranges_overlaps(&[0..4], &(1..4)));
assert!(ranges_overlaps(&[0..4], &(0..3)));
assert!(!ranges_overlaps(&[0..4], &(4..5)));
assert!(ranges_overlaps(&[5..8], &(5..9)));
assert!(ranges_overlaps(&[5..8], &(4..8)));
assert!(ranges_overlaps(&[5..8], &(4..9)));
assert!(ranges_overlaps(&[0..4, 5..8], &(4..5)));
assert!(ranges_overlaps(&[0..4, 5..8], &(0..9)));
}
#[test]
fn test_ranges_contains() {
assert_eq!(ranges_contains(&[0..4], &0), true);
assert_eq!(ranges_contains(&[0..4], &4), false);
assert_eq!(ranges_contains(&[0..4, 5..8], &4), false);
assert_eq!(ranges_contains(&[0..4, 5..8], &6), true);
assert!(ranges_contains(&[0..4], &0));
assert!(!ranges_contains(&[0..4], &4));
assert!(!ranges_contains(&[0..4, 5..8], &4));
assert!(ranges_contains(&[0..4, 5..8], &6));
}
}
+3
View File
@@ -32,3 +32,6 @@ default-features = false
[features]
static = ["avbroot/static"]
[lints]
workspace = true
+3
View File
@@ -16,3 +16,6 @@ publish = false
[target.'cfg(unix)'.dependencies]
avbroot = { path = "../avbroot" }
honggfuzz = "0.5.55"
[lints]
workspace = true
+3
View File
@@ -13,3 +13,6 @@ anyhow = "1.0.75"
clap = { version = "4.4.1", features = ["derive"] }
regex = { version = "1.9.4", default-features = false, features = ["perf", "std"] }
toml_edit = "0.22.9"
[lints]
workspace = true