OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/cryptauth/data_with_timestamp.h" |
| 6 |
| 7 #include <iomanip> |
| 8 |
| 9 #include "base/logging.h" |
| 10 |
| 11 namespace cryptauth { |
| 12 |
| 13 DataWithTimestamp::DataWithTimestamp(const std::string& data, |
| 14 const int64_t start_timestamp_ms, |
| 15 const int64_t end_timestamp_ms) |
| 16 : data(data), |
| 17 start_timestamp_ms(start_timestamp_ms), |
| 18 end_timestamp_ms(end_timestamp_ms) { |
| 19 DCHECK(start_timestamp_ms < end_timestamp_ms); |
| 20 DCHECK(data.size()); |
| 21 } |
| 22 |
| 23 DataWithTimestamp::DataWithTimestamp(const DataWithTimestamp& other) |
| 24 : data(other.data), |
| 25 start_timestamp_ms(other.start_timestamp_ms), |
| 26 end_timestamp_ms(other.end_timestamp_ms) { |
| 27 DCHECK(start_timestamp_ms < end_timestamp_ms); |
| 28 DCHECK(data.size()); |
| 29 } |
| 30 |
| 31 bool DataWithTimestamp::ContainsTime(const int64_t timestamp_ms) const { |
| 32 return start_timestamp_ms <= timestamp_ms && timestamp_ms < end_timestamp_ms; |
| 33 } |
| 34 |
| 35 std::string DataWithTimestamp::DataInHex() const { |
| 36 std::stringstream ss; |
| 37 ss << "0x"; |
| 38 for (uint8_t byte : data) { |
| 39 ss << std::hex << std::setfill('0') << std::setw(2) |
| 40 << static_cast<uint64_t>(byte); |
| 41 } |
| 42 return ss.str(); |
| 43 } |
| 44 |
| 45 bool DataWithTimestamp::operator==(const DataWithTimestamp& other) const { |
| 46 return data == other.data && start_timestamp_ms == other.start_timestamp_ms && |
| 47 end_timestamp_ms == other.end_timestamp_ms; |
| 48 } |
| 49 |
| 50 } // namespace cryptauth |
OLD | NEW |