update_engine: Store and test kern/fw versions as 4 values
- Refactors the handling of _firmware_version and _kernel_version
attributes to split as 4x 16 bit values.
- Based on discussion, we are trying to avoid using the client
specific version format in the network protocol.
- Each of firmware and kernel versions will be stored separately
as uint16_t rather than combined as a uint32_t.
- In the Omaha response the two fields of each version type will
be encoded as key_version.version
- Adds tests for the actual parsing of the response.
BUG=chromium:840432
TEST=cros_run_unit_tests --board=samus --packages update_engine
Change-Id: I4da02e3f4715a132db7e96e55c30139fff6fe6ea
Reviewed-on: https://chromium-review.googlesource.com/1123106
Commit-Ready: Marton Hunyady <hunyadym@chromium.org>
Tested-by: Zentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
diff --git a/common/utils.cc b/common/utils.cc
index b06954b..1a8fd53 100644
--- a/common/utils.cc
+++ b/common/utils.cc
@@ -61,6 +61,7 @@
using base::Time;
using base::TimeDelta;
using std::min;
+using std::numeric_limits;
using std::pair;
using std::string;
using std::vector;
@@ -1082,6 +1083,36 @@
return value;
}
+void ParseRollbackKeyVersion(const string& raw_version,
+ uint16_t* high_version,
+ uint16_t* low_version) {
+ DCHECK(high_version);
+ DCHECK(low_version);
+ *high_version = numeric_limits<uint16_t>::max();
+ *low_version = numeric_limits<uint16_t>::max();
+
+ vector<string> parts = base::SplitString(
+ raw_version, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
+ if (parts.size() != 2) {
+ // The version string must have exactly one period.
+ return;
+ }
+
+ int high;
+ int low;
+ if (!(base::StringToInt(parts[0], &high) &&
+ base::StringToInt(parts[1], &low))) {
+ // Both parts of the version could not be parsed correctly.
+ return;
+ }
+
+ if (high >= 0 && high < numeric_limits<uint16_t>::max() && low >= 0 &&
+ low < numeric_limits<uint16_t>::max()) {
+ *high_version = static_cast<uint16_t>(high);
+ *low_version = static_cast<uint16_t>(low);
+ }
+}
+
} // namespace utils
} // namespace chromeos_update_engine