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 25 matching lines...) Expand all Loading... |
36 namespace WebKit { | 36 namespace WebKit { |
37 | 37 |
38 class WebArrayBuffer; | 38 class WebArrayBuffer; |
39 class WebCryptoAlgorithm; | 39 class WebCryptoAlgorithm; |
40 class WebCryptoKey; | 40 class WebCryptoKey; |
41 class WebCryptoOperation; | 41 class WebCryptoOperation; |
42 class WebCryptoOperationResult; | 42 class WebCryptoOperationResult; |
43 | 43 |
44 class WebCrypto { | 44 class WebCrypto { |
45 public: | 45 public: |
46 // The following methods start a new asynchronous multi-part cryptographic | 46 // FIXME: Deprecated, delete once chromium side is updated. |
| 47 virtual WebCryptoOperation* digest(const WebCryptoAlgorithm&) = 0; |
| 48 |
| 49 // The following methods begin an asynchronous multi-part cryptographic |
47 // operation. | 50 // operation. |
48 // | 51 // |
49 // - Returns 0 on failure | 52 // Let the WebCryptoOperationResult* be called "result". |
50 // - The returned pointer must remain valid until the operation has | 53 // |
51 // completed. After this, the embedder is responsible for freeing it. | 54 // Implementations can either: |
52 | 55 // |
53 virtual WebCryptoOperation* digest(const WebCryptoAlgorithm&) = 0; | 56 // * Synchronously fail initialization by calling: |
| 57 // result->initializationFailed(errorDetails) |
| 58 // |
| 59 // OR |
| 60 // |
| 61 // * Create a new WebCryptoOperation* and return it by calling: |
| 62 // result->initializationSucceeded(cryptoOperation) |
| 63 // |
| 64 // If initialization succeeds, then Blink will subsequently call |
| 65 // methods on cryptoOperation: |
| 66 // |
| 67 // - cryptoOperation->process() to feed it data |
| 68 // - cryptoOperation->finish() to indicate there is no more data |
| 69 // - cryptoOperation->abort() to cancel. |
| 70 // |
| 71 // The embedder may call result->completeWithXXX() at any time while the |
| 72 // cryptoOperation is "in progress". Typically completion is set once |
| 73 // cryptoOperation->finish() is called, however it can also be called |
| 74 // during cryptoOperation->process() (for instance to set an error). |
| 75 // |
| 76 // The cryptoOperation pointer MUST remain valid while it is "in progress". |
| 77 // The cryptoOperation is said to be "in progress" from the time after |
| 78 // result->initializationSucceded() has been called, up until either: |
| 79 // |
| 80 // - Blink calls cryptoOperation->abort() |
| 81 // OR |
| 82 // - Embedder calls result->completeWithXXX() |
| 83 // |
| 84 // 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 // the cryptoOperation. |
| 87 virtual void digest2(const WebCryptoAlgorithm&, WebCryptoOperationResult*) {
} |
54 | 88 |
55 protected: | 89 protected: |
56 virtual ~WebCrypto() { } | 90 virtual ~WebCrypto() { } |
57 }; | 91 }; |
58 | 92 |
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 { | 93 class WebCryptoOperation { |
71 public: | 94 public: |
72 // Feeds data (bytes, size) to the operation. | 95 // Feeds data (bytes, size) to the operation. |
73 // - |bytes| may be 0 if |size| is 0 | 96 // - |bytes| may be 0 if |size| is 0 |
74 // - |bytes| is valid only until process() returns | 97 // - |bytes| is valid only until process() returns |
75 // - process() will not be called after abort() or finish() | 98 // - process() will not be called after abort() or finish() |
76 virtual void process(const unsigned char*, size_t) = 0; | 99 virtual void process(const unsigned char*, size_t) = 0; |
77 | 100 |
78 // Cancels the in-progress operation. | 101 // Cancels the in-progress operation. |
79 // * Implementations should delete |this| after aborting. | 102 // * Implementations should delete |this| after aborting. |
80 virtual void abort() = 0; | 103 virtual void abort() = 0; |
81 | 104 |
82 // Completes the operation and writes the result to the | 105 // Indicates that there is no more data to receive. |
83 // WebCryptoOperationResult* (henceforth called |result|). | 106 virtual void finish() = 0; |
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 | 107 |
92 protected: | 108 protected: |
93 virtual ~WebCryptoOperation() { } | 109 virtual ~WebCryptoOperation() { } |
94 }; | 110 }; |
95 | 111 |
96 // WebCryptoOperationResult is a handle for either synchronous or asynchronous | 112 // FIXME: Add error types. |
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 { | 113 class WebCryptoOperationResult { |
110 public: | 114 public: |
111 virtual void setArrayBuffer(const WebArrayBuffer&) = 0; | 115 // Only one of these should be called. |
| 116 virtual void initializationFailed() = 0; |
| 117 virtual void initializationSucceded(WebCryptoOperation*) = 0; |
| 118 |
| 119 // Only one of these should be called to set the result. |
| 120 virtual void completeWithError() = 0; |
| 121 virtual void completeWithArrayBuffer(const WebArrayBuffer&) = 0; |
112 | 122 |
113 protected: | 123 protected: |
114 virtual ~WebCryptoOperationResult() { } | 124 virtual ~WebCryptoOperationResult() { } |
115 }; | 125 }; |
116 | 126 |
117 } // namespace WebKit | 127 } // namespace WebKit |
118 | 128 |
119 #endif | 129 #endif |
OLD | NEW |