Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / net / ssl / threaded_ssl_private_key.h
blob9c364dd8acaedf664e628bbe4dcc044a5002b065
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 #ifndef NET_SSL_THREADED_SSL_PRIVATE_KEY_H_
6 #define NET_SSL_THREADED_SSL_PRIVATE_KEY_H_
8 #include <stdint.h>
10 #include <vector>
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/strings/string_piece.h"
16 #include "net/ssl/ssl_private_key.h"
18 namespace base {
19 class TaskRunner;
22 namespace net {
24 // An SSLPrivateKey implementation which offloads key operations to a background
25 // task runner.
26 class ThreadedSSLPrivateKey : public SSLPrivateKey {
27 public:
28 // Interface for consumers to implement to perform the actual signing
29 // operation.
30 class Delegate {
31 public:
32 Delegate() {}
33 virtual ~Delegate() {}
35 // These methods behave as those of the same name on SSLPrivateKey. They
36 // must be callable on any thread.
37 virtual Type GetType() = 0;
38 virtual bool SupportsHash(Hash hash) = 0;
39 virtual size_t GetMaxSignatureLengthInBytes() = 0;
41 // Signs |input| as a digest of type |hash|. On sucess it returns OK and
42 // sets |signature| to the resulting signature. Otherwise it returns a net
43 // error code. It will only be called on the task runner passed to the
44 // owning ThreadedSSLPrivateKey.
45 virtual Error SignDigest(Hash hash,
46 const base::StringPiece& input,
47 std::vector<uint8_t>* signature) = 0;
49 private:
50 DISALLOW_COPY_AND_ASSIGN(Delegate);
53 ThreadedSSLPrivateKey(scoped_ptr<Delegate> delegate,
54 scoped_refptr<base::TaskRunner> task_runner);
55 ~ThreadedSSLPrivateKey() override;
57 // SSLPrivateKey implementation.
58 Type GetType() override;
59 bool SupportsHash(Hash hash) override;
60 size_t GetMaxSignatureLengthInBytes() override;
61 void SignDigest(Hash hash,
62 const base::StringPiece& input,
63 const SignCallback& callback) override;
65 private:
66 class Core;
68 scoped_refptr<Core> core_;
69 scoped_refptr<base::TaskRunner> task_runner_;
70 base::WeakPtrFactory<ThreadedSSLPrivateKey> weak_factory_;
72 DISALLOW_COPY_AND_ASSIGN(ThreadedSSLPrivateKey);
75 } // namespace net
77 #endif // NET_SSL_THREADED_SSL_PRIVATE_KEY_H_