OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_H_ | 5 #ifndef COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_H_ |
6 #define COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_H_ | 6 #define COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
| 10 #include <memory> |
10 #include <set> | 11 #include <set> |
11 #include <string> | 12 #include <string> |
12 #include <vector> | 13 #include <vector> |
13 | 14 |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "components/wifi_sync/wifi_security_class.h" | 15 #include "components/wifi_sync/wifi_security_class.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class DictionaryValue; | 18 class DictionaryValue; |
19 } | 19 } |
20 | 20 |
21 namespace wifi_sync { | 21 namespace wifi_sync { |
22 | 22 |
23 // A container to hold the information required to locate and connect | 23 // A container to hold the information required to locate and connect |
24 // to a WiFi network. | 24 // to a WiFi network. |
25 class WifiCredential final { // final because the class is copyable | 25 class WifiCredential final { // final because the class is copyable |
26 public: | 26 public: |
27 // Per IEEE 802.11-2012 (Sec 8.4.2.2), the only requirement on SSIDs | 27 // Per IEEE 802.11-2012 (Sec 8.4.2.2), the only requirement on SSIDs |
28 // is that they are between 0 and 32 bytes in length | 28 // is that they are between 0 and 32 bytes in length |
29 // (inclusive). There are no restrictions on the values of those | 29 // (inclusive). There are no restrictions on the values of those |
30 // bytes. The SSID is not, e.g., required to be encoded as UTF-8. | 30 // bytes. The SSID is not, e.g., required to be encoded as UTF-8. |
31 using SsidBytes = std::vector<uint8_t>; | 31 using SsidBytes = std::vector<uint8_t>; |
32 using CredentialSet = std::set< | 32 using CredentialSet = std::set< |
33 WifiCredential, | 33 WifiCredential, |
34 bool(*)(const WifiCredential&a, const WifiCredential& b)>; | 34 bool(*)(const WifiCredential&a, const WifiCredential& b)>; |
35 | 35 |
36 WifiCredential(const WifiCredential& other); | 36 WifiCredential(const WifiCredential& other); |
37 ~WifiCredential(); | 37 ~WifiCredential(); |
38 | 38 |
39 // Creates a WifiCredential with the given |ssid|, |security_class|, | 39 // Creates a WifiCredential with the given |ssid|, |security_class|, |
40 // and |passphrase|. No assumptions are made about the input | 40 // and |passphrase|. No assumptions are made about the input |
41 // encoding of |ssid|. |passphrase|, however, must be valid | 41 // encoding of |ssid|. |passphrase|, however, must be valid |
42 // UTF-8. Returns NULL if the parameters are invalid. | 42 // UTF-8. Returns NULL if the parameters are invalid. |
43 static scoped_ptr<WifiCredential> Create( | 43 static std::unique_ptr<WifiCredential> Create( |
44 const SsidBytes& ssid, | 44 const SsidBytes& ssid, |
45 WifiSecurityClass security_class, | 45 WifiSecurityClass security_class, |
46 const std::string& passphrase); | 46 const std::string& passphrase); |
47 | 47 |
48 const SsidBytes& ssid() const { return ssid_; } | 48 const SsidBytes& ssid() const { return ssid_; } |
49 WifiSecurityClass security_class() const { return security_class_; } | 49 WifiSecurityClass security_class() const { return security_class_; } |
50 const std::string& passphrase() const { return passphrase_; } | 50 const std::string& passphrase() const { return passphrase_; } |
51 | 51 |
52 // Returns a dictionary which represents this WifiCredential as ONC | 52 // Returns a dictionary which represents this WifiCredential as ONC |
53 // properties. The resulting dictionary can be used, e.g, to | 53 // properties. The resulting dictionary can be used, e.g, to |
54 // configure a new network using | 54 // configure a new network using |
55 // chromeos::NetworkConfigurationHandler::CreateConfiguration. Due | 55 // chromeos::NetworkConfigurationHandler::CreateConfiguration. Due |
56 // to limitations in ONC, this operation fails if ssid() is not | 56 // to limitations in ONC, this operation fails if ssid() is not |
57 // valid UTF-8. In case of failure, returns a scoped_ptr with value | 57 // valid UTF-8. In case of failure, returns a scoped_ptr with value |
58 // nullptr. | 58 // nullptr. |
59 scoped_ptr<base::DictionaryValue> ToOncProperties() const; | 59 std::unique_ptr<base::DictionaryValue> ToOncProperties() const; |
60 | 60 |
61 // Returns a string representation of the credential, for debugging | 61 // Returns a string representation of the credential, for debugging |
62 // purposes. The string will not include the credential's passphrase. | 62 // purposes. The string will not include the credential's passphrase. |
63 std::string ToString() const; | 63 std::string ToString() const; |
64 | 64 |
65 // Returns true if credential |a| comes before credential |b|. | 65 // Returns true if credential |a| comes before credential |b|. |
66 static bool IsLessThan(const WifiCredential& a, const WifiCredential& b); | 66 static bool IsLessThan(const WifiCredential& a, const WifiCredential& b); |
67 | 67 |
68 // Returns an empty set of WifiCredentials, with the IsLessThan | 68 // Returns an empty set of WifiCredentials, with the IsLessThan |
69 // ordering function plumbed in. | 69 // ordering function plumbed in. |
(...skipping 15 matching lines...) Expand all Loading... |
85 const SsidBytes ssid_; | 85 const SsidBytes ssid_; |
86 // The WiFi network's security class (e.g. WEP, PSK). | 86 // The WiFi network's security class (e.g. WEP, PSK). |
87 const WifiSecurityClass security_class_; | 87 const WifiSecurityClass security_class_; |
88 // The passphrase for connecting to the network. | 88 // The passphrase for connecting to the network. |
89 const std::string passphrase_; | 89 const std::string passphrase_; |
90 }; | 90 }; |
91 | 91 |
92 } // namespace wifi_sync | 92 } // namespace wifi_sync |
93 | 93 |
94 #endif // COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_H_ | 94 #endif // COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_H_ |
OLD | NEW |