OLD | NEW |
---|---|
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 Loading... | |
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 |
112 // FIXME: Add error types. | 151 // FIXME: Add error types. |
113 class WebCryptoOperationResult { | 152 class WebCryptoOperationResult { |
114 public: | 153 public: |
154 #if WEBKIT_IMPLEMENTATION | |
155 WebCryptoOperationResult(WebCore::CryptoOperation*); | |
156 #endif | |
157 | |
158 WebCryptoOperationResult(const WebCryptoOperationResult& o) | |
159 { | |
160 m_impl = o.m_impl; | |
161 } | |
162 | |
163 WebCryptoOperationResult& operator=(const WebCryptoOperationResult& o) | |
164 { | |
165 m_impl = o.m_impl; | |
166 return *this; | |
167 } | |
168 | |
115 // Only one of these should be called. | 169 // Only one of these should be called. |
116 virtual void initializationFailed() = 0; | 170 WEBKIT_EXPORT void initializationFailed(); |
117 virtual void initializationSucceded(WebCryptoOperation*) = 0; | 171 WEBKIT_EXPORT void initializationSucceeded(WebCryptoOperation*); |
118 | 172 |
119 // Only one of these should be called to set the result. | 173 // Only one of these should be called to set the result. |
120 virtual void completeWithError() = 0; | 174 WEBKIT_EXPORT void completeWithError(); |
121 virtual void completeWithArrayBuffer(const WebArrayBuffer&) = 0; | 175 WEBKIT_EXPORT void completeWithArrayBuffer(const WebArrayBuffer&); |
176 | |
177 private: | |
178 WebCore::CryptoOperation* m_impl; | |
abarth-chromium
2013/07/23 21:45:49
Should this be a WebPrivatePtr<WebCore::CryptoOper
eroman
2013/07/23 23:29:02
Done.
(I was initially concerned about refcountin
| |
179 }; | |
180 | |
181 class WebCryptoKeyOperation { | |
182 public: | |
183 // Cancels the in-progress operation. | |
184 // * Implementations should delete |this| after aborting. | |
185 virtual void abort() = 0; | |
122 | 186 |
123 protected: | 187 protected: |
124 virtual ~WebCryptoOperationResult() { } | 188 virtual ~WebCryptoKeyOperation() { } |
189 }; | |
190 | |
191 class WebCryptoKeyOperationResult { | |
192 public: | |
193 #if WEBKIT_IMPLEMENTATION | |
194 WebCryptoKeyOperationResult(WebCore::KeyOperation*); | |
195 #endif | |
196 | |
197 ~WebCryptoKeyOperationResult() { reset(); } | |
198 | |
199 WebCryptoKeyOperationResult(const WebCryptoKeyOperationResult& o) | |
200 { | |
201 assign(o); | |
202 } | |
203 | |
204 WebCryptoKeyOperationResult& operator=(const WebCryptoKeyOperationResult& o) | |
205 { | |
206 assign(o); | |
207 return *this; | |
208 } | |
209 | |
210 WEBKIT_EXPORT void initializationFailed(); | |
211 WEBKIT_EXPORT void initializationSucceeded(WebCryptoKeyOperation*); | |
212 | |
213 WEBKIT_EXPORT void completeWithError(); | |
214 WEBKIT_EXPORT void completeWithKey(const WebCryptoKey&); | |
215 | |
216 private: | |
217 WEBKIT_EXPORT void reset(); | |
218 WEBKIT_EXPORT void assign(const WebCryptoKeyOperationResult&); | |
219 | |
220 WebPrivatePtr<WebCore::KeyOperation> m_impl; | |
125 }; | 221 }; |
126 | 222 |
127 } // namespace WebKit | 223 } // namespace WebKit |
128 | 224 |
129 #endif | 225 #endif |
OLD | NEW |