| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_SSL_THREADED_SSL_PRIVATE_KEY_H_ | 5 #ifndef NET_SSL_THREADED_SSL_PRIVATE_KEY_H_ |
| 6 #define NET_SSL_THREADED_SSL_PRIVATE_KEY_H_ | 6 #define NET_SSL_THREADED_SSL_PRIVATE_KEY_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
| 18 #include "net/ssl/ssl_private_key.h" | 18 #include "net/ssl/ssl_private_key.h" |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 class TaskRunner; | 21 class SingleThreadTaskRunner; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace net { | 24 namespace net { |
| 25 | 25 |
| 26 // An SSLPrivateKey implementation which offloads key operations to a background | 26 // An SSLPrivateKey implementation which offloads key operations to a background |
| 27 // task runner. | 27 // task runner. |
| 28 class ThreadedSSLPrivateKey : public SSLPrivateKey { | 28 class ThreadedSSLPrivateKey : public SSLPrivateKey { |
| 29 public: | 29 public: |
| 30 // Interface for consumers to implement to perform the actual signing | 30 // Interface for consumers to implement to perform the actual signing |
| 31 // operation. | 31 // operation. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 45 // error code. It will only be called on the task runner passed to the | 45 // error code. It will only be called on the task runner passed to the |
| 46 // owning ThreadedSSLPrivateKey. | 46 // owning ThreadedSSLPrivateKey. |
| 47 virtual Error SignDigest(Hash hash, | 47 virtual Error SignDigest(Hash hash, |
| 48 const base::StringPiece& input, | 48 const base::StringPiece& input, |
| 49 std::vector<uint8_t>* signature) = 0; | 49 std::vector<uint8_t>* signature) = 0; |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 DISALLOW_COPY_AND_ASSIGN(Delegate); | 52 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 ThreadedSSLPrivateKey(std::unique_ptr<Delegate> delegate, | 55 ThreadedSSLPrivateKey( |
| 56 scoped_refptr<base::TaskRunner> task_runner); | 56 std::unique_ptr<Delegate> delegate, |
| 57 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 57 | 58 |
| 58 // SSLPrivateKey implementation. | 59 // SSLPrivateKey implementation. |
| 59 Type GetType() override; | 60 Type GetType() override; |
| 60 std::vector<SSLPrivateKey::Hash> GetDigestPreferences() override; | 61 std::vector<SSLPrivateKey::Hash> GetDigestPreferences() override; |
| 61 size_t GetMaxSignatureLengthInBytes() override; | 62 size_t GetMaxSignatureLengthInBytes() override; |
| 62 void SignDigest(Hash hash, | 63 void SignDigest(Hash hash, |
| 63 const base::StringPiece& input, | 64 const base::StringPiece& input, |
| 64 const SignCallback& callback) override; | 65 const SignCallback& callback) override; |
| 65 | 66 |
| 66 private: | 67 private: |
| 67 ~ThreadedSSLPrivateKey() override; | 68 ~ThreadedSSLPrivateKey() override; |
| 68 class Core; | 69 class Core; |
| 69 | 70 |
| 70 scoped_refptr<Core> core_; | 71 scoped_refptr<Core> core_; |
| 71 scoped_refptr<base::TaskRunner> task_runner_; | 72 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 72 base::WeakPtrFactory<ThreadedSSLPrivateKey> weak_factory_; | 73 base::WeakPtrFactory<ThreadedSSLPrivateKey> weak_factory_; |
| 73 | 74 |
| 74 DISALLOW_COPY_AND_ASSIGN(ThreadedSSLPrivateKey); | 75 DISALLOW_COPY_AND_ASSIGN(ThreadedSSLPrivateKey); |
| 75 }; | 76 }; |
| 76 | 77 |
| 77 } // namespace net | 78 } // namespace net |
| 78 | 79 |
| 79 #endif // NET_SSL_THREADED_SSL_PRIVATE_KEY_H_ | 80 #endif // NET_SSL_THREADED_SSL_PRIVATE_KEY_H_ |
| OLD | NEW |