Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(800)

Side by Side Diff: components/wifi_sync/wifi_credential.h

Issue 809803005: wifi_sync: add ability to convert WifiCredential to onc properties (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@submit-4.0-wifi-security-class
Patch Set: add validation, return onc_properties via scoped_ptr, fix nits Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/memory/scoped_ptr.h"
14 #include "components/wifi_sync/wifi_security_class.h" 15 #include "components/wifi_sync/wifi_security_class.h"
15 16
17 namespace base {
18 class DictionaryValue;
19 }
20
16 namespace wifi_sync { 21 namespace wifi_sync {
17 22
18 // A container to hold the information required to locate and connect 23 // A container to hold the information required to locate and connect
19 // to a WiFi network. 24 // to a WiFi network.
20 class WifiCredential final { // final because the class is copyable 25 class WifiCredential final { // final because the class is copyable
21 public: 26 public:
22 using SsidBytes = std::vector<uint8_t>; 27 using SsidBytes = std::vector<uint8_t>;
23 using CredentialSet = std::set< 28 using CredentialSet = std::set<
24 WifiCredential, 29 WifiCredential,
25 bool(*)(const WifiCredential&a, const WifiCredential& b)>; 30 bool(*)(const WifiCredential&a, const WifiCredential& b)>;
26 31
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 SsidBytes& ssid,
31 WifiSecurityClass security_class,
32 const std::string& passphrase);
33 ~WifiCredential(); 32 ~WifiCredential();
34 33
35 const SsidBytes& ssid() const { return ssid_; } 34 const SsidBytes& ssid() const { return ssid_; }
36 WifiSecurityClass security_class() const { return security_class_; } 35 WifiSecurityClass security_class() const { return security_class_; }
37 const std::string& passphrase() const { return passphrase_; } 36 const std::string& passphrase() const { return passphrase_; }
38 37
38 // Returns a dictionary which represents this WifiCredential as ONC
39 // properties. The resulting dictionary can be used, e.g, to
40 // configure a new network using
41 // chromeos::NetworkConfigurationHandler::CreateConfiguration. Due
42 // to limitations in ONC, this operation fails if ssid() is not
43 // valid UTF-8. In case of failure, returns a scoped_ptr with value
44 // nullptr.
45 scoped_ptr<base::DictionaryValue> ToOncProperties() const;
46
39 // Returns a string representation of the credential, for debugging 47 // Returns a string representation of the credential, for debugging
40 // purposes. The string will not include the credential's passphrase. 48 // purposes. The string will not include the credential's passphrase.
41 std::string ToString() const; 49 std::string ToString() const;
42 50
51 // Creates a WifiCredential with the given |ssid|, |security_class|,
52 // and |passphrase|. No assumptions are made about the input
53 // encoding of |ssid|. |passphrase|, however, must be valid
54 // UTF-8. Returns a scoped_ptr to the created WifiCredential. If the
55 // parameters are invalid, returns a scoped_ptr with value nullptr.
56 static scoped_ptr<WifiCredential> Create(
57 const SsidBytes& ssid,
58 WifiSecurityClass security_class,
59 const std::string& passphrase);
60
43 // Returns true if credential |a| comes before credential |b|. 61 // Returns true if credential |a| comes before credential |b|.
44 static bool IsLessThan(const WifiCredential& a, const WifiCredential& b); 62 static bool IsLessThan(const WifiCredential& a, const WifiCredential& b);
45 63
46 // Returns an empty set of WifiCredentials, with the IsLessThan 64 // Returns an empty set of WifiCredentials, with the IsLessThan
47 // ordering function plumbed in. 65 // ordering function plumbed in.
48 static CredentialSet MakeSet(); 66 static CredentialSet MakeSet();
49 67
68 // Returns |ssid| as an SsidBytes instance. This convenience
69 // function simplifies some tests, which need to instantiate
70 // SsidBytes from string literals.
71 static SsidBytes MakeSsidBytesForTest(const std::string& ssid);
72
50 private: 73 private:
74 // Constructs a credential with the given |ssid|, |security_class|,
75 // and |passphrase|.
76 WifiCredential(const SsidBytes& ssid,
77 WifiSecurityClass security_class,
78 const std::string& passphrase);
79
51 // The WiFi network's SSID. 80 // The WiFi network's SSID.
52 const SsidBytes ssid_; 81 const SsidBytes ssid_;
53 // The WiFi network's security class (e.g. WEP, PSK). 82 // The WiFi network's security class (e.g. WEP, PSK).
54 const WifiSecurityClass security_class_; 83 const WifiSecurityClass security_class_;
55 // The passphrase for connecting to the network. 84 // The passphrase for connecting to the network.
56 const std::string passphrase_; 85 const std::string passphrase_;
57 }; 86 };
58 87
59 } // namespace wifi_sync 88 } // namespace wifi_sync
60 89
61 #endif // COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_H_ 90 #endif // COMPONENTS_WIFI_SYNC_WIFI_CREDENTIAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698