Chromium Code Reviews| Index: components/ownership/owner_key_util.h |
| diff --git a/components/ownership/owner_key_util.h b/components/ownership/owner_key_util.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..387865a633e4dac0f38104bf36f6aad3e68ab405 |
| --- /dev/null |
| +++ b/components/ownership/owner_key_util.h |
| @@ -0,0 +1,102 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_ |
| +#define COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_ |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/compiler_specific.h" |
| +#include "base/files/file_path.h" |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/stl_util.h" |
| +#include "components/ownership/owner_key_util.h" |
| +#include "components/ownership/ownership_export.h" |
| +#include "crypto/rsa_private_key.h" |
|
wtc
2014/08/27 22:12:53
Just wanted to clarify that I would use forward de
|
| + |
| +namespace ownership { |
| + |
| +class OwnerKeyUtilTest; |
| + |
| +class OWNERSHIP_EXPORT PublicKey |
| + : public base::RefCountedThreadSafe<PublicKey> { |
| + public: |
| + PublicKey(); |
| + |
| + std::vector<uint8>& data() { return data_; } |
| + |
| + bool is_loaded() const { return !data_.empty(); } |
| + |
| + std::string as_string() { |
| + return std::string(reinterpret_cast<const char*>(vector_as_array(&data_)), |
| + data_.size()); |
| + } |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<PublicKey>; |
| + |
| + virtual ~PublicKey(); |
| + |
| + std::vector<uint8> data_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PublicKey); |
| +}; |
| + |
| +class OWNERSHIP_EXPORT PrivateKey |
| + : public base::RefCountedThreadSafe<PrivateKey> { |
| + public: |
| + explicit PrivateKey(crypto::RSAPrivateKey* key); |
| + |
| + crypto::RSAPrivateKey* key() { return key_.get(); } |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<PrivateKey>; |
| + |
| + virtual ~PrivateKey(); |
| + |
| + scoped_ptr<crypto::RSAPrivateKey> key_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PrivateKey); |
| +}; |
| + |
| +class OWNERSHIP_EXPORT OwnerKeyUtil |
| + : public base::RefCountedThreadSafe<OwnerKeyUtil> { |
| + public: |
| + explicit OwnerKeyUtil(const base::FilePath& public_key_file); |
| + |
| + // Attempts to read the public key from the file system. Upon success, |
| + // returns true and populates |output|. False on failure. |
| + virtual bool ImportPublicKey(std::vector<uint8>* output); |
| + |
| +#if defined(USE_NSS) |
| + // Looks for the private key associated with |key| in the |slot| |
| + // and returns it if it can be found. Returns NULL otherwise. |
| + // Caller takes ownership. |
| + virtual crypto::RSAPrivateKey* FindPrivateKeyInSlot( |
| + const std::vector<uint8>& key, |
| + PK11SlotInfo* slot); |
| +#endif // defined(USE_NSS) |
| + |
| + // Checks whether the public key is present in the file system. |
| + virtual bool IsPublicKeyPresent(); |
| + |
| + protected: |
| + virtual ~OwnerKeyUtil(); |
| + |
| + private: |
| + // The file that holds the public key. |
| + base::FilePath public_key_file_; |
| + |
| + friend class base::RefCountedThreadSafe<OwnerKeyUtil>; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtil); |
| +}; |
| + |
| +} // namespace ownership |
| + |
| +#endif // COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_ |