Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / settings / owner_key_util.h
blob8e42a50da0ef8dc78e4932ab447f8f41110a020e
1 // Copyright (c) 2012 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 CHROME_BROWSER_CHROMEOS_SETTINGS_OWNER_KEY_UTIL_H_
6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_OWNER_KEY_UTIL_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h"
14 #include "base/gtest_prod_util.h"
15 #include "base/memory/ref_counted.h"
17 namespace base {
18 class FilePath;
21 namespace crypto {
22 class RSAPrivateKey;
25 namespace chromeos {
27 class OwnerKeyUtilTest;
29 class OwnerKeyUtil : public base::RefCountedThreadSafe<OwnerKeyUtil> {
30 public:
31 // Creates an OwnerKeyUtil instance.
32 static OwnerKeyUtil* Create();
34 // Attempts to read the public key from the file system.
35 // Upon success, returns true and populates |output|. False on failure.
36 virtual bool ImportPublicKey(std::vector<uint8>* output) = 0;
38 // Looks for the private key associated with |key| in the default slot,
39 // and returns it if it can be found. Returns NULL otherwise.
40 // Caller takes ownership.
41 virtual crypto::RSAPrivateKey* FindPrivateKey(
42 const std::vector<uint8>& key) = 0;
44 // Checks whether the public key is present in the file system.
45 virtual bool IsPublicKeyPresent() = 0;
47 protected:
48 OwnerKeyUtil();
49 virtual ~OwnerKeyUtil();
51 private:
52 friend class base::RefCountedThreadSafe<OwnerKeyUtil>;
54 FRIEND_TEST_ALL_PREFIXES(OwnerKeyUtilTest, ExportImportPublicKey);
57 // Implementation of OwnerKeyUtil that is used in production code.
58 class OwnerKeyUtilImpl : public OwnerKeyUtil {
59 public:
60 explicit OwnerKeyUtilImpl(const base::FilePath& public_key_file);
62 // OwnerKeyUtil:
63 virtual bool ImportPublicKey(std::vector<uint8>* output) OVERRIDE;
64 virtual crypto::RSAPrivateKey* FindPrivateKey(
65 const std::vector<uint8>& key) OVERRIDE;
66 virtual bool IsPublicKeyPresent() OVERRIDE;
68 protected:
69 virtual ~OwnerKeyUtilImpl();
71 private:
72 // The file that holds the public key.
73 base::FilePath key_file_;
75 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtilImpl);
78 } // namespace chromeos
80 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_OWNER_KEY_UTIL_H_