libweave: Remove few small base/ dependencies
In particular Contains() and SimpleTestClock and StringPiece from
crypto.
Also updated some includes.
BUG=brillo:1256
TEST=`FEATURES=test emerge-gizmo libweave buffet`
Change-Id: I4efd2e8154c7c432532d7e18afec9acf10f156f1
Reviewed-on: https://chromium-review.googlesource.com/294340
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/libweave/external/crypto/p224.cc b/libweave/external/crypto/p224.cc
index b7c66c5..99fd2d1 100644
--- a/libweave/external/crypto/p224.cc
+++ b/libweave/external/crypto/p224.cc
@@ -11,16 +11,32 @@
#include <string.h>
-#include <base/sys_byteorder.h>
-
namespace weave {
namespace crypto {
namespace p224 {
namespace {
-using base::HostToNet32;
-using base::NetToHost32;
+inline uint32 ByteSwap(uint32 x) {
+ return ((x & 0x000000fful) << 24) | ((x & 0x0000ff00ul) << 8) |
+ ((x & 0x00ff0000ul) >> 8) | ((x & 0xff000000ul) >> 24);
+}
+
+inline uint32 HostToNet32(uint32 x) {
+#if defined(ARCH_CPU_LITTLE_ENDIAN)
+ return ByteSwap(x);
+#else
+ return x;
+#endif
+}
+
+inline uint32 NetToHost32(uint32 x) {
+#if defined(ARCH_CPU_LITTLE_ENDIAN)
+ return ByteSwap(x);
+#else
+ return x;
+#endif
+}
// Field element functions.
//
@@ -655,7 +671,7 @@
} // anonymous namespace
-bool Point::SetFromString(const base::StringPiece& in) {
+bool Point::SetFromString(const std::string& in) {
if (in.size() != 2*28)
return false;
const uint32* inwords = reinterpret_cast<const uint32*>(in.data());
diff --git a/libweave/external/crypto/p224.h b/libweave/external/crypto/p224.h
index a835ecd..ea15acf 100644
--- a/libweave/external/crypto/p224.h
+++ b/libweave/external/crypto/p224.h
@@ -8,7 +8,6 @@
#include <string>
#include <base/basictypes.h>
-#include <base/strings/string_piece.h>
namespace weave {
namespace crypto {
@@ -26,7 +25,7 @@
// representation. The external point representation is an (x, y) pair of a
// point on the curve. Each field element is represented as a big-endian
// number < p.
- bool SetFromString(const base::StringPiece& in);
+ bool SetFromString(const std::string& in);
// ToString returns an external representation of the Point.
std::string ToString() const;
diff --git a/libweave/external/crypto/p224_spake.cc b/libweave/external/crypto/p224_spake.cc
index 634c7e6..890002a 100644
--- a/libweave/external/crypto/p224_spake.cc
+++ b/libweave/external/crypto/p224_spake.cc
@@ -115,10 +115,9 @@
} // anonymous namespace
-P224EncryptedKeyExchange::P224EncryptedKeyExchange(
- PeerType peer_type, const base::StringPiece& password)
- : state_(kStateInitial),
- is_server_(peer_type == kPeerTypeServer) {
+P224EncryptedKeyExchange::P224EncryptedKeyExchange(PeerType peer_type,
+ const std::string& password)
+ : state_(kStateInitial), is_server_(peer_type == kPeerTypeServer) {
memset(&x_, 0, sizeof(x_));
memset(&expected_authenticator_, 0, sizeof(expected_authenticator_));
@@ -165,7 +164,7 @@
}
P224EncryptedKeyExchange::Result P224EncryptedKeyExchange::ProcessMessage(
- const base::StringPiece& message) {
+ const std::string& message) {
if (state_ == kStateRecvHash) {
// This is the final state of the protocol: we are reading the peer's
// authentication hash and checking that it matches the one that we expect.
@@ -212,11 +211,11 @@
std::string client_masked_dh, server_masked_dh;
if (is_server_) {
- client_masked_dh = message.as_string();
+ client_masked_dh = message;
server_masked_dh = next_message_;
} else {
client_masked_dh = next_message_;
- server_masked_dh = message.as_string();
+ server_masked_dh = message;
}
// Now we calculate the hashes that each side will use to prove to the other
diff --git a/libweave/external/crypto/p224_spake.h b/libweave/external/crypto/p224_spake.h
index aea280d..547f8dc 100644
--- a/libweave/external/crypto/p224_spake.h
+++ b/libweave/external/crypto/p224_spake.h
@@ -8,7 +8,6 @@
#include <string>
#include <base/gtest_prod_util.h>
-#include <base/strings/string_piece.h>
#include "libweave/external/crypto/p224.h"
#include "libweave/external/crypto/sha2.h"
@@ -56,8 +55,7 @@
// password: secret session password. Both parties to the
// authentication must pass the same value. For the case of a
// TLS connection, see RFC 5705.
- P224EncryptedKeyExchange(PeerType peer_type,
- const base::StringPiece& password);
+ P224EncryptedKeyExchange(PeerType peer_type, const std::string& password);
// GetNextMessage returns a byte string which must be passed to the other
// party in the authentication.
@@ -65,7 +63,7 @@
// ProcessMessage processes a message which must have been generated by a
// call to GetNextMessage() by the other party.
- Result ProcessMessage(const base::StringPiece& message);
+ Result ProcessMessage(const std::string& message);
// In the event that ProcessMessage() returns kResultFailed, error will
// return a human readable error message.
diff --git a/libweave/external/crypto/p224_unittest.cc b/libweave/external/crypto/p224_unittest.cc
index 5d149da..c0d3b2f 100644
--- a/libweave/external/crypto/p224_unittest.cc
+++ b/libweave/external/crypto/p224_unittest.cc
@@ -771,9 +771,9 @@
TEST(P224, ExternalToInternalAndBack) {
Point point;
- EXPECT_TRUE(point.SetFromString(base::StringPiece(
- reinterpret_cast<const char *>(kBasePointExternal),
- sizeof(kBasePointExternal))));
+ EXPECT_TRUE(point.SetFromString(
+ std::string(reinterpret_cast<const char*>(kBasePointExternal),
+ sizeof(kBasePointExternal))));
const std::string external = point.ToString();
@@ -797,10 +797,10 @@
TEST(P224, Addition) {
Point a, b, minus_b, sum, a_again;
- ASSERT_TRUE(a.SetFromString(base::StringPiece(
- reinterpret_cast<const char *>(kNISTTestVectors[10].affine), 56)));
- ASSERT_TRUE(b.SetFromString(base::StringPiece(
- reinterpret_cast<const char *>(kNISTTestVectors[11].affine), 56)));
+ ASSERT_TRUE(a.SetFromString(std::string(
+ reinterpret_cast<const char*>(kNISTTestVectors[10].affine), 56)));
+ ASSERT_TRUE(b.SetFromString(std::string(
+ reinterpret_cast<const char*>(kNISTTestVectors[11].affine), 56)));
p224::Negate(b, &minus_b);
p224::Add(a, b, &sum);
diff --git a/libweave/external/crypto/sha2.cc b/libweave/external/crypto/sha2.cc
index 59a111d..d4e3ac9 100644
--- a/libweave/external/crypto/sha2.cc
+++ b/libweave/external/crypto/sha2.cc
@@ -12,14 +12,13 @@
namespace weave {
namespace crypto {
-void SHA256HashString(const base::StringPiece& str, uint8_t* output,
- size_t len) {
+void SHA256HashString(const std::string& str, uint8_t* output, size_t len) {
std::string hash = SHA256HashString(str);
len = std::min(hash.size(), len);
std::copy(hash.begin(), hash.begin() + len, output);
}
-std::string SHA256HashString(const base::StringPiece& str) {
+std::string SHA256HashString(const std::string& str) {
SHA256_CTX sha_context;
SHA256_Init(&sha_context);
SHA256_Update(&sha_context, str.data(), str.size());
diff --git a/libweave/external/crypto/sha2.h b/libweave/external/crypto/sha2.h
index 34f6af8..920a798 100644
--- a/libweave/external/crypto/sha2.h
+++ b/libweave/external/crypto/sha2.h
@@ -7,8 +7,6 @@
#include <string>
-#include <base/strings/string_piece.h>
-
namespace weave {
namespace crypto {
@@ -21,12 +19,11 @@
// Computes the SHA-256 hash of the input string 'str' and stores the first
// 'len' bytes of the hash in the output buffer 'output'. If 'len' > 32,
// only 32 bytes (the full hash) are stored in the 'output' buffer.
-void SHA256HashString(const base::StringPiece& str, uint8_t* output,
- size_t len);
+void SHA256HashString(const std::string& str, uint8_t* output, size_t len);
// Convenience version of the above that returns the result in a 32-byte
// string.
-std::string SHA256HashString(const base::StringPiece& str);
+std::string SHA256HashString(const std::string& str);
} // namespace crypto
} // namespace weave
diff --git a/libweave/include/weave/error.h b/libweave/include/weave/error.h
index 278d2f9..344f56f 100644
--- a/libweave/include/weave/error.h
+++ b/libweave/include/weave/error.h
@@ -9,7 +9,8 @@
#include <string>
#include <base/macros.h>
-#include <base/tracked_objects.h>
+#include <base/location.h>
+#include <base/compiler_specific.h>
#include <weave/export.h>
namespace weave {
diff --git a/libweave/include/weave/mock_task_runner.h b/libweave/include/weave/mock_task_runner.h
index 313e05f..d0d06f0 100644
--- a/libweave/include/weave/mock_task_runner.h
+++ b/libweave/include/weave/mock_task_runner.h
@@ -12,7 +12,7 @@
#include <utility>
#include <vector>
-#include <base/test/simple_test_clock.h>
+#include <base/time/clock.h>
#include <gmock/gmock.h>
namespace weave {
@@ -51,7 +51,7 @@
}
}
- base::SimpleTestClock* GetClock() { return &test_clock_; }
+ base::Clock* GetClock() { return &test_clock_; }
private:
void SaveTask(const tracked_objects::Location& from_here,
@@ -69,7 +69,17 @@
};
size_t counter_{0}; // Keeps order of tasks with the same time.
- base::SimpleTestClock test_clock_;
+
+ class TestClock : public base::Clock {
+ public:
+ base::Time Now() override { return now_; }
+
+ void SetNow(base::Time now) { now_ = now; }
+
+ private:
+ base::Time now_;
+ };
+ TestClock test_clock_;
std::priority_queue<QueueItem,
std::vector<QueueItem>,
diff --git a/libweave/include/weave/task_runner.h b/libweave/include/weave/task_runner.h
index 0b349b6..66b83ab 100644
--- a/libweave/include/weave/task_runner.h
+++ b/libweave/include/weave/task_runner.h
@@ -10,6 +10,7 @@
#include <vector>
#include <base/callback.h>
+#include <base/location.h>
namespace weave {
diff --git a/libweave/src/base_api_handler.cc b/libweave/src/base_api_handler.cc
index 3e641d7..b9e4de4 100644
--- a/libweave/src/base_api_handler.cc
+++ b/libweave/src/base_api_handler.cc
@@ -4,6 +4,8 @@
#include "libweave/src/base_api_handler.h"
+#include <base/bind.h>
+
#include "libweave/src/commands/command_instance.h"
#include "libweave/src/commands/command_manager.h"
#include "libweave/src/device_registration_info.h"
diff --git a/libweave/src/commands/command_queue.h b/libweave/src/commands/command_queue.h
index 851a283..66cc2d2 100644
--- a/libweave/src/commands/command_queue.h
+++ b/libweave/src/commands/command_queue.h
@@ -14,6 +14,7 @@
#include <base/callback.h>
#include <base/macros.h>
+#include <base/time/time.h>
#include <weave/commands.h>
#include "libweave/src/commands/command_instance.h"
diff --git a/libweave/src/commands/prop_constraints.cc b/libweave/src/commands/prop_constraints.cc
index c1ab1c4..babba85 100644
--- a/libweave/src/commands/prop_constraints.cc
+++ b/libweave/src/commands/prop_constraints.cc
@@ -5,6 +5,7 @@
#include "libweave/src/commands/prop_constraints.h"
#include <base/json/json_writer.h>
+#include <base/logging.h>
#include "libweave/src/commands/prop_values.h"
#include "libweave/src/commands/schema_constants.h"
diff --git a/libweave/src/commands/schema_utils.cc b/libweave/src/commands/schema_utils.cc
index 85455ed..b48b89b 100644
--- a/libweave/src/commands/schema_utils.cc
+++ b/libweave/src/commands/schema_utils.cc
@@ -9,6 +9,7 @@
#include <string>
#include <base/json/json_writer.h>
+#include <base/logging.h>
#include "libweave/src/commands/object_schema.h"
#include "libweave/src/commands/prop_types.h"
diff --git a/libweave/src/commands/schema_utils.h b/libweave/src/commands/schema_utils.h
index 5691ddd..570fb42 100644
--- a/libweave/src/commands/schema_utils.h
+++ b/libweave/src/commands/schema_utils.h
@@ -12,6 +12,7 @@
#include <type_traits>
#include <vector>
+#include <base/logging.h>
#include <base/values.h>
#include <weave/error.h>
diff --git a/libweave/src/commands/unittest_utils.cc b/libweave/src/commands/unittest_utils.cc
index 0b9c2e3..12a1c02 100644
--- a/libweave/src/commands/unittest_utils.cc
+++ b/libweave/src/commands/unittest_utils.cc
@@ -5,6 +5,7 @@
#include "libweave/src/commands/unittest_utils.h"
#include <base/json/json_reader.h>
+#include <base/logging.h>
namespace weave {
namespace unittests {
diff --git a/libweave/src/data_encoding_unittest.cc b/libweave/src/data_encoding_unittest.cc
index 76265cd..6a546f8 100644
--- a/libweave/src/data_encoding_unittest.cc
+++ b/libweave/src/data_encoding_unittest.cc
@@ -7,6 +7,7 @@
#include <algorithm>
#include <numeric>
+#include <base/logging.h>
#include <gtest/gtest.h>
namespace weave {
diff --git a/libweave/src/device_manager.cc b/libweave/src/device_manager.cc
index 0f51098..4187df7 100644
--- a/libweave/src/device_manager.cc
+++ b/libweave/src/device_manager.cc
@@ -6,6 +6,8 @@
#include <string>
+#include <base/bind.h>
+
#include "libweave/src/base_api_handler.h"
#include "libweave/src/commands/command_manager.h"
#include "libweave/src/config.h"
diff --git a/libweave/src/device_registration_info.h b/libweave/src/device_registration_info.h
index 45f2257..564fb87 100644
--- a/libweave/src/device_registration_info.h
+++ b/libweave/src/device_registration_info.h
@@ -13,11 +13,8 @@
#include <base/callback.h>
#include <base/macros.h>
-#include <base/memory/ref_counted.h>
#include <base/memory/weak_ptr.h>
-#include <base/single_thread_task_runner.h>
#include <base/time/time.h>
-#include <base/timer/timer.h>
#include <weave/error.h>
#include <weave/cloud.h>
#include <weave/http_client.h>
diff --git a/libweave/src/notification/pull_channel.h b/libweave/src/notification/pull_channel.h
index 7b10152..7f1b789 100644
--- a/libweave/src/notification/pull_channel.h
+++ b/libweave/src/notification/pull_channel.h
@@ -10,6 +10,7 @@
#include <base/macros.h>
#include <base/memory/weak_ptr.h>
+#include <base/time/time.h>
#include "libweave/src/notification/notification_channel.h"
diff --git a/libweave/src/notification/xmpp_channel_unittest.cc b/libweave/src/notification/xmpp_channel_unittest.cc
index 1816288..eaacf83 100644
--- a/libweave/src/notification/xmpp_channel_unittest.cc
+++ b/libweave/src/notification/xmpp_channel_unittest.cc
@@ -7,7 +7,6 @@
#include <algorithm>
#include <queue>
-#include <base/test/simple_test_clock.h>
#include <gtest/gtest.h>
#include <weave/mock_task_runner.h>
diff --git a/libweave/src/notification/xmpp_iq_stanza_handler.h b/libweave/src/notification/xmpp_iq_stanza_handler.h
index eb1f1b6..b4edcac 100644
--- a/libweave/src/notification/xmpp_iq_stanza_handler.h
+++ b/libweave/src/notification/xmpp_iq_stanza_handler.h
@@ -11,8 +11,8 @@
#include <base/callback_forward.h>
#include <base/macros.h>
+#include <base/time/time.h>
#include <base/memory/weak_ptr.h>
-#include <base/single_thread_task_runner.h>
#include "libweave/src/notification/xmpp_stream_parser.h"
diff --git a/libweave/src/privet/privet_handler.cc b/libweave/src/privet/privet_handler.cc
index b83df36..97a8d6a 100644
--- a/libweave/src/privet/privet_handler.cc
+++ b/libweave/src/privet/privet_handler.cc
@@ -11,7 +11,6 @@
#include <base/bind.h>
#include <base/location.h>
-#include <base/stl_util.h>
#include <base/strings/string_number_conversions.h>
#include <base/strings/stringprintf.h>
#include <base/values.h>
@@ -533,7 +532,8 @@
PairingType pairing;
std::set<PairingType> modes = security_->GetPairingTypes();
- if (!StringToEnum(pairing_str, &pairing) || !ContainsKey(modes, pairing)) {
+ if (!StringToEnum(pairing_str, &pairing) ||
+ modes.find(pairing) == modes.end()) {
Error::AddToPrintf(&error, FROM_HERE, errors::kDomain,
errors::kInvalidParams, kInvalidParamValueFormat,
kPairingKey, pairing_str.c_str());
@@ -542,7 +542,8 @@
CryptoType crypto;
std::set<CryptoType> cryptos = security_->GetCryptoTypes();
- if (!StringToEnum(crypto_str, &crypto) || !ContainsKey(cryptos, crypto)) {
+ if (!StringToEnum(crypto_str, &crypto) ||
+ cryptos.find(crypto) == cryptos.end()) {
Error::AddToPrintf(&error, FROM_HERE, errors::kDomain,
errors::kInvalidParams, kInvalidParamValueFormat,
kCryptoKey, crypto_str.c_str());
diff --git a/libweave/src/privet/privet_types.h b/libweave/src/privet/privet_types.h
index b46e5b6..d013500 100644
--- a/libweave/src/privet/privet_types.h
+++ b/libweave/src/privet/privet_types.h
@@ -7,6 +7,7 @@
#include <string>
+#include <base/logging.h>
#include <weave/error.h>
namespace weave {
diff --git a/libweave/src/privet/security_manager.cc b/libweave/src/privet/security_manager.cc
index 409f09a..588cbd3 100644
--- a/libweave/src/privet/security_manager.cc
+++ b/libweave/src/privet/security_manager.cc
@@ -13,7 +13,6 @@
#include <base/guid.h>
#include <base/logging.h>
#include <base/rand_util.h>
-#include <base/stl_util.h>
#include <base/strings/string_number_conversions.h>
#include <base/strings/stringprintf.h>
#include <base/time/time.h>
diff --git a/libweave/src/privet/security_manager.h b/libweave/src/privet/security_manager.h
index 60c59e8..07f8c0c 100644
--- a/libweave/src/privet/security_manager.h
+++ b/libweave/src/privet/security_manager.h
@@ -12,6 +12,7 @@
#include <vector>
#include <base/callback.h>
+#include <base/gtest_prod_util.h>
#include <base/memory/weak_ptr.h>
#include <weave/error.h>
diff --git a/libweave/src/states/state_change_queue.cc b/libweave/src/states/state_change_queue.cc
index 345e532..8f787ca 100644
--- a/libweave/src/states/state_change_queue.cc
+++ b/libweave/src/states/state_change_queue.cc
@@ -15,8 +15,6 @@
bool StateChangeQueue::NotifyPropertiesUpdated(base::Time timestamp,
ValueMap changed_properties) {
- DCHECK(thread_checker_.CalledOnValidThread());
-
auto& stored_changes = state_changes_[timestamp];
// Merge the old property set.
changed_properties.insert(stored_changes.begin(), stored_changes.end());
@@ -41,7 +39,6 @@
}
std::vector<StateChange> StateChangeQueue::GetAndClearRecordedStateChanges() {
- DCHECK(thread_checker_.CalledOnValidThread());
std::vector<StateChange> changes;
changes.reserve(state_changes_.size());
for (const auto& pair : state_changes_) {
diff --git a/libweave/src/states/state_change_queue.h b/libweave/src/states/state_change_queue.h
index 4b2acaf..3289209 100644
--- a/libweave/src/states/state_change_queue.h
+++ b/libweave/src/states/state_change_queue.h
@@ -30,11 +30,6 @@
void NotifyStateUpdatedOnServer(UpdateID update_id) override;
private:
- // To make sure we do not call NotifyPropertiesUpdated() and
- // GetAndClearRecordedStateChanges() on different threads, |thread_checker_|
- // is here to help us with verifying the single-threaded operation.
- base::ThreadChecker thread_checker_;
-
// Maximum queue size. If it is full, the oldest state update records are
// merged together until the queue size is within the size limit.
const size_t max_queue_size_;
diff --git a/libweave/src/weave_testrunner.cc b/libweave/src/weave_testrunner.cc
index 215818f..5de7cae 100644
--- a/libweave/src/weave_testrunner.cc
+++ b/libweave/src/weave_testrunner.cc
@@ -2,13 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <base/at_exit.h>
#include <base/command_line.h>
+#include <base/logging.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
int main(int argc, char** argv) {
- base::AtExitManager exit_manager;
base::CommandLine::Init(argc, argv);
logging::LoggingSettings settings;