OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_ | |
6 #define COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
erikwright (departed)
2014/08/28 19:41:38
same comment.
ygorshenin1
2014/08/29 10:28:58
I need basictypes.h for the definition of uint8.
| |
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" | |
17 | |
18 #if defined(USE_NSS) | |
19 struct PK11SlotInfoStr; | |
20 typedef struct PK11SlotInfoStr PK11SlotInfo; | |
21 #endif // defined(USE_NSS) | |
22 | |
23 namespace crypto { | |
24 class RSAPrivateKey; | |
25 } | |
26 | |
27 namespace ownership { | |
28 | |
29 class OwnerKeyUtilTest; | |
30 | |
31 // This class is a ref-counted wrapper around plain public key. | |
erikwright (departed)
2014/08/28 19:41:38
_a_ plain public key.
ygorshenin1
2014/08/29 10:28:58
Done.
| |
32 class OWNERSHIP_EXPORT PublicKey | |
33 : public base::RefCountedThreadSafe<PublicKey> { | |
34 public: | |
35 PublicKey(); | |
36 | |
37 std::vector<uint8>& data() { return data_; } | |
38 | |
39 bool is_loaded() const { return !data_.empty(); } | |
40 | |
41 std::string as_string() { | |
42 return std::string(reinterpret_cast<const char*>(vector_as_array(&data_)), | |
43 data_.size()); | |
44 } | |
45 | |
46 private: | |
47 friend class base::RefCountedThreadSafe<PublicKey>; | |
48 | |
49 virtual ~PublicKey(); | |
50 | |
51 std::vector<uint8> data_; | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(PublicKey); | |
54 }; | |
55 | |
56 // This class is a ref-counted wrapper around crypto::RSAPrivateKey. | |
57 class OWNERSHIP_EXPORT PrivateKey | |
58 : public base::RefCountedThreadSafe<PrivateKey> { | |
59 public: | |
60 explicit PrivateKey(crypto::RSAPrivateKey* key); | |
61 | |
62 crypto::RSAPrivateKey* key() { return key_.get(); } | |
63 | |
64 private: | |
65 friend class base::RefCountedThreadSafe<PrivateKey>; | |
66 | |
67 virtual ~PrivateKey(); | |
68 | |
69 scoped_ptr<crypto::RSAPrivateKey> key_; | |
70 | |
71 DISALLOW_COPY_AND_ASSIGN(PrivateKey); | |
72 }; | |
73 | |
74 // This class is a helper class that allows to import public/private | |
75 // parts of the owner key. | |
76 class OWNERSHIP_EXPORT OwnerKeyUtil | |
erikwright (departed)
2014/08/28 19:41:38
Do pure-virtual classes need EXPORT? Check for con
ygorshenin1
2014/08/29 10:28:58
Done.
| |
77 : public base::RefCountedThreadSafe<OwnerKeyUtil> { | |
78 public: | |
79 // Attempts to read the public key from the file system. Upon success, | |
80 // returns true and populates |output|. False on failure. | |
81 virtual bool ImportPublicKey(std::vector<uint8>* output) = 0; | |
82 | |
83 #if defined(USE_NSS) | |
84 // Looks for the private key associated with |key| in the |slot| | |
85 // and returns it if it can be found. Returns NULL otherwise. | |
86 // Caller takes ownership. | |
87 virtual crypto::RSAPrivateKey* FindPrivateKeyInSlot( | |
88 const std::vector<uint8>& key, | |
89 PK11SlotInfo* slot) = 0; | |
90 #endif // defined(USE_NSS) | |
91 | |
92 // Checks whether the public key is present in the file system. | |
93 virtual bool IsPublicKeyPresent() = 0; | |
94 | |
95 protected: | |
96 virtual ~OwnerKeyUtil() {} | |
97 | |
98 private: | |
99 friend class base::RefCountedThreadSafe<OwnerKeyUtil>; | |
100 }; | |
101 | |
102 } // namespace ownership | |
103 | |
104 #endif // COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_ | |
OLD | NEW |