Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1893)

Side by Side Diff: net/ssl/threaded_ssl_private_key.cc

Issue 1178193002: Sign CertificateVerify messages on a background thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more mac build fix, this is blind while mac checkout syncs Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/ssl/threaded_ssl_private_key.h ('k') | remoting/protocol/ssl_hmac_channel_authenticator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 namespace {
18
19 void DoCallback(const base::WeakPtr<ThreadedSSLPrivateKey>& key,
20 const ThreadedSSLPrivateKey::SignCallback& callback,
21 std::vector<uint8_t>* signature,
22 Error error) {
23 if (!key)
24 return;
25 callback.Run(error, *signature);
26 }
27 }
28
29 class ThreadedSSLPrivateKey::Core
30 : public base::RefCountedThreadSafe<ThreadedSSLPrivateKey::Core> {
31 public:
32 Core(scoped_ptr<ThreadedSSLPrivateKey::Delegate> delegate)
33 : delegate_(delegate.Pass()) {}
34
35 ThreadedSSLPrivateKey::Delegate* delegate() { return delegate_.get(); }
36
37 Error SignDigest(SSLPrivateKey::Hash hash,
38 const base::StringPiece& input,
39 std::vector<uint8_t>* signature) {
40 return delegate_->SignDigest(hash, input, signature);
41 }
42
43 private:
44 friend class base::RefCountedThreadSafe<Core>;
45 ~Core() {}
46
47 scoped_ptr<ThreadedSSLPrivateKey::Delegate> delegate_;
48 };
49
50 ThreadedSSLPrivateKey::ThreadedSSLPrivateKey(
51 scoped_ptr<ThreadedSSLPrivateKey::Delegate> delegate,
52 scoped_refptr<base::TaskRunner> task_runner)
53 : core_(new Core(delegate.Pass())),
54 task_runner_(task_runner.Pass()),
55 weak_factory_(this) {
56 }
57
58 ThreadedSSLPrivateKey::~ThreadedSSLPrivateKey() {
59 }
60
61 SSLPrivateKey::Type ThreadedSSLPrivateKey::GetType() {
62 return core_->delegate()->GetType();
63 }
64
65 bool ThreadedSSLPrivateKey::SupportsHash(SSLPrivateKey::Hash hash) {
66 return core_->delegate()->SupportsHash(hash);
67 }
68
69 size_t ThreadedSSLPrivateKey::GetMaxSignatureLengthInBytes() {
70 return core_->delegate()->GetMaxSignatureLengthInBytes();
71 }
72
73 void ThreadedSSLPrivateKey::SignDigest(
74 SSLPrivateKey::Hash hash,
75 const base::StringPiece& input,
76 const SSLPrivateKey::SignCallback& callback) {
77 std::vector<uint8_t>* signature = new std::vector<uint8_t>;
78 base::PostTaskAndReplyWithResult(
79 task_runner_.get(), FROM_HERE,
80 base::Bind(&ThreadedSSLPrivateKey::Core::SignDigest, core_, hash,
81 input.as_string(), base::Unretained(signature)),
82 base::Bind(&DoCallback, weak_factory_.GetWeakPtr(), callback,
83 base::Owned(signature)));
84 }
85
86 } // namespace net
OLDNEW
« no previous file with comments | « net/ssl/threaded_ssl_private_key.h ('k') | remoting/protocol/ssl_hmac_channel_authenticator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698