Chromium Code Reviews| 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 WebCryptoKey_h | |
| 32 #define WebCryptoKey_h | |
| 33 | |
| 34 #include "WebCommon.h" | |
| 35 #include "WebPrivatePtr.h" | |
| 36 | |
| 37 namespace WebKit { | |
| 38 | |
| 39 enum WebCryptoKeyType { | |
| 40 WebCryptoKeyTypeSecret, | |
| 41 WebCryptoKeyTypePublic, | |
| 42 WebCryptoKeyTypePrivate, | |
| 43 }; | |
| 44 | |
| 45 enum WebCryptoKeyUsage { | |
| 46 WebCryptoKeyUsageEncrypt = 1 << 0, | |
| 47 WebCryptoKeyUsageDecrypt = 1 << 1, | |
| 48 WebCryptoKeyUsageSign = 1 << 2, | |
| 49 WebCryptoKeyUsageVerify = 1 << 3, | |
| 50 WebCryptoKeyUsageDerive = 1 << 4, | |
| 51 WebCryptoKeyUsageWrap = 1 << 5, | |
| 52 WebCryptoKeyUsageUnwrap = 1 << 6, | |
| 53 }; | |
| 54 | |
| 55 // A bitfield of WebCryptoKeyUsage | |
| 56 typedef int WebCryptoKeyUsageMask; | |
| 57 | |
| 58 class WebCryptoAlgorithm; | |
| 59 class WebCryptoKeyPrivate; | |
| 60 class WebCryptoKeyHandle; | |
| 61 | |
| 62 // The WebCryptoKey represents a key from the Web Crypto API: | |
| 63 // | |
| 64 // https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#key-inte rface | |
| 65 // | |
| 66 // WebCryptoKey is just a reference-counted wrapper that manages the lifetime of | |
| 67 // a "WebCryptoKeyHandle*". | |
| 68 // | |
| 69 // WebCryptoKey is: | |
| 70 // * Copiable (cheaply) | |
| 71 // * Threadsafe if the embedder's WebCryptoKeyHandle is also threadsafe. | |
| 72 // | |
| 73 // The embedder is responsible for creating all WebCryptoKeys, and therefore can | |
| 74 // safely assume any details regarding the type of the wrapped | |
| 75 // WebCryptoKeyHandle*. | |
| 76 // | |
| 77 // FIXME: Define the interface to use for structured clone. | |
| 78 // Cloning across a process boundary will need serialization, | |
| 79 // however cloning for in-process workers could just share the same | |
| 80 // (threadsafe) handle. | |
| 81 class WebCryptoKey { | |
| 82 public: | |
| 83 ~WebCryptoKey() { reset(); } | |
| 84 | |
| 85 WebCryptoKey(const WebCryptoKey& other) { assign(other); } | |
| 86 WebCryptoKey& operator=(const WebCryptoKey& other) | |
| 87 { | |
| 88 assign(other); | |
| 89 return *this; | |
| 90 } | |
| 91 | |
| 92 // For an explanation of these parameters see: | |
| 93 // https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#key- interface-members | |
| 94 // | |
| 95 // Note that the caller is passing ownership of the WebCryptoKeyHandle*. | |
| 96 WEBKIT_EXPORT static WebCryptoKey create(WebCryptoKeyHandle*, WebCryptoKeyTy pe, bool extractable, const WebCryptoAlgorithm&, WebCryptoKeyUsageMask); | |
| 97 | |
| 98 // Returns the opaque key handle that was set by the embedder. | |
| 99 // * Safe to downcast to known type (since embedder creates all the keys) | |
| 100 // * Returned pointer's lifetime is bound to |this| | |
|
abarth-chromium
2013/07/03 18:01:41
Thanks for the comments about lifetime.
| |
| 101 WEBKIT_EXPORT WebCryptoKeyHandle* handle() const; | |
| 102 | |
| 103 WEBKIT_EXPORT WebCryptoKeyType type() const; | |
| 104 WEBKIT_EXPORT bool extractable() const; | |
| 105 WEBKIT_EXPORT const WebCryptoAlgorithm& algorithm() const; | |
| 106 WEBKIT_EXPORT WebCryptoKeyUsageMask keyUsage() const; | |
| 107 | |
| 108 private: | |
| 109 WebCryptoKey() { } | |
| 110 void assign(const WebCryptoKey& other); | |
| 111 void reset(); | |
|
abarth-chromium
2013/07/03 18:01:41
These probably need WEBKIT_EXPORT
| |
| 112 | |
| 113 WebPrivatePtr<WebCryptoKeyPrivate> m_private; | |
| 114 }; | |
| 115 | |
| 116 // Base class for the embedder to define its own opaque key handle. The lifetime | |
| 117 // of this object is controlled by WebCryptoKey using reference counting. | |
| 118 class WebCryptoKeyHandle { | |
| 119 public: | |
| 120 virtual ~WebCryptoKeyHandle() { } | |
| 121 }; | |
| 122 | |
| 123 } // namespace WebKit | |
| 124 | |
| 125 #endif | |
| OLD | NEW |