OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
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. | |
29 */ | |
30 | |
31 #ifndef WebCrypto_h | |
32 #define WebCrypto_h | |
33 | |
34 #include "WebCommon.h" | |
35 | |
36 namespace WebKit { | |
37 | |
38 class WebArrayBuffer; | |
39 class WebCryptoAlgorithm; | |
40 class WebCryptoKey; | |
41 class WebCryptoOperation; | |
42 class WebCryptoOperationResult; | |
43 | |
44 class WebCrypto { | |
45 public: | |
46 // The following methods start a new asynchronous multi-part cryptographic | |
47 // operation. | |
48 // | |
49 // - Returns 0 on failure | |
50 // - The returned pointer must remain valid until the operation has | |
51 // completed. After this, the embedder is responsible for freeing it. | |
52 | |
53 virtual WebCryptoOperation* digest(const WebCryptoAlgorithm&) = 0; | |
54 | |
55 protected: | |
56 virtual ~WebCrypto() { } | |
57 }; | |
58 | |
59 // WebCryptoOperation represents a multi-part cryptographic operation. The | |
60 // methods on this interface will be called in this order: | |
61 // | |
62 // (1) 0 or more calls to process() | |
63 // (2) 0 or 1 calls to finish() | |
64 // (3) 0 or 1 calls to abort() | |
65 // | |
66 // Deletion of the WebCryptoOperation is the responsibility of the embedder. | |
67 // However it MUST remain alive until either: | |
68 // (a) Blink has called this->abort() | |
69 // (b) The embedder has called result->setXXX() | |
70 class WebCryptoOperation { | |
71 public: | |
72 // Feeds data (bytes, size) to the operation. | |
73 // - |bytes| may be 0 if |size| is 0 | |
74 // - |bytes| is valid only until process() returns | |
75 // - process() will not be called after abort() or finish() | |
76 virtual void process(const unsigned char*, size_t) = 0; | |
77 | |
78 // Cancels the in-progress operation. | |
79 // * Implementations should delete |this| after aborting. | |
80 virtual void abort() = 0; | |
81 | |
82 // Completes the operation and writes the result to the | |
83 // WebCryptoOperationResult* (henceforth called |result|). | |
84 // | |
85 // |result| can be set either synchronously or asynchronously. |result| | |
86 // will remain alive until the operation completes OR this->abort() is | |
87 // called. |result| SHOULD NOT be used after this->abort() has been called. | |
88 // | |
89 // * Implementations should delete |this| after setting |result|. | |
90 virtual void finish(WebCryptoOperationResult*) = 0; | |
91 | |
92 protected: | |
93 virtual ~WebCryptoOperation() { } | |
94 }; | |
95 | |
96 // WebCryptoOperationResult is a handle for either synchronous or asynchronous | |
97 // completion of WebCryptoOperation::finish(). | |
98 // | |
99 // The result can be either an error or a value. | |
100 // | |
101 // Only one of the setXXX() methods should be called, corresponding to the | |
102 // expected type of result for the operation. For instance digest() outputs an | |
103 // ArrayBuffer whereas verify() outputs a boolean. | |
104 // | |
105 // Note on re-entrancy: After completing the result (i.e. calling one of the | |
106 // setXXX() methods) the embedder must be ready to service other requests. In | |
107 // other words, it should release any locks that would prevent other | |
108 // WebCryptoOperations from being created or used. | |
109 class WebCryptoOperationResult { | |
110 public: | |
111 virtual void setArrayBuffer(const WebArrayBuffer&) = 0; | |
112 | |
113 protected: | |
114 virtual ~WebCryptoOperationResult() { } | |
115 }; | |
116 | |
117 } // namespace WebKit | |
118 | |
119 #endif | |
OLD | NEW |