Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1091)

Side by Side Diff: components/ownership/owner_key_util.h

Issue 494093002: OwnerKeyUtil is moved to components/ownership. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added forward declarations of RSAPrivateKey and PK11SlotInfoStr. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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
21 #if defined(USE_NSS)
22 struct PK11SlotInfoStr;
23 typedef struct PK11SlotInfoStr PK11SlotInfo;
24 #endif // defined(USE_NSS)
25
26 namespace crypto {
27 class RSAPrivateKey;
28 }
29
30 namespace ownership {
31
32 class OwnerKeyUtilTest;
33
34 class OWNERSHIP_EXPORT PublicKey
35 : public base::RefCountedThreadSafe<PublicKey> {
36 public:
37 PublicKey();
38
39 std::vector<uint8>& data() { return data_; }
40
41 bool is_loaded() const { return !data_.empty(); }
42
43 std::string as_string() {
44 return std::string(reinterpret_cast<const char*>(vector_as_array(&data_)),
45 data_.size());
46 }
47
48 private:
49 friend class base::RefCountedThreadSafe<PublicKey>;
50
51 virtual ~PublicKey();
52
53 std::vector<uint8> data_;
54
55 DISALLOW_COPY_AND_ASSIGN(PublicKey);
56 };
57
58 class OWNERSHIP_EXPORT PrivateKey
59 : public base::RefCountedThreadSafe<PrivateKey> {
60 public:
61 explicit PrivateKey(crypto::RSAPrivateKey* key);
62
63 crypto::RSAPrivateKey* key() { return key_.get(); }
64
65 private:
66 friend class base::RefCountedThreadSafe<PrivateKey>;
67
68 virtual ~PrivateKey();
69
70 scoped_ptr<crypto::RSAPrivateKey> key_;
71
72 DISALLOW_COPY_AND_ASSIGN(PrivateKey);
73 };
74
75 class OWNERSHIP_EXPORT OwnerKeyUtil
76 : public base::RefCountedThreadSafe<OwnerKeyUtil> {
77 public:
78 explicit OwnerKeyUtil(const base::FilePath& public_key_file);
79
80 // Attempts to read the public key from the file system. Upon success,
81 // returns true and populates |output|. False on failure.
82 virtual bool ImportPublicKey(std::vector<uint8>* output);
83
84 #if defined(USE_NSS)
85 // Looks for the private key associated with |key| in the |slot|
86 // and returns it if it can be found. Returns NULL otherwise.
87 // Caller takes ownership.
88 virtual crypto::RSAPrivateKey* FindPrivateKeyInSlot(
89 const std::vector<uint8>& key,
90 PK11SlotInfo* slot);
91 #endif // defined(USE_NSS)
92
93 // Checks whether the public key is present in the file system.
94 virtual bool IsPublicKeyPresent();
95
96 protected:
97 virtual ~OwnerKeyUtil();
98
99 private:
100 // The file that holds the public key.
101 base::FilePath public_key_file_;
102
103 friend class base::RefCountedThreadSafe<OwnerKeyUtil>;
104
105 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtil);
106 };
107
108 } // namespace ownership
109
110 #endif // COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698