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

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

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: 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 #include "components/wifi_sync/wifi_credential.h" 5 #include "components/wifi_sync/wifi_credential.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
erikwright (departed) 2015/01/08 19:27:07 not required (included in header)
mukesh agrawal 2015/01/09 02:00:18 Done. Also removed limits, since it's also unnece
9 9
10 #include "base/i18n/streaming_utf8_validator.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/values.h"
15 #include "components/onc/onc_constants.h"
16 #include "components/wifi_sync/wifi_security_class.h"
erikwright (departed) 2015/01/08 19:27:07 not required (included in header)
mukesh agrawal 2015/01/09 02:00:18 Done.
13 17
14 namespace wifi_sync { 18 namespace wifi_sync {
15 19
16 WifiCredential::WifiCredential( 20 WifiCredential::WifiCredential(
17 const std::vector<unsigned char>& ssid, 21 const std::vector<unsigned char>& ssid,
18 WifiSecurityClass security_class, 22 WifiSecurityClass security_class,
19 const std::string& passphrase) 23 const std::string& passphrase)
20 : ssid_(ssid), 24 : ssid_(ssid),
21 security_class_(security_class), 25 security_class_(security_class),
22 passphrase_(passphrase) { 26 passphrase_(passphrase) {
23 } 27 }
24 28
25 WifiCredential::~WifiCredential() { 29 WifiCredential::~WifiCredential() {
26 } 30 }
27 31
32 bool WifiCredential::ToOncProperties(base::DictionaryValue* onc_properties)
33 const {
34 const std::string ssid_utf8(ssid().begin(), ssid().end());
35 if (!base::StreamingUtf8Validator::Validate(ssid_utf8)) {
36 LOG(ERROR) << "SSID is not valid UTF-8";
37 return false;
38 }
39
40 std::string onc_security;
41 if (!WifiSecurityClassToOncSecurityString(security_class(), &onc_security)) {
erikwright (departed) 2015/01/08 19:27:07 Assuming that security_class() is not ..._INVALID
mukesh agrawal 2015/01/09 02:00:18 Done. I've left in the check that the SecurityCla
erikwright (departed) 2015/01/09 14:58:20 The NOTREACHED is good, but I would remove the NUL
42 LOG(ERROR) << "Error converting SecurityClass with value "
43 << security_class();
44 return false;
45 }
46
47 onc_properties->Set(onc::toplevel_config::kType,
48 new base::StringValue(onc::network_type::kWiFi));
49 // TODO(quiche): Switch to the HexSSID property, once ONC fully supports it.
50 onc_properties->Set(onc::network_config::WifiProperty(onc::wifi::kSSID),
51 new base::StringValue(ssid_utf8));
52 onc_properties->Set(onc::network_config::WifiProperty(onc::wifi::kSecurity),
53 new base::StringValue(onc_security));
54 if (WifiSecurityClassSupportsPassphrases(security_class())) {
55 onc_properties->Set(
56 onc::network_config::WifiProperty(onc::wifi::kPassphrase),
57 new base::StringValue(passphrase()));
58 }
59 return true;
60 }
61
28 std::string WifiCredential::ToString() const { 62 std::string WifiCredential::ToString() const {
29 return base::StringPrintf( 63 return base::StringPrintf(
30 "[SSID (hex): %s, SecurityClass: %d]", 64 "[SSID (hex): %s, SecurityClass: %d]",
31 base::HexEncode(&ssid_.front(), ssid_.size()).c_str(), 65 base::HexEncode(&ssid_.front(), ssid_.size()).c_str(),
32 security_class_); // Passphrase deliberately omitted. 66 security_class_); // Passphrase deliberately omitted.
33 } 67 }
34 68
35 // static 69 // static
36 bool WifiCredential::IsLessThan( 70 bool WifiCredential::IsLessThan(
37 const WifiCredential& a, const WifiCredential& b) { 71 const WifiCredential& a, const WifiCredential& b) {
38 return a.ssid_ < b.ssid_ || 72 return a.ssid_ < b.ssid_ ||
39 a.security_class_< b.security_class_ || 73 a.security_class_< b.security_class_ ||
40 a.passphrase_ < b.passphrase_; 74 a.passphrase_ < b.passphrase_;
41 } 75 }
42 76
43 // static 77 // static
44 WifiCredential::CredentialSet WifiCredential::MakeSet() { 78 WifiCredential::CredentialSet WifiCredential::MakeSet() {
45 return CredentialSet(WifiCredential::IsLessThan); 79 return CredentialSet(WifiCredential::IsLessThan);
46 } 80 }
47 81
82 // static
83 WifiCredential::SsidBytes WifiCredential::MakeSsidBytes(
84 const std::string& ssid) {
85 return SsidBytes(ssid.begin(), ssid.end());
86 }
87
48 } // namespace wifi_sync 88 } // namespace wifi_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698