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

Side by Side Diff: public/platform/WebCrypto.h

Issue 19885002: WebCrypto: Add interfaces for importKey(). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add testing interface Created 7 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef WebCrypto_h 31 #ifndef WebCrypto_h
32 #define WebCrypto_h 32 #define WebCrypto_h
33 33
34 #include "WebCommon.h" 34 #include "WebCommon.h"
35 #include "WebCryptoKey.h"
36 #include "WebPrivatePtr.h"
37
38 namespace WebCore {
39 class CryptoOperation;
40 class KeyOperation;
41 }
35 42
36 namespace WebKit { 43 namespace WebKit {
37 44
38 class WebArrayBuffer; 45 class WebArrayBuffer;
39 class WebCryptoAlgorithm; 46 class WebCryptoKeyOperation;
40 class WebCryptoKey; 47 class WebCryptoKeyOperationResult;
41 class WebCryptoOperation; 48 class WebCryptoOperation;
42 class WebCryptoOperationResult; 49 class WebCryptoOperationResult;
43 50
44 class WebCrypto { 51 class WebCrypto {
45 public: 52 public:
46 // FIXME: Deprecated, delete once chromium side is updated. 53 // FIXME: Deprecated, delete once chromium side is updated.
47 virtual WebCryptoOperation* digest(const WebCryptoAlgorithm&) { return 0; } 54 virtual WebCryptoOperation* digest(const WebCryptoAlgorithm&) { return 0; }
48 55
49 // The following methods begin an asynchronous multi-part cryptographic 56 // The following methods begin an asynchronous multi-part cryptographic
50 // operation. 57 // operation.
51 // 58 //
52 // Let the WebCryptoOperationResult* be called "result". 59 // Let the WebCryptoOperationResult& be called "result".
53 // 60 //
54 // Implementations can either: 61 // Before returning, implementations can either:
55 // 62 //
56 // * Synchronously fail initialization by calling: 63 // * Synchronously fail initialization by calling:
57 // result->initializationFailed(errorDetails) 64 // result.initializationFailed(errorDetails)
58 // 65 //
59 // OR 66 // OR
60 // 67 //
61 // * Create a new WebCryptoOperation* and return it by calling: 68 // * Create a new WebCryptoOperation* and return it by calling:
62 // result->initializationSucceeded(cryptoOperation) 69 // result.initializationSucceeded(cryptoOperation)
63 // 70 //
64 // If initialization succeeds, then Blink will subsequently call 71 // If initialization succeeds, then Blink will subsequently call
65 // methods on cryptoOperation: 72 // methods on cryptoOperation:
66 // 73 //
67 // - cryptoOperation->process() to feed it data 74 // - cryptoOperation->process() to feed it data
68 // - cryptoOperation->finish() to indicate there is no more data 75 // - cryptoOperation->finish() to indicate there is no more data
69 // - cryptoOperation->abort() to cancel. 76 // - cryptoOperation->abort() to cancel.
70 // 77 //
71 // The embedder may call result->completeWithXXX() at any time while the 78 // The embedder may call result.completeWithXXX() at any time while the
72 // cryptoOperation is "in progress". Typically completion is set once 79 // cryptoOperation is "in progress" (can copy the initial "result" object).
73 // cryptoOperation->finish() is called, however it can also be called 80 // Typically completion is set once cryptoOperation->finish() is called,
74 // during cryptoOperation->process() (for instance to set an error). 81 // however it can also be called during cryptoOperation->process() (for
82 // instance to set an error).
75 // 83 //
76 // The cryptoOperation pointer MUST remain valid while it is "in progress". 84 // The cryptoOperation pointer MUST remain valid while it is "in progress".
77 // The cryptoOperation is said to be "in progress" from the time after 85 // The cryptoOperation is said to be "in progress" from the time after
78 // result->initializationSucceded() has been called, up until either: 86 // result->initializationSucceded() has been called, up until either:
79 // 87 //
80 // - Blink calls cryptoOperation->abort() 88 // - Blink calls cryptoOperation->abort()
81 // OR 89 // OR
82 // - Embedder calls result->completeWithXXX() 90 // - Embedder calls result.completeWithXXX()
83 // 91 //
84 // Once the cryptoOperation is no longer "in progress" the "result" pointer 92 // Once the cryptoOperation is no longer "in progress" the embedder is
85 // is no longer valid. At this time the embedder is responsible for freeing 93 // responsible for freeing the cryptoOperation.
86 // the cryptoOperation. 94 virtual void digest(const WebCryptoAlgorithm&, WebCryptoOperationResult&) { }
87 virtual void digest(const WebCryptoAlgorithm&, WebCryptoOperationResult*) { } 95
96 // The following methods begin an asynchronous single-part key operation.
97 //
98 // Let the WebCryptoKeyOperationResult& be called "result".
99 //
100 // Before returning, implementations can either:
101 //
102 // (a) Synchronously fail initialization by calling:
103 // result.initializationFailed(errorDetails)
104 // (this results in throwing a Javascript exception)
105 //
106 // (b) Synchronously complete the request (success or error) by calling:
107 // result.completeWithXXX()
108 //
109 // (c) Defer completion by calling
110 // result.initializationSucceeded(keyOperation)
111 //
112 // If asynchronous completion (c) was chosen, then the embedder can notify
113 // completion after returning by calling result.completeWithXXX() (can make
114 // a copy of "result").
115 //
116 // The keyOperation pointer MUST remain valid while it is "in progress".
117 // The keyOperation is said to be "in progress" from the time after
118 // result->initializationSucceded() has been called, up until either:
119 //
120 // - Blink calls keyOperation->abort()
121 // OR
122 // - Embedder calls result.completeWithXXX()
123 //
124 // Once the keyOperation is no longer "in progress" the embedder is
125 // responsible for freeing the cryptoOperation.
126 virtual void importKey(WebCryptoKeyFormat, const unsigned char* keyData, siz e_t keyDataSize, const WebCryptoAlgorithm&, bool extractable, WebCryptoKeyUsageM ask, WebCryptoKeyOperationResult&) { }
88 127
89 protected: 128 protected:
90 virtual ~WebCrypto() { } 129 virtual ~WebCrypto() { }
91 }; 130 };
92 131
93 class WebCryptoOperation { 132 class WebCryptoOperation {
94 public: 133 public:
95 // Feeds data (bytes, size) to the operation. 134 // Feeds data (bytes, size) to the operation.
96 // - |bytes| may be 0 if |size| is 0 135 // - |bytes| may be 0 if |size| is 0
97 // - |bytes| is valid only until process() returns 136 // - |bytes| is valid only until process() returns
98 // - process() will not be called after abort() or finish() 137 // - process() will not be called after abort() or finish()
99 virtual void process(const unsigned char*, size_t) = 0; 138 virtual void process(const unsigned char*, size_t) = 0;
100 139
101 // Cancels the in-progress operation. 140 // Cancels the in-progress operation.
102 // * Implementations should delete |this| after aborting. 141 // * Implementations should delete |this| after aborting.
103 virtual void abort() = 0; 142 virtual void abort() = 0;
104 143
105 // Indicates that there is no more data to receive. 144 // Indicates that there is no more data to receive.
106 virtual void finish() = 0; 145 virtual void finish() = 0;
107 146
108 protected: 147 protected:
109 virtual ~WebCryptoOperation() { } 148 virtual ~WebCryptoOperation() { }
110 }; 149 };
111 150
151 class WebCryptoOperationResultInterface {
152 public:
153 virtual ~WebCryptoOperationResultInterface() { }
154
155 virtual void initializationFailed() { }
156 virtual void initializationSucceeded(WebCryptoOperation*) { }
157 virtual void initializationSucceeded(WebCryptoKeyOperation*) { }
158 virtual void completeWithError() { }
159 virtual void completeWithArrayBuffer(const WebArrayBuffer&) { }
160 virtual void completeWithKey(const WebCryptoKey&) { }
161 };
162
112 // FIXME: Add error types. 163 // FIXME: Add error types.
113 class WebCryptoOperationResult { 164 class WebCryptoOperationResult {
114 public: 165 public:
166 #if WEBKIT_IMPLEMENTATION
167 WebCryptoOperationResult(WebCore::CryptoOperation*);
168 #endif
169
170 // |interface| must remain alive for duration of the result.
171 static WebCryptoOperationResult createForTest(WebCryptoOperationResultInterf ace* interface)
172 {
173 return WebCryptoOperationResult(interface);
174 }
175
176 ~WebCryptoOperationResult() { reset(); }
177
178 WebCryptoOperationResult(const WebCryptoOperationResult& o)
179 {
180 assign(o);
181 }
182
183 WebCryptoOperationResult& operator=(const WebCryptoOperationResult& o)
184 {
185 assign(o);
186 return *this;
187 }
188
115 // Only one of these should be called. 189 // Only one of these should be called.
116 virtual void initializationFailed() = 0; 190 WEBKIT_EXPORT void initializationFailed();
117 virtual void initializationSucceded(WebCryptoOperation*) = 0; 191 WEBKIT_EXPORT void initializationSucceeded(WebCryptoOperation*);
118 192
119 // Only one of these should be called to set the result. 193 // Only one of these should be called to set the result.
120 virtual void completeWithError() = 0; 194 WEBKIT_EXPORT void completeWithError();
121 virtual void completeWithArrayBuffer(const WebArrayBuffer&) = 0; 195 WEBKIT_EXPORT void completeWithArrayBuffer(const WebArrayBuffer&);
196
197 private:
198 explicit WebCryptoOperationResult(WebCryptoOperationResultInterface* interfa ce) : m_testInterface(interface) { }
199
200 WEBKIT_EXPORT void reset();
201 WEBKIT_EXPORT void assign(const WebCryptoOperationResult&);
202
203 WebPrivatePtr<WebCore::CryptoOperation> m_impl;
204 WebCryptoOperationResultInterface* m_testInterface;
205 };
206
207 class WebCryptoKeyOperation {
208 public:
209 // Cancels the in-progress operation.
210 // * Implementations should delete |this| after aborting.
211 virtual void abort() = 0;
122 212
123 protected: 213 protected:
124 virtual ~WebCryptoOperationResult() { } 214 virtual ~WebCryptoKeyOperation() { }
215 };
216
217 class WebCryptoKeyOperationResult {
218 public:
219 #if WEBKIT_IMPLEMENTATION
220 WebCryptoKeyOperationResult(WebCore::KeyOperation*);
221 #endif
222
223 // |interface| must remain alive for duration of the result.
224 static WebCryptoKeyOperationResult createForTest(WebCryptoOperationResultInt erface* interface)
225 {
226 return WebCryptoKeyOperationResult(interface);
227 }
228
229 ~WebCryptoKeyOperationResult() { reset(); }
230
231 WebCryptoKeyOperationResult(const WebCryptoKeyOperationResult& o)
232 {
233 assign(o);
234 }
235
236 WebCryptoKeyOperationResult& operator=(const WebCryptoKeyOperationResult& o)
237 {
238 assign(o);
239 return *this;
240 }
241
242 WEBKIT_EXPORT void initializationFailed();
243 WEBKIT_EXPORT void initializationSucceeded(WebCryptoKeyOperation*);
244
245 WEBKIT_EXPORT void completeWithError();
246 WEBKIT_EXPORT void completeWithKey(const WebCryptoKey&);
247
248 private:
249 explicit WebCryptoKeyOperationResult(WebCryptoOperationResultInterface* inte rface) : m_testInterface(interface) { }
250
251 WEBKIT_EXPORT void reset();
252 WEBKIT_EXPORT void assign(const WebCryptoKeyOperationResult&);
253
254 WebPrivatePtr<WebCore::KeyOperation> m_impl;
255 WebCryptoOperationResultInterface* m_testInterface;
125 }; 256 };
126 257
127 } // namespace WebKit 258 } // namespace WebKit
128 259
129 #endif 260 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698