Chromium Code Reviews| 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" | |
| 12 #include "base/compiler_specific.h" | |
| 13 #include "base/files/file_path.h" | |
| 14 #include "base/macros.h" | |
| 15 #include "base/memory/ref_counted.h" | |
| 16 #include "base/memory/scoped_ptr.h" | |
| 17 #include "base/stl_util.h" | |
| 18 #include "components/ownership/owner_key_util.h" | |
| 19 #include "components/ownership/ownership_export.h" | |
| 20 #include "crypto/rsa_private_key.h" | |
|
wtc
2014/08/27 22:12:53
Just wanted to clarify that I would use forward de
| |
| 21 | |
| 22 namespace ownership { | |
| 23 | |
| 24 class OwnerKeyUtilTest; | |
| 25 | |
| 26 class OWNERSHIP_EXPORT PublicKey | |
| 27 : public base::RefCountedThreadSafe<PublicKey> { | |
| 28 public: | |
| 29 PublicKey(); | |
| 30 | |
| 31 std::vector<uint8>& data() { return data_; } | |
| 32 | |
| 33 bool is_loaded() const { return !data_.empty(); } | |
| 34 | |
| 35 std::string as_string() { | |
| 36 return std::string(reinterpret_cast<const char*>(vector_as_array(&data_)), | |
| 37 data_.size()); | |
| 38 } | |
| 39 | |
| 40 private: | |
| 41 friend class base::RefCountedThreadSafe<PublicKey>; | |
| 42 | |
| 43 virtual ~PublicKey(); | |
| 44 | |
| 45 std::vector<uint8> data_; | |
| 46 | |
| 47 DISALLOW_COPY_AND_ASSIGN(PublicKey); | |
| 48 }; | |
| 49 | |
| 50 class OWNERSHIP_EXPORT PrivateKey | |
| 51 : public base::RefCountedThreadSafe<PrivateKey> { | |
| 52 public: | |
| 53 explicit PrivateKey(crypto::RSAPrivateKey* key); | |
| 54 | |
| 55 crypto::RSAPrivateKey* key() { return key_.get(); } | |
| 56 | |
| 57 private: | |
| 58 friend class base::RefCountedThreadSafe<PrivateKey>; | |
| 59 | |
| 60 virtual ~PrivateKey(); | |
| 61 | |
| 62 scoped_ptr<crypto::RSAPrivateKey> key_; | |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(PrivateKey); | |
| 65 }; | |
| 66 | |
| 67 class OWNERSHIP_EXPORT OwnerKeyUtil | |
| 68 : public base::RefCountedThreadSafe<OwnerKeyUtil> { | |
| 69 public: | |
| 70 explicit OwnerKeyUtil(const base::FilePath& public_key_file); | |
| 71 | |
| 72 // Attempts to read the public key from the file system. Upon success, | |
| 73 // returns true and populates |output|. False on failure. | |
| 74 virtual bool ImportPublicKey(std::vector<uint8>* output); | |
| 75 | |
| 76 #if defined(USE_NSS) | |
| 77 // Looks for the private key associated with |key| in the |slot| | |
| 78 // and returns it if it can be found. Returns NULL otherwise. | |
| 79 // Caller takes ownership. | |
| 80 virtual crypto::RSAPrivateKey* FindPrivateKeyInSlot( | |
| 81 const std::vector<uint8>& key, | |
| 82 PK11SlotInfo* slot); | |
| 83 #endif // defined(USE_NSS) | |
| 84 | |
| 85 // Checks whether the public key is present in the file system. | |
| 86 virtual bool IsPublicKeyPresent(); | |
| 87 | |
| 88 protected: | |
| 89 virtual ~OwnerKeyUtil(); | |
| 90 | |
| 91 private: | |
| 92 // The file that holds the public key. | |
| 93 base::FilePath public_key_file_; | |
| 94 | |
| 95 friend class base::RefCountedThreadSafe<OwnerKeyUtil>; | |
| 96 | |
| 97 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtil); | |
| 98 }; | |
| 99 | |
| 100 } // namespace ownership | |
| 101 | |
| 102 #endif // COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_ | |
| OLD | NEW |