Check if zlib is compatible.

Add a --zlib_fingerprint flag in delta_generator to check if the zlib of
source image is compatible, and only enable IMGDIFF operation if it is.

Test: Added unittest to check /etc/zlib_fingerprint
Bug: 27156099

Change-Id: Ida346a99430c95cdc8a43e1055d6efa08f07ca25
diff --git a/common/utils.cc b/common/utils.cc
index 912bc96..2b09560 100644
--- a/common/utils.cc
+++ b/common/utils.cc
@@ -61,6 +61,7 @@
 #include "update_engine/common/subprocess.h"
 #include "update_engine/payload_consumer/file_descriptor.h"
 #include "update_engine/payload_consumer/file_writer.h"
+#include "update_engine/payload_consumer/payload_constants.h"
 
 using base::Time;
 using base::TimeDelta;
@@ -1133,6 +1134,19 @@
   return false;
 }
 
+bool IsZlibCompatible(const string& fingerprint) {
+  if (fingerprint.size() != sizeof(kCompatibleZlibFingerprint[0]) - 1) {
+    LOG(ERROR) << "Invalid fingerprint: " << fingerprint;
+    return false;
+  }
+  for (auto& f : kCompatibleZlibFingerprint) {
+    if (base::CompareCaseInsensitiveASCII(fingerprint, f) == 0) {
+      return true;
+    }
+  }
+  return false;
+}
+
 bool ReadExtents(const string& path, const vector<Extent>& extents,
                  brillo::Blob* out_data, ssize_t out_data_size,
                  size_t block_size) {
diff --git a/common/utils.h b/common/utils.h
index df06ef1..55d8a80 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -343,6 +343,9 @@
 bool GetMinorVersion(const brillo::KeyValueStore& store,
                      uint32_t* minor_version);
 
+// Returns whether zlib |fingerprint| is compatible with zlib we are using.
+bool IsZlibCompatible(const std::string& fingerprint);
+
 // This function reads the specified data in |extents| into |out_data|. The
 // extents are read from the file at |path|. |out_data_size| is the size of
 // |out_data|. Returns false if the number of bytes to read given in