OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_H_ | |
6 #define COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <set> | |
11 #include <string> | |
12 #include <vector> | |
13 | |
14 #include "components/wifi_sync/wifi_security_class.h" | |
15 | |
16 namespace wifi_sync { | |
17 | |
18 // A container to hold the information required to locate and connect | |
19 // to a WiFi network. | |
20 class WifiCredential final { // final because the class is copyable | |
21 public: | |
22 using SsidBytes = std::vector<uint8_t>; | |
23 using CredentialSet = std::set< | |
24 WifiCredential, | |
25 bool(*)(const WifiCredential&a, const WifiCredential& b)>; | |
26 | |
27 // Constructs a credential with the given |ssid|, |security_class|, | |
28 // and |passphrase|. No assumptions are made about the input | |
29 // encoding of |ssid|. The passphrase must be valid UTF-8. | |
30 WifiCredential(const char* ssid, | |
31 WifiSecurityClass security_class, | |
32 const std::string& passphrase); | |
stevenjb
2014/12/05 20:28:17
nit: blank line between methods
mukesh agrawal
2014/12/05 23:48:11
Acknowledged.
| |
33 // Constructs a credential with the given |ssid|, |security_class|, | |
34 // and |passphrase|. No assumptions are made about the input | |
35 // encoding of |ssid|. The passphrase must be valid UTF-8. | |
36 WifiCredential(const SsidBytes& ssid, | |
37 WifiSecurityClass security_class, | |
38 const std::string& passphrase); | |
stevenjb
2014/12/05 20:28:17
We try to avoid multiple constructors. Do we reall
mukesh agrawal
2014/12/05 23:48:11
Done.
| |
39 ~WifiCredential(); | |
40 | |
41 const SsidBytes& ssid() const { return ssid_; } | |
42 WifiSecurityClass security_class() const { return security_class_; } | |
43 const std::string& passphrase() const { return passphrase_; } | |
44 | |
45 // Returns a string representation of the credential. The string | |
46 // will not include the credential's passphrase. | |
47 std::string ToString() const; | |
48 | |
49 // Returns true if credential |a| comes before credential |b|. | |
50 static bool IsLessThan(const WifiCredential& a, const WifiCredential& b); | |
stevenjb
2014/12/05 20:28:17
WS
mukesh agrawal
2014/12/05 23:48:11
Done.
Following the pattern of chromeos/network/c
| |
51 // Returns an empty set of WifiCredentials, with the IsLessThan | |
52 // ordering function plumbed in. | |
53 static CredentialSet MakeSet(); | |
54 | |
55 private: | |
56 // The WiFi network's SSID. | |
57 const SsidBytes ssid_; | |
58 // The WiFi network's security class (e.g. WEP, PSK). | |
59 const WifiSecurityClass security_class_; | |
60 // The passphrase for connecting to the network. | |
61 const std::string passphrase_; | |
62 }; | |
63 | |
64 } // namespace wifi_sync | |
65 | |
66 #endif // COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_H_ | |
OLD | NEW |