Roll src/third_party/WebKit abe9e39c:3d349bd (svn 182659:182669)
[chromium-blink-merge.git] / chromeos / login / auth / key.h
blob969c8245b605864bbdceb83722506fa0cd1a44b4
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.
5 #ifndef CHROMEOS_LOGIN_AUTH_KEY_H_
6 #define CHROMEOS_LOGIN_AUTH_KEY_H_
8 #include <string>
10 #include "chromeos/chromeos_export.h"
12 namespace chromeos {
14 // Key for user authentication. The class supports hashing of plain text
15 // passwords to generate keys as well as the use of pre-hashed keys.
16 class CHROMEOS_EXPORT Key {
17 public:
18 enum KeyType {
19 // Plain text password.
20 KEY_TYPE_PASSWORD_PLAIN = 0,
21 // SHA256 of salt + password, first half only, lower-case hex encoded.
22 KEY_TYPE_SALTED_SHA256_TOP_HALF = 1,
23 // PBKDF2 with 256 bit AES and 1234 iterations, base64 encoded.
24 KEY_TYPE_SALTED_PBKDF2_AES256_1234 = 2,
25 // SHA256 of salt + password, base64 encoded.
26 KEY_TYPE_SALTED_SHA256 = 3,
28 // Sentinel. Must be last.
29 KEY_TYPE_COUNT
32 Key();
33 Key(const Key& other);
34 explicit Key(const std::string& plain_text_password);
35 Key(KeyType key_type, const std::string& salt, const std::string& secret);
36 ~Key();
38 bool operator==(const Key& other) const;
40 KeyType GetKeyType() const;
41 const std::string& GetSecret() const;
42 const std::string& GetLabel() const;
44 void SetLabel(const std::string& label);
46 void ClearSecret();
48 void Transform(KeyType target_key_type, const std::string& salt);
50 private:
51 KeyType key_type_;
52 std::string salt_;
53 std::string secret_;
54 std::string label_;
57 } // namespace chromeos
59 #endif // CHROMEOS_LOGIN_AUTH_KEY_H_