Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master # avoid the tag here to prevent dependabot from updating it
with:
toolchain: "1.70"
toolchain: "1.85"
- run: cargo check --all-targets --all-features
fmt:
name: cargo fmt
Expand All @@ -26,7 +26,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master # avoid the tag here to prevent dependabot from updating it
with:
toolchain: "1.70"
toolchain: "1.85"
components: rustfmt
- run: cargo fmt --all --check
test:
Expand All @@ -38,7 +38,7 @@ jobs:
lfs: 'true'
- uses: dtolnay/rust-toolchain@master # avoid the tag here to prevent dependabot from updating it
with:
toolchain: "1.70"
toolchain: "1.85"
- run: cargo test --all-targets --all-features

clippy:
Expand All @@ -48,7 +48,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master # avoid the tag here to prevent dependabot from updating it
with:
toolchain: "1.70"
toolchain: "1.85"
components: clippy
- run: cargo clippy --all-targets --all-features -- -D warnings

Expand Down
2 changes: 1 addition & 1 deletion bmap-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme = "../README.md"

[dependencies]
thiserror = "1.0.24"
quick-xml = { version = "0.31.0", features = [ "serialize" ] }
quick-xml = { version = "0.38.0", features = [ "serialize" ] }
serde = { version = "1.0.147", features = [ "derive" ] }
anyhow = { version = "1.0.40", optional = true }
sha2 = { version = "0.10.6", features = [ "asm" ] }
Expand Down
2 changes: 1 addition & 1 deletion bmap-parser/src/bmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Bmap {
}

/// Iterator over the block map
pub fn block_map(&self) -> impl ExactSizeIterator + Iterator<Item = &BlockRange> {
pub fn block_map(&self) -> impl ExactSizeIterator<Item = &BlockRange> {
self.blockmap.iter()
}

Expand Down
28 changes: 20 additions & 8 deletions bmap-parser/src/bmap/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@ use serde::Deserialize;
use std::str::FromStr;
use thiserror::Error;

/// Custom deserializer to first trim whitespace around text elements before converting.
/// Should be unnecessary once https://github.com/tafia/quick-xml/issues/900 gets fixed
fn deserialize_trimmed<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
D: serde::Deserializer<'de>,
T: FromStr,
<T as std::str::FromStr>::Err: std::fmt::Display,
{
let s = <&str>::deserialize(deserializer)?;
s.trim().parse().map_err(serde::de::Error::custom)
}

#[derive(Debug, Deserialize)]
struct Range {
#[serde(rename = "@chksum")]
chksum: String,
#[serde(rename = "$value")]
#[serde(rename = "$value", deserialize_with = "deserialize_trimmed")]
range: String,
}

Expand All @@ -23,17 +35,17 @@ struct BlockMap {
struct Bmap {
#[serde(rename = "@version")]
version: String,
#[serde(rename = "ImageSize")]
#[serde(rename = "ImageSize", deserialize_with = "deserialize_trimmed")]
image_size: u64,
#[serde(rename = "BlockSize")]
#[serde(rename = "BlockSize", deserialize_with = "deserialize_trimmed")]
block_size: u64,
#[serde(rename = "BlocksCount")]
#[serde(rename = "BlocksCount", deserialize_with = "deserialize_trimmed")]
blocks_count: u64,
#[serde(rename = "MappedBlocksCount")]
#[serde(rename = "MappedBlocksCount", deserialize_with = "deserialize_trimmed")]
mapped_blocks_count: u64,
#[serde(rename = "ChecksumType")]
#[serde(rename = "ChecksumType", deserialize_with = "deserialize_trimmed")]
checksum_type: String,
#[serde(rename = "BmapFileChecksum")]
#[serde(rename = "BmapFileChecksum", deserialize_with = "deserialize_trimmed")]
bmap_file_checksum: String,
#[serde(rename = "BlockMap")]
block_map: BlockMap,
Expand Down Expand Up @@ -79,7 +91,7 @@ fn str_to_digest(s: String, digest: &mut [u8]) -> Result<(), XmlError> {
Some(v) => v,
None => return Err(XmlError::InvalidChecksum(s)),
};
digest[i] = hi << 4 | lo;
digest[i] = (hi << 4) | lo;
}

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions bmap-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ where
left -= r;
}
let digest = hasher.finalize_reset();
if range.checksum().as_slice() != digest.as_slice() {
if range.checksum().as_slice() != &digest[..] {
return Err(CopyError::ChecksumError);
}

Expand Down Expand Up @@ -139,7 +139,7 @@ where
left -= r;
}
let digest = hasher.finalize_reset();
if range.checksum().as_slice() != digest.as_slice() {
if range.checksum().as_slice() != &digest[..] {
return Err(CopyError::ChecksumError);
}

Expand Down
2 changes: 1 addition & 1 deletion bmap-parser/tests/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn parse() {
assert_eq!((block + 1) * 4096, range.length());

let digest = Sha256::digest(format!("{}", block).as_bytes());
assert_eq!(digest.as_slice(), range.checksum().as_slice());
assert_eq!(&digest[..], range.checksum().as_slice());

block = if block == 0 { 8 } else { block * 4 };
}
Expand Down
4 changes: 4 additions & 0 deletions bmap-rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ fn copy_local_input(source: PathBuf, destination: PathBuf) -> Result<()> {
let output = std::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(destination)?;

setup_output(&output, &bmap, output.metadata()?)?;
Expand All @@ -231,6 +232,7 @@ async fn copy_remote_input(source: Url, destination: PathBuf) -> Result<()> {
let mut output = tokio::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(destination)
.await?;

Expand Down Expand Up @@ -263,6 +265,7 @@ fn copy_local_input_nobmap(source: PathBuf, destination: PathBuf) -> Result<()>
let output = std::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(destination)?;

let mut input = setup_local_input(&source)?;
Expand All @@ -281,6 +284,7 @@ async fn copy_remote_input_nobmap(source: Url, destination: PathBuf) -> Result<(
let mut output = tokio::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(destination)
.await?;

Expand Down