OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef DEVICE_BLUETOOTH_PUBLIC_INTERFACES_BLUETOOTH_UUID_STRUCT_TRAITS_H_ | 5 #ifndef DEVICE_BLUETOOTH_PUBLIC_INTERFACES_BLUETOOTH_UUID_STRUCT_TRAITS_H_ |
6 #define DEVICE_BLUETOOTH_PUBLIC_INTERFACES_BLUETOOTH_UUID_STRUCT_TRAITS_H_ | 6 #define DEVICE_BLUETOOTH_PUBLIC_INTERFACES_BLUETOOTH_UUID_STRUCT_TRAITS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "device/bluetooth/bluetooth_uuid.h" | 10 #include "device/bluetooth/bluetooth_uuid.h" |
11 #include "device/bluetooth/public/interfaces/bluetooth_uuid.mojom.h" | 11 #include "device/bluetooth/public/interfaces/bluetooth_uuid.mojom.h" |
12 | 12 |
13 namespace mojo { | 13 namespace mojo { |
14 | 14 |
15 template <> | 15 template <> |
16 struct StructTraits<device::mojom::BluetoothUUID, device::BluetoothUUID> { | 16 struct StructTraits<device::mojom::BluetoothUUIDDataView, |
| 17 device::BluetoothUUID> { |
17 static const std::string& uuid(const device::BluetoothUUID& uuid) { | 18 static const std::string& uuid(const device::BluetoothUUID& uuid) { |
18 return uuid.canonical_value(); | 19 return uuid.canonical_value(); |
19 } | 20 } |
20 | 21 |
21 static bool Read(device::mojom::BluetoothUUIDDataView input, | 22 static bool Read(device::mojom::BluetoothUUIDDataView input, |
22 device::BluetoothUUID* output) { | 23 device::BluetoothUUID* output) { |
23 std::string result; | 24 std::string result; |
24 if (!input.ReadUuid(&result)) | 25 if (!input.ReadUuid(&result)) |
25 return false; | 26 return false; |
26 *output = device::BluetoothUUID(result); | 27 *output = device::BluetoothUUID(result); |
27 | 28 |
28 // If the format isn't 128-bit, .value() would return a different answer | 29 // If the format isn't 128-bit, .value() would return a different answer |
29 // than .canonical_value(). Then if browser-side code accidentally checks | 30 // than .canonical_value(). Then if browser-side code accidentally checks |
30 // .value() against a 128-bit string literal, a hostile renderer could use | 31 // .value() against a 128-bit string literal, a hostile renderer could use |
31 // the 16- or 32-bit format and evade the check. | 32 // the 16- or 32-bit format and evade the check. |
32 return output->IsValid() && | 33 return output->IsValid() && |
33 output->format() == device::BluetoothUUID::kFormat128Bit; | 34 output->format() == device::BluetoothUUID::kFormat128Bit; |
34 } | 35 } |
35 }; | 36 }; |
36 | 37 |
37 } // namespace mojo | 38 } // namespace mojo |
38 | 39 |
39 #endif // DEVICE_BLUETOOTH_PUBLIC_INTERFACES_BLUETOOTH_UUID_STRUCT_TRAITS_H_ | 40 #endif // DEVICE_BLUETOOTH_PUBLIC_INTERFACES_BLUETOOTH_UUID_STRUCT_TRAITS_H_ |
OLD | NEW |