Index: mojo/common/common_custom_types_struct_traits.h |
diff --git a/mojo/common/common_custom_types_struct_traits.h b/mojo/common/common_custom_types_struct_traits.h |
index 5244cf7a2a6108280136a03f9a3bc385c49a5cb2..43eb059103f4be1f14c6faba73690fcc985f2fd4 100644 |
--- a/mojo/common/common_custom_types_struct_traits.h |
+++ b/mojo/common/common_custom_types_struct_traits.h |
@@ -5,6 +5,7 @@ |
#ifndef MOJO_COMMON_COMMON_CUSTOM_TYPES_STRUCT_TRAITS_H_ |
#define MOJO_COMMON_COMMON_CUSTOM_TYPES_STRUCT_TRAITS_H_ |
+#include "base/unguessable_token.h" |
#include "base/version.h" |
#include "mojo/common/common_custom_types.mojom-shared.h" |
@@ -23,6 +24,42 @@ struct StructTraits<mojo::common::mojom::VersionDataView, base::Version> { |
base::Version* out); |
}; |
+// If base::UnguessableToken is no longer 128 bits, the logic below and the |
+// mojom::UnguessableToken type should be updated. |
+static_assert(sizeof(base::UnguessableToken) == 2 * sizeof(uint64_t), |
+ "base::UnguessableToken should be of size 2 * sizeof(uint64_t)."); |
+ |
+template <> |
+struct StructTraits<mojo::common::mojom::UnguessableTokenDataView, |
+ base::UnguessableToken> { |
+ static uint64_t high(const base::UnguessableToken& token) { |
+ DCHECK(token); |
+ uint64_t high, low; |
+ token.Serialize(&high, &low); |
dcheng
2016/09/16 23:01:35
So, for Reasons (tm), each getter here is actually
danakj
2016/09/16 23:26:50
Honestly I think we can just expose them, I'm not
|
+ return high; |
+ } |
+ |
+ static uint64_t low(const base::UnguessableToken& token) { |
+ DCHECK(token); |
+ uint64_t high, low; |
+ token.Serialize(&high, &low); |
+ return low; |
+ } |
+ |
+ static bool Read(mojo::common::mojom::UnguessableTokenDataView data, |
+ base::UnguessableToken* out) { |
+ uint64_t high = data.high(); |
+ uint64_t low = data.low(); |
+ |
+ // Receiving a zeroed UnguessableToken is a security issue. |
+ if(high == 0 && low == 0) |
+ return false; |
+ |
+ *out = base::UnguessableToken::Deserialize(high, low); |
+ return true; |
+ } |
+}; |
+ |
template <> |
struct StructTraits<mojo::common::mojom::TimeDeltaDataView, base::TimeDelta> { |
static int64_t microseconds(const base::TimeDelta& delta) { |