| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "components/wifi_sync/wifi_security_class.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "components/onc/onc_constants.h" | |
| 9 | |
| 10 namespace wifi_sync { | |
| 11 | |
| 12 bool WifiSecurityClassSupportsPassphrases( | |
| 13 const WifiSecurityClass security_class) { | |
| 14 switch (security_class) { | |
| 15 case SECURITY_CLASS_NONE: | |
| 16 return false; | |
| 17 case SECURITY_CLASS_WEP: | |
| 18 case SECURITY_CLASS_PSK: | |
| 19 case SECURITY_CLASS_802_1X: | |
| 20 return true; | |
| 21 case SECURITY_CLASS_INVALID: | |
| 22 return false; | |
| 23 } | |
| 24 NOTREACHED() << "Invalid WifiSecurityClass enum with value " | |
| 25 << security_class; | |
| 26 return false; | |
| 27 } | |
| 28 | |
| 29 WifiSecurityClass WifiSecurityClassFromSyncSecurityClass( | |
| 30 const sync_pb::WifiCredentialSpecifics_SecurityClass sync_enum) { | |
| 31 switch (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; | |
| 40 } | |
| 41 NOTREACHED() << "Invalid sync security class enum with value " << sync_enum; | |
| 42 return WifiSecurityClass::SECURITY_CLASS_INVALID; | |
| 43 } | |
| 44 | |
| 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; | |
| 59 } | |
| 60 NOTREACHED() << "Invalid WifiSecurityClass enum with value " | |
| 61 << security_class; | |
| 62 return sync_pb::WifiCredentialSpecifics::SECURITY_CLASS_INVALID; | |
| 63 } | |
| 64 | |
| 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; | |
| 71 return true; | |
| 72 case SECURITY_CLASS_WEP: | |
| 73 *security_class_string = onc::wifi::kWEP_PSK; | |
| 74 return true; | |
| 75 case SECURITY_CLASS_PSK: | |
| 76 *security_class_string = onc::wifi::kWPA_PSK; | |
| 77 return true; | |
| 78 case SECURITY_CLASS_802_1X: | |
| 79 *security_class_string = onc::wifi::kWPA_EAP; | |
| 80 return true; | |
| 81 case SECURITY_CLASS_INVALID: | |
| 82 return false; | |
| 83 } | |
| 84 NOTREACHED() << "Invalid WifiSecurityClass enum with value " | |
| 85 << security_class; | |
| 86 return false; | |
| 87 } | |
| 88 | |
| 89 } // namespace wifi_sync | |
| OLD | NEW |