OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_ | 5 #ifndef COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_ |
6 #define COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_ | 6 #define COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_ |
7 | 7 |
| 8 #include <stdint.h> |
| 9 |
8 #include <string> | 10 #include <string> |
9 #include <vector> | 11 #include <vector> |
10 | 12 |
11 #include "base/basictypes.h" | |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "components/ownership/ownership_export.h" | 16 #include "components/ownership/ownership_export.h" |
16 #include "crypto/scoped_nss_types.h" | 17 #include "crypto/scoped_nss_types.h" |
17 | 18 |
18 struct PK11SlotInfoStr; | 19 struct PK11SlotInfoStr; |
19 typedef struct PK11SlotInfoStr PK11SlotInfo; | 20 typedef struct PK11SlotInfoStr PK11SlotInfo; |
20 | 21 |
21 namespace ownership { | 22 namespace ownership { |
22 | 23 |
23 class OwnerKeyUtilTest; | 24 class OwnerKeyUtilTest; |
24 | 25 |
25 // This class is a ref-counted wrapper around a plain public key. | 26 // This class is a ref-counted wrapper around a plain public key. |
26 class OWNERSHIP_EXPORT PublicKey | 27 class OWNERSHIP_EXPORT PublicKey |
27 : public base::RefCountedThreadSafe<PublicKey> { | 28 : public base::RefCountedThreadSafe<PublicKey> { |
28 public: | 29 public: |
29 PublicKey(); | 30 PublicKey(); |
30 | 31 |
31 std::vector<uint8>& data() { return data_; } | 32 std::vector<uint8_t>& data() { return data_; } |
32 | 33 |
33 bool is_loaded() const { return !data_.empty(); } | 34 bool is_loaded() const { return !data_.empty(); } |
34 | 35 |
35 std::string as_string() { | 36 std::string as_string() { |
36 return std::string(reinterpret_cast<const char*>(data_.data()), | 37 return std::string(reinterpret_cast<const char*>(data_.data()), |
37 data_.size()); | 38 data_.size()); |
38 } | 39 } |
39 | 40 |
40 private: | 41 private: |
41 friend class base::RefCountedThreadSafe<PublicKey>; | 42 friend class base::RefCountedThreadSafe<PublicKey>; |
42 | 43 |
43 virtual ~PublicKey(); | 44 virtual ~PublicKey(); |
44 | 45 |
45 std::vector<uint8> data_; | 46 std::vector<uint8_t> data_; |
46 | 47 |
47 DISALLOW_COPY_AND_ASSIGN(PublicKey); | 48 DISALLOW_COPY_AND_ASSIGN(PublicKey); |
48 }; | 49 }; |
49 | 50 |
50 // This class is a ref-counted wrapper around a SECKEYPrivateKey | 51 // This class is a ref-counted wrapper around a SECKEYPrivateKey |
51 // instance. | 52 // instance. |
52 class OWNERSHIP_EXPORT PrivateKey | 53 class OWNERSHIP_EXPORT PrivateKey |
53 : public base::RefCountedThreadSafe<PrivateKey> { | 54 : public base::RefCountedThreadSafe<PrivateKey> { |
54 public: | 55 public: |
55 explicit PrivateKey(crypto::ScopedSECKEYPrivateKey key); | 56 explicit PrivateKey(crypto::ScopedSECKEYPrivateKey key); |
(...skipping 10 matching lines...) Expand all Loading... |
66 DISALLOW_COPY_AND_ASSIGN(PrivateKey); | 67 DISALLOW_COPY_AND_ASSIGN(PrivateKey); |
67 }; | 68 }; |
68 | 69 |
69 // This class is a helper class that allows to import public/private | 70 // This class is a helper class that allows to import public/private |
70 // parts of the owner key. | 71 // parts of the owner key. |
71 class OWNERSHIP_EXPORT OwnerKeyUtil | 72 class OWNERSHIP_EXPORT OwnerKeyUtil |
72 : public base::RefCountedThreadSafe<OwnerKeyUtil> { | 73 : public base::RefCountedThreadSafe<OwnerKeyUtil> { |
73 public: | 74 public: |
74 // Attempts to read the public key from the file system. Upon success, | 75 // Attempts to read the public key from the file system. Upon success, |
75 // returns true and populates |output|. False on failure. | 76 // returns true and populates |output|. False on failure. |
76 virtual bool ImportPublicKey(std::vector<uint8>* output) = 0; | 77 virtual bool ImportPublicKey(std::vector<uint8_t>* output) = 0; |
77 | 78 |
78 // Looks for the private key associated with |key| in the |slot| | 79 // Looks for the private key associated with |key| in the |slot| |
79 // and returns it if it can be found. Returns NULL otherwise. | 80 // and returns it if it can be found. Returns NULL otherwise. |
80 // Caller takes ownership. | 81 // Caller takes ownership. |
81 virtual crypto::ScopedSECKEYPrivateKey FindPrivateKeyInSlot( | 82 virtual crypto::ScopedSECKEYPrivateKey FindPrivateKeyInSlot( |
82 const std::vector<uint8>& key, | 83 const std::vector<uint8_t>& key, |
83 PK11SlotInfo* slot) = 0; | 84 PK11SlotInfo* slot) = 0; |
84 | 85 |
85 // Checks whether the public key is present in the file system. | 86 // Checks whether the public key is present in the file system. |
86 virtual bool IsPublicKeyPresent() = 0; | 87 virtual bool IsPublicKeyPresent() = 0; |
87 | 88 |
88 protected: | 89 protected: |
89 virtual ~OwnerKeyUtil() {} | 90 virtual ~OwnerKeyUtil() {} |
90 | 91 |
91 private: | 92 private: |
92 friend class base::RefCountedThreadSafe<OwnerKeyUtil>; | 93 friend class base::RefCountedThreadSafe<OwnerKeyUtil>; |
93 }; | 94 }; |
94 | 95 |
95 } // namespace ownership | 96 } // namespace ownership |
96 | 97 |
97 #endif // COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_ | 98 #endif // COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_ |
OLD | NEW |