Update V8 to version 4.7.53.
[chromium-blink-merge.git] / net / ssl / threaded_ssl_private_key.cc
blobda81bdf06abdda80a6050d3e936caef14cadb9f2
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.
5 #include "net/ssl/threaded_ssl_private_key.h"
7 #include <string>
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"
15 namespace net {
17 namespace {
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);
29 class ThreadedSSLPrivateKey::Core
30 : public base::RefCountedThreadSafe<ThreadedSSLPrivateKey::Core> {
31 public:
32 Core(scoped_ptr<ThreadedSSLPrivateKey::Delegate> delegate)
33 : delegate_(delegate.Pass()) {}
35 ThreadedSSLPrivateKey::Delegate* delegate() { return delegate_.get(); }
37 Error SignDigest(SSLPrivateKey::Hash hash,
38 const base::StringPiece& input,
39 std::vector<uint8_t>* signature) {
40 return delegate_->SignDigest(hash, input, signature);
43 private:
44 friend class base::RefCountedThreadSafe<Core>;
45 ~Core() {}
47 scoped_ptr<ThreadedSSLPrivateKey::Delegate> delegate_;
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) {
58 ThreadedSSLPrivateKey::~ThreadedSSLPrivateKey() {
61 SSLPrivateKey::Type ThreadedSSLPrivateKey::GetType() {
62 return core_->delegate()->GetType();
65 bool ThreadedSSLPrivateKey::SupportsHash(SSLPrivateKey::Hash hash) {
66 return core_->delegate()->SupportsHash(hash);
69 size_t ThreadedSSLPrivateKey::GetMaxSignatureLengthInBytes() {
70 return core_->delegate()->GetMaxSignatureLengthInBytes();
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)));
86 } // namespace net