File: wifi_credential.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (94 lines) | stat: -rw-r--r-- 3,445 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SYNC_WIFI_WIFI_CREDENTIAL_H_
#define COMPONENTS_SYNC_WIFI_WIFI_CREDENTIAL_H_

#include <stdint.h>

#include <memory>
#include <set>
#include <string>
#include <vector>

#include "components/sync_wifi/wifi_security_class.h"

namespace base {
class DictionaryValue;
}

namespace sync_wifi {

// A container to hold the information required to locate and connect
// to a WiFi network.
class WifiCredential final {  // final because the class is copyable
 public:
  // Per IEEE 802.11-2012 (Sec 8.4.2.2), the only requirement on SSIDs
  // is that they are between 0 and 32 bytes in length
  // (inclusive). There are no restrictions on the values of those
  // bytes. The SSID is not, e.g., required to be encoded as UTF-8.
  using SsidBytes = std::vector<uint8_t>;
  using CredentialSet =
      std::set<WifiCredential,
               bool (*)(const WifiCredential& a, const WifiCredential& b)>;

  WifiCredential(const WifiCredential& other);
  ~WifiCredential();

  // Creates a WifiCredential with the given |ssid|, |security_class|,
  // and |passphrase|. No assumptions are made about the input
  // encoding of |ssid|. |passphrase|, however, must be valid
  // UTF-8. Returns NULL if the parameters are invalid.
  static std::unique_ptr<WifiCredential> Create(
      const SsidBytes& ssid,
      WifiSecurityClass security_class,
      const std::string& passphrase);

  const SsidBytes& ssid() const { return ssid_; }
  WifiSecurityClass security_class() const { return security_class_; }
  const std::string& passphrase() const { return passphrase_; }

  // Returns a dictionary which represents this WifiCredential as ONC
  // properties. The resulting dictionary can be used, e.g, to
  // configure a new network using
  // chromeos::NetworkConfigurationHandler::CreateConfiguration. Due
  // to limitations in ONC, this operation fails if ssid() is not
  // valid UTF-8. In case of failure, returns a scoped_ptr with value
  // nullptr.
  std::unique_ptr<base::DictionaryValue> ToOncProperties() const;

  // Returns a string representation of the credential, for debugging
  // purposes. The string will not include the credential's passphrase.
  std::string ToString() const;

  // Returns true if credential |a| comes before credential |b|.
  static bool IsLessThan(const WifiCredential& a, const WifiCredential& b);

  // Returns an empty set of WifiCredentials, with the IsLessThan
  // ordering function plumbed in.
  static CredentialSet MakeSet();

  // Returns |ssid| as an SsidBytes instance. This convenience
  // function simplifies some tests, which need to instantiate
  // SsidBytes from string literals.
  static SsidBytes MakeSsidBytesForTest(const std::string& ssid);

 private:
  // Constructs a credential with the given |ssid|, |security_class|,
  // and |passphrase|.
  WifiCredential(const SsidBytes& ssid,
                 WifiSecurityClass security_class,
                 const std::string& passphrase);

  // The WiFi network's SSID.
  const SsidBytes ssid_;
  // The WiFi network's security class (e.g. WEP, PSK).
  const WifiSecurityClass security_class_;
  // The passphrase for connecting to the network.
  const std::string passphrase_;
};

}  // namespace sync_wifi

#endif  // COMPONENTS_SYNC_WIFI_WIFI_CREDENTIAL_H_