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 #include "components/wifi_sync/wifi_credential.h" |
| 6 |
| 7 #include <limits> |
| 8 #include <string> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/stringprintf.h" |
| 13 |
| 14 namespace wifi_sync { |
| 15 |
| 16 WifiCredential::WifiCredential( |
| 17 const char* ssid, |
| 18 WifiSecurityClass security_class, |
| 19 const std::string& passphrase) |
| 20 : ssid_(ssid, ssid + strlen(ssid)), |
| 21 security_class_(security_class), |
| 22 passphrase_(passphrase) { |
| 23 } |
| 24 |
| 25 WifiCredential::WifiCredential( |
| 26 const std::vector<unsigned char>& ssid, |
| 27 WifiSecurityClass security_class, |
| 28 const std::string& passphrase) |
| 29 : ssid_(ssid), |
| 30 security_class_(security_class), |
| 31 passphrase_(passphrase) { |
| 32 } |
| 33 |
| 34 WifiCredential::~WifiCredential() { |
| 35 // Nothing special to do. |
| 36 } |
| 37 |
| 38 std::string WifiCredential::ToString() const { |
| 39 DCHECK(ssid_.size() <= std::numeric_limits<size_t>::max() / 2); |
| 40 return base::StringPrintf( |
| 41 "[SSID (hex): %s, SecurityClass: %d]", |
| 42 base::HexEncode(ssid_.data(), ssid_.size()).c_str(), |
| 43 security_class_); // Passphrase deliberately omitted. |
| 44 } |
| 45 |
| 46 // static |
| 47 bool WifiCredential::IsLessThan( |
| 48 const WifiCredential& a, const WifiCredential& b) { |
| 49 return a.ssid_ < b.ssid_ || |
| 50 a.security_class_< b.security_class_ || |
| 51 a.passphrase_ < b.passphrase_; |
| 52 } |
| 53 |
| 54 // static |
| 55 WifiCredential::CredentialSet WifiCredential::MakeSet() { |
| 56 return CredentialSet(WifiCredential::IsLessThan); |
| 57 } |
| 58 |
| 59 } // namespace wifi_sync |
OLD | NEW |