1 // Copyright 2015 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.
5 #include "components/wifi_sync/wifi_security_class.h"
7 #include "base/logging.h"
8 #include "components/onc/onc_constants.h"
12 bool WifiSecurityClassSupportsPassphrases(
13 const WifiSecurityClass security_class
) {
14 switch (security_class
) {
15 case SECURITY_CLASS_NONE
:
17 case SECURITY_CLASS_WEP
:
18 case SECURITY_CLASS_PSK
:
19 case SECURITY_CLASS_802_1X
:
21 case SECURITY_CLASS_INVALID
:
24 NOTREACHED() << "Invalid WifiSecurityClass enum with value "
29 WifiSecurityClass
WifiSecurityClassFromSyncSecurityClass(
30 const sync_pb::WifiCredentialSpecifics_SecurityClass sync_enum
) {
32 case SECURITY_CLASS_INVALID
:
33 return WifiSecurityClass::SECURITY_CLASS_INVALID
;
34 case SECURITY_CLASS_NONE
:
35 return WifiSecurityClass::SECURITY_CLASS_NONE
;
36 case SECURITY_CLASS_WEP
:
37 return WifiSecurityClass::SECURITY_CLASS_WEP
;
38 case SECURITY_CLASS_PSK
:
39 return WifiSecurityClass::SECURITY_CLASS_PSK
;
41 NOTREACHED() << "Invalid sync security class enum with value " << sync_enum
;
42 return WifiSecurityClass::SECURITY_CLASS_INVALID
;
45 sync_pb::WifiCredentialSpecifics_SecurityClass
46 WifiSecurityClassToSyncSecurityClass(const WifiSecurityClass security_class
) {
47 switch (security_class
) {
48 case SECURITY_CLASS_NONE
:
49 return sync_pb::WifiCredentialSpecifics::SECURITY_CLASS_NONE
;
50 case SECURITY_CLASS_WEP
:
51 return sync_pb::WifiCredentialSpecifics::SECURITY_CLASS_WEP
;
52 case SECURITY_CLASS_PSK
:
53 return sync_pb::WifiCredentialSpecifics::SECURITY_CLASS_PSK
;
54 case SECURITY_CLASS_802_1X
:
55 LOG(WARNING
) << "Unsupported security class 802.1X";
56 return sync_pb::WifiCredentialSpecifics::SECURITY_CLASS_INVALID
;
57 case SECURITY_CLASS_INVALID
:
58 return sync_pb::WifiCredentialSpecifics::SECURITY_CLASS_INVALID
;
60 NOTREACHED() << "Invalid WifiSecurityClass enum with value "
62 return sync_pb::WifiCredentialSpecifics::SECURITY_CLASS_INVALID
;
65 bool WifiSecurityClassToOncSecurityString(WifiSecurityClass security_class
,
66 std::string
* security_class_string
) {
67 DCHECK(security_class_string
);
68 switch (security_class
) {
69 case SECURITY_CLASS_NONE
:
70 *security_class_string
= onc::wifi::kSecurityNone
;
72 case SECURITY_CLASS_WEP
:
73 *security_class_string
= onc::wifi::kWEP_PSK
;
75 case SECURITY_CLASS_PSK
:
76 *security_class_string
= onc::wifi::kWPA_PSK
;
78 case SECURITY_CLASS_802_1X
:
79 *security_class_string
= onc::wifi::kWPA_EAP
;
81 case SECURITY_CLASS_INVALID
:
84 NOTREACHED() << "Invalid WifiSecurityClass enum with value "
89 } // namespace wifi_sync