| 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 #include "net/ssl/threaded_ssl_private_key.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/location.h" |
| 11 #include "base/task_runner.h" |
| 12 #include "base/task_runner_util.h" |
| 13 #include "base/thread_task_runner_handle.h" |
| 14 |
| 15 namespace net { |
| 16 |
| 17 class ThreadedSSLPrivateKey::Core |
| 18 : public base::RefCountedThreadSafe<ThreadedSSLPrivateKey::Core> { |
| 19 public: |
| 20 Core(scoped_ptr<ThreadedSSLPrivateKey::Delegate> delegate) |
| 21 : delegate_(delegate.Pass()) {} |
| 22 |
| 23 ThreadedSSLPrivateKey::Delegate* delegate() { return delegate_.get(); } |
| 24 |
| 25 Error SignDigest(SSLPrivateKey::Hash hash, |
| 26 const base::StringPiece& input, |
| 27 std::vector<uint8_t>* signature) { |
| 28 return delegate_->SignDigest(hash, input, signature); |
| 29 } |
| 30 |
| 31 private: |
| 32 friend class base::RefCountedThreadSafe<Core>; |
| 33 ~Core() {} |
| 34 |
| 35 scoped_ptr<ThreadedSSLPrivateKey::Delegate> delegate_; |
| 36 }; |
| 37 |
| 38 ThreadedSSLPrivateKey::ThreadedSSLPrivateKey( |
| 39 scoped_ptr<ThreadedSSLPrivateKey::Delegate> delegate, |
| 40 const scoped_refptr<base::TaskRunner>& task_runner) |
| 41 : core_(new Core(delegate.Pass())), |
| 42 task_runner_(task_runner), |
| 43 weak_factory_(this) { |
| 44 } |
| 45 |
| 46 ThreadedSSLPrivateKey::~ThreadedSSLPrivateKey() { |
| 47 } |
| 48 |
| 49 SSLPrivateKey::Type ThreadedSSLPrivateKey::GetType() { |
| 50 return core_->delegate()->GetType(); |
| 51 } |
| 52 |
| 53 bool ThreadedSSLPrivateKey::SupportsHash(SSLPrivateKey::Hash hash) { |
| 54 return core_->delegate()->SupportsHash(hash); |
| 55 } |
| 56 |
| 57 size_t ThreadedSSLPrivateKey::GetMaxSignatureLength() { |
| 58 return core_->delegate()->GetMaxSignatureLength(); |
| 59 } |
| 60 |
| 61 void ThreadedSSLPrivateKey::SignDigest( |
| 62 SSLPrivateKey::Hash hash, |
| 63 const base::StringPiece& input, |
| 64 const SSLPrivateKey::SignCallback& callback) { |
| 65 std::vector<uint8_t>* signature = new std::vector<uint8_t>; |
| 66 base::PostTaskAndReplyWithResult( |
| 67 task_runner_.get(), FROM_HERE, |
| 68 base::Bind(&ThreadedSSLPrivateKey::Core::SignDigest, core_, hash, |
| 69 input.as_string(), base::Unretained(signature)), |
| 70 base::Bind(&ThreadedSSLPrivateKey::DoCallback, weak_factory_.GetWeakPtr(), |
| 71 callback, base::Owned(signature))); |
| 72 } |
| 73 |
| 74 void ThreadedSSLPrivateKey::DoCallback( |
| 75 const SSLPrivateKey::SignCallback& callback, |
| 76 std::vector<uint8_t>* signature, |
| 77 Error error) { |
| 78 callback.Run(error, *signature); |
| 79 } |
| 80 |
| 81 } // namespace net |
| OLD | NEW |