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_
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"
27 class OwnerKeyUtilTest
;
29 class OwnerKeyUtil
: public base::RefCountedThreadSafe
<OwnerKeyUtil
> {
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;
49 virtual ~OwnerKeyUtil();
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
{
60 explicit OwnerKeyUtilImpl(const base::FilePath
& public_key_file
);
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
;
69 virtual ~OwnerKeyUtilImpl();
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_