platform2: Switch over to using base64 functions from libchromeos

Replaced existing implementations of Base64Encode/Base64Decode
with the functions from libchromeos, which were added as part
of an earlier change (see CL:247690).

BUG=None
TEST=`FEATURES=test emerge-link cryptohome debugd metrics privetd update_engine`

Change-Id: I8cec677ce2c2fd3b97ca2228d35c2cf5cd133f4c
Reviewed-on: https://chromium-review.googlesource.com/247792
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/utils.cc b/utils.cc
index 9a596a7..2007e9b 100644
--- a/utils.cc
+++ b/utils.cc
@@ -36,6 +36,7 @@
 #include <base/strings/string_split.h>
 #include <base/strings/string_util.h>
 #include <base/strings/stringprintf.h>
+#include <chromeos/data_encoding.h>
 #include <glib.h>
 
 #include "update_engine/clock_interface.h"
@@ -1463,18 +1464,15 @@
 }
 
 string CalculateP2PFileId(const string& payload_hash, size_t payload_size) {
-  string encoded_hash;
-  OmahaHashCalculator::Base64Encode(payload_hash.c_str(),
-                                    payload_hash.size(),
-                                    &encoded_hash);
+  string encoded_hash = chromeos::data_encoding::Base64Encode(payload_hash);
   return base::StringPrintf("cros_update_size_%zu_hash_%s",
-                      payload_size,
-                      encoded_hash.c_str());
+                            payload_size,
+                            encoded_hash.c_str());
 }
 
 bool DecodeAndStoreBase64String(const string& base64_encoded,
                                 base::FilePath *out_path) {
-  vector<char> contents;
+  chromeos::Blob contents;
 
   out_path->clear();
 
@@ -1483,7 +1481,7 @@
     return false;
   }
 
-  if (!OmahaHashCalculator::Base64Decode(base64_encoded, &contents) ||
+  if (!chromeos::data_encoding::Base64Decode(base64_encoded, &contents) ||
       contents.size() == 0) {
     LOG(ERROR) << "Error decoding base64.";
     return false;
@@ -1495,7 +1493,7 @@
     return false;
   }
 
-  if (fwrite(&contents[0], 1, contents.size(), file) != contents.size()) {
+  if (fwrite(contents.data(), 1, contents.size(), file) != contents.size()) {
     PLOG(ERROR) << "Error writing to temporary file.";
     if (fclose(file) != 0)
       PLOG(ERROR) << "Error closing temporary file.";