Skip to content

Commit 5d4db08

Browse files
authored
Merge pull request #88 from james-parky/dev-omaha-improvements
Omaha crate improvements
2 parents c22367c + 29a23ad commit 5d4db08

File tree

17 files changed

+563
-574
lines changed

17 files changed

+563
-574
lines changed

Cargo.lock

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/download_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() -> Result<(), Box<dyn Error>> {
1616
let res = download_and_hash(&client, url, &path, None, None)?;
1717
tempdir.close()?;
1818

19-
println!("hash: {}", res.hash_sha256);
19+
println!("hash: {:?}", res.hash_sha256);
2020

2121
Ok(())
2222
}

examples/full_test.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ use std::borrow::Cow;
44
use anyhow::{Context, Result};
55
use hard_xml::XmlRead;
66
use url::Url;
7+
use omaha::Sha256Digest;
78

8-
fn get_pkgs_to_download(resp: &omaha::Response) -> Result<Vec<(Url, omaha::Hash<omaha::Sha256>)>> {
9-
let mut to_download: Vec<(Url, omaha::Hash<_>)> = Vec::new();
9+
fn get_pkgs_to_download(resp: &omaha::Response) -> Result<Vec<(Url, Sha256Digest)>> {
10+
let mut to_download: Vec<(Url, Sha256Digest)> = Vec::new();
1011

1112
for app in &resp.apps {
1213
let manifest = &app.update_check.manifest;
@@ -83,9 +84,9 @@ fn main() -> Result<(), Box<dyn Error>> {
8384
let res = ue_rs::download_and_hash(&client, url.clone(), &path, Some(expected_sha256.clone()), None).context(format!("download_and_hash({url:?}) failed"))?;
8485
tempdir.close()?;
8586

86-
println!("\texpected sha256: {}", expected_sha256);
87-
println!("\tcalculated sha256: {}", res.hash_sha256);
88-
println!("\tsha256 match? {}", expected_sha256 == res.hash_sha256);
87+
println!("\texpected sha256: {:?}", expected_sha256);
88+
println!("\tcalculated sha256: {:?}", res.hash_sha256);
89+
println!("\tsha256 match? {:?}", expected_sha256 == res.hash_sha256);
8990
}
9091

9192
Ok(())

examples/response.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn main() -> Result<(), Box<dyn Error>> {
4646

4747
#[rustfmt::skip]
4848
if let Some(h) = pkg.hash.as_ref() {
49-
println!(" sha1: {}", h);
49+
println!(" sha1: {:?}", h);
5050
};
5151

5252
#[rustfmt::skip]
@@ -61,7 +61,7 @@ fn main() -> Result<(), Box<dyn Error>> {
6161
#[rustfmt::skip]
6262
hash_sha256
6363
.map(|h| {
64-
println!(" sha256: {}", h);
64+
println!(" sha256: {:?}", h);
6565
});
6666

6767
println!();

omaha/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@ edition = "2021"
77

88
[dependencies]
99
uuid = "1.2"
10-
ct-codecs = "1"
1110
url = "2"
12-
anyhow = "1.0.75"
1311
sha2 = "0.10.8"
1412
sha1 = "0.10.6"
15-
digest = "0.10.7"
1613

1714
[dependencies.hard-xml]
1815
path = "../vendor/hard-xml"

omaha/src/error.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use std::fmt::Display;
2+
use std::num::ParseIntError;
3+
4+
#[derive(Debug)]
5+
pub enum Error {
6+
TryFromHex(ParseIntError),
7+
InvalidDigestLength {
8+
expected: usize,
9+
actual: usize,
10+
},
11+
UnknownActionEvent(String),
12+
UnknownSuccessAction(String),
13+
ParseFileSize(ParseIntError),
14+
ParseUuid(uuid::Error),
15+
ParseUrl(url::ParseError),
16+
}
17+
18+
impl Display for Error {
19+
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20+
match self {
21+
Error::TryFromHex(err) => write!(fmt, "failed to convert from hex: {err}"),
22+
Error::InvalidDigestLength {
23+
expected,
24+
actual,
25+
} => {
26+
write!(fmt, "invalid digest length: expected {expected}, actual {actual}")
27+
}
28+
Error::UnknownActionEvent(action) => write!(fmt, "unknown action event: {action}"),
29+
Error::UnknownSuccessAction(action) => write!(fmt, "unknown success action: {action}"),
30+
Error::ParseFileSize(err) => write!(fmt, "failed to parse file size: {err}"),
31+
Error::ParseUuid(err) => write!(fmt, "failed to parse uuid: {err}"),
32+
Error::ParseUrl(err) => write!(fmt, "failed to parse url: {err}"),
33+
}
34+
}
35+
}
36+
37+
impl std::error::Error for Error {}

0 commit comments

Comments
 (0)