Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Unified Diff: components/cryptauth/data_with_timestamp.cc

Issue 2847233003: [EasyUnlock] Move DataWithTimestamp out of ForegroundEidGenerator so it can be shared. (Closed)
Patch Set: fixes Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/cryptauth/data_with_timestamp.h ('k') | components/cryptauth/foreground_eid_generator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cryptauth/data_with_timestamp.cc
diff --git a/components/cryptauth/data_with_timestamp.cc b/components/cryptauth/data_with_timestamp.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7fbc96c275323f9b44bbca7e605be5cfc72fcb37
--- /dev/null
+++ b/components/cryptauth/data_with_timestamp.cc
@@ -0,0 +1,63 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/cryptauth/data_with_timestamp.h"
+
+#include <iomanip>
+
+#include "base/logging.h"
+
+namespace cryptauth {
+
+DataWithTimestamp::DataWithTimestamp(const std::string& data,
+ const int64_t start_timestamp_ms,
+ const int64_t end_timestamp_ms)
+ : data(data),
+ start_timestamp_ms(start_timestamp_ms),
+ end_timestamp_ms(end_timestamp_ms) {
+ DCHECK(start_timestamp_ms < end_timestamp_ms);
+ DCHECK(data.size());
+}
+
+DataWithTimestamp::DataWithTimestamp(const DataWithTimestamp& other)
+ : data(other.data),
+ start_timestamp_ms(other.start_timestamp_ms),
+ end_timestamp_ms(other.end_timestamp_ms) {
+ DCHECK(start_timestamp_ms < end_timestamp_ms);
+ DCHECK(data.size());
+}
+
+// static.
+std::string DataWithTimestamp::ToDebugString(
+ const std::vector<DataWithTimestamp>& data_with_timestamps) {
+ std::stringstream ss;
+ ss << "[";
+ for (const DataWithTimestamp& data : data_with_timestamps) {
+ ss << "\n (" << data.start_timestamp_ms << ": " << data.DataInHex()
+ << "),";
+ }
+ ss << "\n]";
+ return ss.str();
+}
+
+bool DataWithTimestamp::ContainsTime(const int64_t timestamp_ms) const {
+ return start_timestamp_ms <= timestamp_ms && timestamp_ms < end_timestamp_ms;
+}
+
+std::string DataWithTimestamp::DataInHex() const {
+ std::stringstream ss;
+ ss << "0x";
+ for (uint8_t byte : data) {
+ ss << std::hex << std::setfill('0') << std::setw(2)
+ << static_cast<uint64_t>(byte);
+ }
+ return ss.str();
+}
+
+bool DataWithTimestamp::operator==(const DataWithTimestamp& other) const {
+ return data == other.data && start_timestamp_ms == other.start_timestamp_ms &&
+ end_timestamp_ms == other.end_timestamp_ms;
+}
+
+} // namespace cryptauth
« no previous file with comments | « components/cryptauth/data_with_timestamp.h ('k') | components/cryptauth/foreground_eid_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698