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 COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_
6 #define COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_
11 #include "base/basictypes.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/stl_util.h"
16 #include "components/ownership/ownership_export.h"
19 struct PK11SlotInfoStr
;
20 typedef struct PK11SlotInfoStr PK11SlotInfo
;
21 #endif // defined(USE_NSS)
29 class OwnerKeyUtilTest
;
31 // This class is a ref-counted wrapper around a plain public key.
32 class OWNERSHIP_EXPORT PublicKey
33 : public base::RefCountedThreadSafe
<PublicKey
> {
37 std::vector
<uint8
>& data() { return data_
; }
39 bool is_loaded() const { return !data_
.empty(); }
41 std::string
as_string() {
42 return std::string(reinterpret_cast<const char*>(vector_as_array(&data_
)),
47 friend class base::RefCountedThreadSafe
<PublicKey
>;
51 std::vector
<uint8
> data_
;
53 DISALLOW_COPY_AND_ASSIGN(PublicKey
);
56 // This class is a ref-counted wrapper around a crypto::RSAPrivateKey
58 class OWNERSHIP_EXPORT PrivateKey
59 : public base::RefCountedThreadSafe
<PrivateKey
> {
61 explicit PrivateKey(crypto::RSAPrivateKey
* key
);
63 crypto::RSAPrivateKey
* key() { return key_
.get(); }
66 friend class base::RefCountedThreadSafe
<PrivateKey
>;
68 virtual ~PrivateKey();
70 scoped_ptr
<crypto::RSAPrivateKey
> key_
;
72 DISALLOW_COPY_AND_ASSIGN(PrivateKey
);
75 // This class is a helper class that allows to import public/private
76 // parts of the owner key.
77 class OWNERSHIP_EXPORT OwnerKeyUtil
78 : public base::RefCountedThreadSafe
<OwnerKeyUtil
> {
80 // Attempts to read the public key from the file system. Upon success,
81 // returns true and populates |output|. False on failure.
82 virtual bool ImportPublicKey(std::vector
<uint8
>* output
) = 0;
85 // Looks for the private key associated with |key| in the |slot|
86 // and returns it if it can be found. Returns NULL otherwise.
87 // Caller takes ownership.
88 virtual crypto::RSAPrivateKey
* FindPrivateKeyInSlot(
89 const std::vector
<uint8
>& key
,
90 PK11SlotInfo
* slot
) = 0;
91 #endif // defined(USE_NSS)
93 // Checks whether the public key is present in the file system.
94 virtual bool IsPublicKeyPresent() = 0;
97 virtual ~OwnerKeyUtil() {}
100 friend class base::RefCountedThreadSafe
<OwnerKeyUtil
>;
103 } // namespace ownership
105 #endif // COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_