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 #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/thread_task_runner_handle.h" | |
| 13 | |
| 14 namespace net { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 void DoSign(const scoped_refptr<ThreadedSSLPrivateKey::Core>& core, | |
| 19 SSLPrivateKey::Hash hash, | |
| 20 const std::string& input, | |
| 21 const SSLPrivateKey::SignCallback& callback, | |
| 22 const scoped_refptr<base::TaskRunner>& task_runner) { | |
| 23 std::vector<uint8_t> signature; | |
| 24 Error error = core->SignDigest(hash, input, &signature); | |
| 25 task_runner->PostTask(FROM_HERE, base::Bind(callback, error, signature)); | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 ThreadedSSLPrivateKey::ThreadedSSLPrivateKey( | |
| 31 const scoped_refptr<Core>& core, | |
| 32 const scoped_refptr<base::TaskRunner>& task_runner) | |
| 33 : core_(core), task_runner_(task_runner), weak_factory_(this) { | |
| 34 } | |
| 35 | |
| 36 ThreadedSSLPrivateKey::~ThreadedSSLPrivateKey() { | |
| 37 } | |
| 38 | |
| 39 SSLPrivateKey::Type ThreadedSSLPrivateKey::GetType() { | |
| 40 return core_->GetType(); | |
| 41 } | |
| 42 | |
| 43 bool ThreadedSSLPrivateKey::SupportsHash(SSLPrivateKey::Hash hash) { | |
| 44 return core_->SupportsHash(hash); | |
| 45 } | |
| 46 | |
| 47 size_t ThreadedSSLPrivateKey::GetMaxSignatureLength() { | |
| 48 return core_->GetMaxSignatureLength(); | |
| 49 } | |
| 50 | |
| 51 void ThreadedSSLPrivateKey::SignDigest( | |
| 52 SSLPrivateKey::Hash hash, | |
| 53 const base::StringPiece& input, | |
| 54 const SSLPrivateKey::SignCallback& callback) { | |
| 55 task_runner_->PostTask( | |
| 56 FROM_HERE, base::Bind(&DoSign, core_, hash, input.as_string(), | |
| 57 base::Bind(&ThreadedSSLPrivateKey::DoCallback, | |
| 58 weak_factory_.GetWeakPtr(), callback), | |
| 59 base::ThreadTaskRunnerHandle::Get())); | |
|
Ryan Sleevi
2015/06/12 23:37:20
An alternative way to do this
namespace {
void D
davidben
2015/06/15 21:28:25
I don't believe it quite avoids the need for DoCal
| |
| 60 } | |
| 61 | |
| 62 void ThreadedSSLPrivateKey::DoCallback( | |
| 63 const SSLPrivateKey::SignCallback& callback, | |
| 64 Error error, | |
| 65 const std::vector<uint8_t>& signature) { | |
| 66 callback.Run(error, signature); | |
| 67 } | |
| 68 | |
| 69 } // namespace net | |
| OLD | NEW |