Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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 NET_SSL_THREADED_SSL_PRIVATE_KEY_H_ | |
| 6 #define NET_SSL_THREADED_SSL_PRIVATE_KEY_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "base/strings/string_piece.h" | |
| 16 #include "net/ssl/ssl_private_key.h" | |
| 17 | |
| 18 namespace base { | |
| 19 class TaskRunner; | |
| 20 } | |
| 21 | |
| 22 namespace net { | |
| 23 | |
| 24 // An SSLPrivateKey implementation which offloads key operations to a background | |
| 25 // thread. | |
| 26 class ThreadedSSLPrivateKey : public SSLPrivateKey { | |
| 27 public: | |
| 28 // Interface for consumers to implement to perform the actual signing | |
| 29 // operation. All methods must be callable on any thread. | |
| 30 class Core : public base::RefCountedThreadSafe<Core> { | |
|
Ryan Sleevi
2015/06/12 23:37:20
The naming of Core is a little weird here. Aren't
davidben
2015/06/15 21:28:25
Done.
| |
| 31 public: | |
| 32 Core() {} | |
| 33 | |
| 34 virtual Type GetType() = 0; | |
| 35 virtual bool SupportsHash(Hash hash) = 0; | |
| 36 virtual size_t GetMaxSignatureLength() = 0; | |
| 37 virtual Error SignDigest(Hash hash, | |
| 38 const base::StringPiece& input, | |
| 39 std::vector<uint8_t>* signature) = 0; | |
| 40 | |
| 41 protected: | |
| 42 virtual ~Core() {} | |
| 43 | |
| 44 private: | |
| 45 friend class base::RefCountedThreadSafe<Core>; | |
| 46 | |
| 47 DISALLOW_COPY_AND_ASSIGN(Core); | |
| 48 }; | |
| 49 | |
| 50 ThreadedSSLPrivateKey(const scoped_refptr<Core>& core, | |
| 51 const scoped_refptr<base::TaskRunner>& task_runner); | |
| 52 ~ThreadedSSLPrivateKey() override; | |
| 53 | |
| 54 // SSLPrivateKey implementation. | |
| 55 Type GetType() override; | |
| 56 bool SupportsHash(Hash hash) override; | |
| 57 size_t GetMaxSignatureLength() override; | |
| 58 void SignDigest(Hash hash, | |
| 59 const base::StringPiece& input, | |
| 60 const SignCallback& callback) override; | |
| 61 | |
| 62 private: | |
| 63 // A wrapper over SignCallback to ensure the callback isn't called if the key | |
| 64 // is destroyed. | |
| 65 void DoCallback(const SignCallback& callback, | |
| 66 Error error, | |
| 67 const std::vector<uint8_t>& signature); | |
|
Ryan Sleevi
2015/06/12 23:37:20
There's no need to make this a private class membe
davidben
2015/06/15 21:28:25
Now it needs to be. If we split up Delegate and Co
| |
| 68 | |
| 69 scoped_refptr<Core> core_; | |
| 70 scoped_refptr<base::TaskRunner> task_runner_; | |
| 71 base::WeakPtrFactory<ThreadedSSLPrivateKey> weak_factory_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(ThreadedSSLPrivateKey); | |
| 74 }; | |
| 75 | |
| 76 } // namespace net | |
| 77 | |
| 78 #endif // NET_SSL_THREADED_SSL_PRIVATE_KEY_H_ | |
| OLD | NEW |