Make |track_| in MediaStreamTrack const. and a couple of other cosmetic changes.
[chromium-blink-merge.git] / components / ownership / owner_key_util.h
blob7e2f15ee0c9e1427c7e62f794f165067a34e71cb
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"
18 #if defined(USE_NSS)
19 struct PK11SlotInfoStr;
20 typedef struct PK11SlotInfoStr PK11SlotInfo;
21 #endif // defined(USE_NSS)
23 namespace crypto {
24 class RSAPrivateKey;
27 namespace ownership {
29 class OwnerKeyUtilTest;
31 // This class is a ref-counted wrapper around a plain public key.
32 class OWNERSHIP_EXPORT PublicKey
33 : public base::RefCountedThreadSafe<PublicKey> {
34 public:
35 PublicKey();
37 std::vector<uint8>& data() { return data_; }
39 bool is_loaded() const { return !data_.empty(); }
41 std::string as_string() {
42 return std::string(reinterpret_cast<const char*>(vector_as_array(&data_)),
43 data_.size());
46 private:
47 friend class base::RefCountedThreadSafe<PublicKey>;
49 virtual ~PublicKey();
51 std::vector<uint8> data_;
53 DISALLOW_COPY_AND_ASSIGN(PublicKey);
56 // This class is a ref-counted wrapper around a crypto::RSAPrivateKey
57 // instance.
58 class OWNERSHIP_EXPORT PrivateKey
59 : public base::RefCountedThreadSafe<PrivateKey> {
60 public:
61 explicit PrivateKey(crypto::RSAPrivateKey* key);
63 crypto::RSAPrivateKey* key() { return key_.get(); }
65 private:
66 friend class base::RefCountedThreadSafe<PrivateKey>;
68 virtual ~PrivateKey();
70 scoped_ptr<crypto::RSAPrivateKey> key_;
72 DISALLOW_COPY_AND_ASSIGN(PrivateKey);
75 // This class is a helper class that allows to import public/private
76 // parts of the owner key.
77 class OWNERSHIP_EXPORT OwnerKeyUtil
78 : public base::RefCountedThreadSafe<OwnerKeyUtil> {
79 public:
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) = 0;
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) = 0;
91 #endif // defined(USE_NSS)
93 // Checks whether the public key is present in the file system.
94 virtual bool IsPublicKeyPresent() = 0;
96 protected:
97 virtual ~OwnerKeyUtil() {}
99 private:
100 friend class base::RefCountedThreadSafe<OwnerKeyUtil>;
103 } // namespace ownership
105 #endif // COMPONENTS_OWNERSHIP_OWNER_KEY_UTIL_H_