From c1fd11068c3ce1fe08798c9d90c9ed9583b8d480 Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Wed, 27 Sep 2023 17:32:42 +0200 Subject: [PATCH] download_sysext: read delta update file after downloading Read delta update file after downloading, and do not store sigfiles. --- src/bin/download_sysext.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/bin/download_sysext.rs b/src/bin/download_sysext.rs index 3257672..527df4e 100644 --- a/src/bin/download_sysext.rs +++ b/src/bin/download_sysext.rs @@ -4,7 +4,6 @@ use std::path::Path; use std::fs::File; use std::fs; use std::io; -use std::io::Write; #[macro_use] extern crate log; @@ -132,7 +131,6 @@ async fn main() -> Result<(), Box> { println!(); const PUBKEY_FILE: &str = "../src/testdata/public_key_test_pkcs8.pem"; - const SIGFILE: &str = "./testsigfile"; //// // download @@ -145,9 +143,6 @@ async fn main() -> Result<(), Box> { let path = unverified_dir.join(&*pkg.name); let mut file = File::create(path.clone())?; - // Read update payload from file, read delta update header from the payload. - let updata = io::read_to_string(file.try_clone().unwrap()); - println!("creating {}...", path.display()); let res = ue_rs::download_and_hash(&client, pkg.url, &mut file).await?; @@ -156,24 +151,21 @@ async fn main() -> Result<(), Box> { println!("\tcalculated sha256: {}", res.hash); println!("\tsha256 match? {}", pkg.hash == res.hash); + // Read update payload from file, read delta update header from the payload. + let updata = io::read_to_string(res.data.try_clone().unwrap()); + let header = delta_update::read_delta_update_header(res.data)?; // Extract signature from header. let sigbytes = delta_update::get_signatures_bytes(res.data, &header)?; // Parse signature data from the signature containing data, version, special fields. - let sigdata = match delta_update::parse_signature_data(updata.unwrap().as_bytes(), &sigbytes, PUBKEY_FILE) { + let _sigdata = match delta_update::parse_signature_data(updata.unwrap().as_bytes(), &sigbytes, PUBKEY_FILE) { Some(data) => Box::leak(data), _ => return Err("unable to parse signature data".into()), }; println!("Parsed signature data from file {:?}", path); - - // Store signature into a file. - let mut sigfile = File::create(SIGFILE.clone())?; - let _ = sigfile.write_all(sigdata); - - println!("Wrote signature data into file {:?}", SIGFILE); } Ok(())