Store raw payload hash blob in install plan.
We were using a custom sha256 pair in Omaha response, now that Omaha
has a standard hash_sha256 field in package, we should use that instead.
The difference is that hash_sha256 is encoded in hex instead of base64,
but the android payload property is still using base64, to be backward
compatible, we have to keep accepting base64 there, to avoid decoding
and then re-encoding to another encoding, we store the decoded raw hash.
Also removed the hash() related functions in HashCalculator, since it's
rarely used and the caller should encode it in whatever encoding they
want.
Also make use of RawHashOfBytes to simply code in a few places.
Bug: 36252799
Test: update_engine_unittests
Change-Id: Iaa02611b4c9cda3ead5de51e777e8caba6d99d93
(cherry picked from commit f14d51b6823522f6b2eb834f9e14d72c8363a3ad)
diff --git a/payload_consumer/download_action_unittest.cc b/payload_consumer/download_action_unittest.cc
index 5e9ef5c..4392b74 100644
--- a/payload_consumer/download_action_unittest.cc
+++ b/payload_consumer/download_action_unittest.cc
@@ -139,13 +139,13 @@
0, writer.Open(output_temp_file.path().c_str(), O_WRONLY | O_CREAT, 0));
writer.set_fail_write(fail_write);
- // We pull off the first byte from data and seek past it.
- string hash = HashCalculator::HashOfBytes(&data[1], data.size() - 1);
uint64_t size = data.size();
InstallPlan install_plan;
install_plan.payload_type = InstallPayloadType::kDelta;
install_plan.payload_size = size;
- install_plan.payload_hash = hash;
+ // We pull off the first byte from data and seek past it.
+ EXPECT_TRUE(HashCalculator::RawHashOfBytes(
+ &data[1], data.size() - 1, &install_plan.payload_hash));
install_plan.source_slot = 0;
install_plan.target_slot = 1;
// We mark both slots as bootable. Only the target slot should be unbootable
@@ -371,7 +371,7 @@
// takes ownership of passed in HttpFetcher
InstallPlan install_plan;
install_plan.payload_size = 1;
- install_plan.payload_hash = HashCalculator::HashOfString("x");
+ EXPECT_TRUE(HashCalculator::RawHashOfData({'x'}, &install_plan.payload_hash));
ObjectFeederAction<InstallPlan> feeder_action;
feeder_action.set_obj(install_plan);
MockPrefs prefs;
@@ -456,7 +456,7 @@
0, writer.Open(output_temp_file.path().c_str(), O_WRONLY | O_CREAT, 0));
InstallPlan install_plan;
install_plan.payload_size = data_.length();
- install_plan.payload_hash = "1234hash";
+ install_plan.payload_hash = {'1', '2', '3', '4', 'h', 'a', 's', 'h'};
ObjectFeederAction<InstallPlan> feeder_action;
feeder_action.set_obj(install_plan);
MockPrefs prefs;
@@ -569,7 +569,8 @@
// Prepare the file with existing data before starting to write to
// it via DownloadAction.
- string file_id = utils::CalculateP2PFileId("1234hash", data_.length());
+ string file_id = utils::CalculateP2PFileId(
+ {'1', '2', '3', '4', 'h', 'a', 's', 'h'}, data_.length());
ASSERT_TRUE(p2p_manager_->FileShare(file_id, data_.length()));
string existing_data;
for (unsigned int i = 0; i < 1000; i++)
@@ -606,7 +607,8 @@
// Prepare the file with all existing data before starting to write
// to it via DownloadAction.
- string file_id = utils::CalculateP2PFileId("1234hash", data_.length());
+ string file_id = utils::CalculateP2PFileId(
+ {'1', '2', '3', '4', 'h', 'a', 's', 'h'}, data_.length());
ASSERT_TRUE(p2p_manager_->FileShare(file_id, data_.length()));
string existing_data;
for (unsigned int i = 0; i < 1000; i++)