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

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: Move test stuff into MockWebCrypto 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"
35 36
36 namespace WebKit { 37 namespace WebKit {
37 38
38 class WebArrayBuffer; 39 class WebArrayBuffer;
39 class WebCryptoAlgorithm; 40 class WebCryptoKeyOperation;
40 class WebCryptoKey; 41 class WebCryptoKeyOperationResult;
41 class WebCryptoOperation; 42 class WebCryptoOperation;
42 class WebCryptoOperationResult; 43 class WebCryptoOperationResult;
43 44
44 class WebCrypto { 45 class WebCrypto {
45 public: 46 public:
46 // FIXME: Deprecated, delete once chromium side is updated. 47 // FIXME: Deprecated, delete once chromium side is updated.
47 virtual WebCryptoOperation* digest(const WebCryptoAlgorithm&) { return 0; } 48 virtual WebCryptoOperation* digest(const WebCryptoAlgorithm&) { return 0; }
48 49
49 // The following methods begin an asynchronous multi-part cryptographic 50 // The following methods begin an asynchronous multi-part cryptographic
50 // operation. 51 // operation.
51 // 52 //
52 // Let the WebCryptoOperationResult* be called "result". 53 // Let the WebCryptoOperationResult* be called "result".
53 // 54 //
54 // Implementations can either: 55 // Before returning, implementations can either:
55 // 56 //
56 // * Synchronously fail initialization by calling: 57 // * Synchronously fail initialization by calling:
57 // result->initializationFailed(errorDetails) 58 // result->initializationFailed(errorDetails)
58 // 59 //
59 // OR 60 // OR
60 // 61 //
61 // * Create a new WebCryptoOperation* and return it by calling: 62 // * Create a new WebCryptoOperation* and return it by calling:
62 // result->initializationSucceeded(cryptoOperation) 63 // result->initializationSucceeded(cryptoOperation)
63 // 64 //
64 // If initialization succeeds, then Blink will subsequently call 65 // If initialization succeeds, then Blink will subsequently call
(...skipping 14 matching lines...) Expand all
79 // 80 //
80 // - Blink calls cryptoOperation->abort() 81 // - Blink calls cryptoOperation->abort()
81 // OR 82 // OR
82 // - Embedder calls result->completeWithXXX() 83 // - Embedder calls result->completeWithXXX()
83 // 84 //
84 // Once the cryptoOperation is no longer "in progress" the "result" pointer 85 // Once the cryptoOperation is no longer "in progress" the "result" pointer
85 // is no longer valid. At this time the embedder is responsible for freeing 86 // is no longer valid. At this time the embedder is responsible for freeing
86 // the cryptoOperation. 87 // the cryptoOperation.
87 virtual void digest(const WebCryptoAlgorithm&, WebCryptoOperationResult*) { } 88 virtual void digest(const WebCryptoAlgorithm&, WebCryptoOperationResult*) { }
88 89
90 // The following methods begin an asynchronous single-part key operation.
91 //
92 // Let the WebCryptoKeyOperationResult* be called "result".
93 //
94 // Before returning, implementations can either:
95 //
96 // (a) Synchronously fail initialization by calling:
97 // result->initializationFailed(errorDetails)
98 // (this results in throwing a Javascript exception)
99 //
100 // (b) Synchronously complete the request (success or error) by calling:
101 // result->completeWithXXX()
102 //
103 // (c) Defer completion by calling
104 // result->initializationSucceeded(keyOperation)
105 //
106 // If asynchronous completion (c) was chosen, then the embedder can notify
107 // completion after returning by calling result->completeWithXXX().
108 //
109 // The keyOperation pointer MUST remain valid while it is "in progress".
110 // The keyOperation is said to be "in progress" from the time after
111 // result->initializationSucceded() has been called, up until either:
112 //
113 // - Blink calls keyOperation->abort()
114 // OR
115 // - Embedder calls result->completeWithXXX()
116 //
117 // Once the keyOperation is no longer "in progress" the "result" pointer
118 // is no longer valid. At this time the embedder is responsible for freeing
119 // the cryptoOperation.
120 virtual void importKey(WebCryptoKeyFormat, const unsigned char* keyData, siz e_t keyDataSize, const WebCryptoAlgorithm&, bool extractable, WebCryptoKeyUsageM ask, WebCryptoKeyOperationResult*) { }
121
89 protected: 122 protected:
90 virtual ~WebCrypto() { } 123 virtual ~WebCrypto() { }
91 }; 124 };
92 125
93 class WebCryptoOperation { 126 class WebCryptoOperation {
94 public: 127 public:
95 // Feeds data (bytes, size) to the operation. 128 // Feeds data (bytes, size) to the operation.
96 // - |bytes| may be 0 if |size| is 0 129 // - |bytes| may be 0 if |size| is 0
97 // - |bytes| is valid only until process() returns 130 // - |bytes| is valid only until process() returns
98 // - process() will not be called after abort() or finish() 131 // - process() will not be called after abort() or finish()
(...skipping 18 matching lines...) Expand all
117 virtual void initializationSucceded(WebCryptoOperation*) = 0; 150 virtual void initializationSucceded(WebCryptoOperation*) = 0;
118 151
119 // Only one of these should be called to set the result. 152 // Only one of these should be called to set the result.
120 virtual void completeWithError() = 0; 153 virtual void completeWithError() = 0;
121 virtual void completeWithArrayBuffer(const WebArrayBuffer&) = 0; 154 virtual void completeWithArrayBuffer(const WebArrayBuffer&) = 0;
122 155
123 protected: 156 protected:
124 virtual ~WebCryptoOperationResult() { } 157 virtual ~WebCryptoOperationResult() { }
125 }; 158 };
126 159
160 class WebCryptoKeyOperation {
161 public:
162 // Cancels the in-progress operation.
163 // * Implementations should delete |this| after aborting.
164 virtual void abort() = 0;
165
166 protected:
167 virtual ~WebCryptoKeyOperation() { }
168 };
169
170 class WebCryptoKeyOperationResult {
171 public:
172 virtual void initializationFailed() = 0;
173 virtual void initializationSucceeded(WebCryptoKeyOperation*) = 0;
174
175 virtual void completeWithError() = 0;
176 virtual void completeWithKey(const WebCryptoKey&) = 0;
177
178 protected:
179 virtual ~WebCryptoKeyOperationResult() { }
180 };
181
127 } // namespace WebKit 182 } // namespace WebKit
128 183
129 #endif 184 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698