[Sync] Componentize UIModelWorker.
[chromium-blink-merge.git] / components / ownership / owner_key_util.h
blobae083cfc78c05e43c76310a5832da7cdb45fb33f
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_
8 #include <string>
9 #include <vector>
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"
17 #include "crypto/scoped_nss_types.h"
19 struct PK11SlotInfoStr;
20 typedef struct PK11SlotInfoStr PK11SlotInfo;
22 namespace ownership {
24 class OwnerKeyUtilTest;
26 // This class is a ref-counted wrapper around a plain public key.
27 class OWNERSHIP_EXPORT PublicKey
28 : public base::RefCountedThreadSafe<PublicKey> {
29 public:
30 PublicKey();
32 std::vector<uint8>& data() { return data_; }
34 bool is_loaded() const { return !data_.empty(); }
36 std::string as_string() {
37 return std::string(reinterpret_cast<const char*>(vector_as_array(&data_)),
38 data_.size());
41 private:
42 friend class base::RefCountedThreadSafe<PublicKey>;
44 virtual ~PublicKey();
46 std::vector<uint8> data_;
48 DISALLOW_COPY_AND_ASSIGN(PublicKey);
51 // This class is a ref-counted wrapper around a SECKEYPrivateKey
52 // instance.
53 class OWNERSHIP_EXPORT PrivateKey
54 : public base::RefCountedThreadSafe<PrivateKey> {
55 public:
56 explicit PrivateKey(crypto::ScopedSECKEYPrivateKey key);
58 SECKEYPrivateKey* key() { return key_.get(); }
60 private:
61 friend class base::RefCountedThreadSafe<PrivateKey>;
63 virtual ~PrivateKey();
65 crypto::ScopedSECKEYPrivateKey key_;
67 DISALLOW_COPY_AND_ASSIGN(PrivateKey);
70 // This class is a helper class that allows to import public/private
71 // parts of the owner key.
72 class OWNERSHIP_EXPORT OwnerKeyUtil
73 : public base::RefCountedThreadSafe<OwnerKeyUtil> {
74 public:
75 // Attempts to read the public key from the file system. Upon success,
76 // returns true and populates |output|. False on failure.
77 virtual bool ImportPublicKey(std::vector<uint8>* output) = 0;
79 // Looks for the private key associated with |key| in the |slot|
80 // and returns it if it can be found. Returns NULL otherwise.
81 // Caller takes ownership.
82 virtual crypto::ScopedSECKEYPrivateKey FindPrivateKeyInSlot(
83 const std::vector<uint8>& key,
84 PK11SlotInfo* slot) = 0;
86 // Checks whether the public key is present in the file system.
87 virtual bool IsPublicKeyPresent() = 0;
89 protected:
90 virtual ~OwnerKeyUtil() {}
92 private:
93 friend class base::RefCountedThreadSafe<OwnerKeyUtil>;
96 } // namespace ownership
98 #endif // COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_