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 15 matching lines...) Expand all Loading... |
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 #include "config.h" | 31 #include "config.h" |
32 #include "modules/crypto/CryptoKey.h" | 32 #include "modules/crypto/CryptoKey.h" |
33 | 33 |
34 #include "bindings/v8/ExceptionState.h" | 34 #include "bindings/v8/ExceptionState.h" |
35 #include "core/dom/ExceptionCode.h" | 35 #include "core/dom/ExceptionCode.h" |
36 #include "modules/crypto/KeyAlgorithm.h" | |
37 #include "platform/CryptoResult.h" | 36 #include "platform/CryptoResult.h" |
38 #include "public/platform/WebCryptoAlgorithmParams.h" | 37 #include "public/platform/WebCryptoAlgorithmParams.h" |
| 38 #include "public/platform/WebCryptoKeyAlgorithm.h" |
39 #include "public/platform/WebString.h" | 39 #include "public/platform/WebString.h" |
40 | 40 |
41 namespace WebCore { | 41 namespace WebCore { |
42 | 42 |
43 namespace { | 43 namespace { |
44 | 44 |
45 const char* keyTypeToString(blink::WebCryptoKeyType type) | 45 const char* keyTypeToString(blink::WebCryptoKeyType type) |
46 { | 46 { |
47 switch (type) { | 47 switch (type) { |
48 case blink::WebCryptoKeyTypeSecret: | 48 case blink::WebCryptoKeyTypeSecret: |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 String CryptoKey::type() const | 140 String CryptoKey::type() const |
141 { | 141 { |
142 return keyTypeToString(m_key.type()); | 142 return keyTypeToString(m_key.type()); |
143 } | 143 } |
144 | 144 |
145 bool CryptoKey::extractable() const | 145 bool CryptoKey::extractable() const |
146 { | 146 { |
147 return m_key.extractable(); | 147 return m_key.extractable(); |
148 } | 148 } |
149 | 149 |
150 KeyAlgorithm* CryptoKey::algorithm() | |
151 { | |
152 if (!m_algorithm) | |
153 m_algorithm = KeyAlgorithm::create(m_key.algorithm()); | |
154 return m_algorithm.get(); | |
155 } | |
156 | |
157 // FIXME: This creates a new javascript array each time. What should happen | 150 // FIXME: This creates a new javascript array each time. What should happen |
158 // instead is return the same (immutable) array. (Javascript callers can | 151 // instead is return the same (immutable) array. (Javascript callers can |
159 // distinguish this by doing an == test on the arrays and seeing they are | 152 // distinguish this by doing an == test on the arrays and seeing they are |
160 // different). | 153 // different). |
161 Vector<String> CryptoKey::usages() const | 154 Vector<String> CryptoKey::usages() const |
162 { | 155 { |
163 Vector<String> result; | 156 Vector<String> result; |
164 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) { | 157 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) { |
165 blink::WebCryptoKeyUsage usage = keyUsageMappings[i].value; | 158 blink::WebCryptoKeyUsage usage = keyUsageMappings[i].value; |
166 if (m_key.usages() & usage) | 159 if (m_key.usages() & usage) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 blink::WebCryptoKeyUsageMask usage = keyUsageStringToMask(usages[i]); | 208 blink::WebCryptoKeyUsageMask usage = keyUsageStringToMask(usages[i]); |
216 if (!usage) { | 209 if (!usage) { |
217 result->completeWithError(blink::WebCryptoErrorTypeSyntax, "Invalid
keyUsages argument"); | 210 result->completeWithError(blink::WebCryptoErrorTypeSyntax, "Invalid
keyUsages argument"); |
218 return false; | 211 return false; |
219 } | 212 } |
220 mask |= usage; | 213 mask |= usage; |
221 } | 214 } |
222 return true; | 215 return true; |
223 } | 216 } |
224 | 217 |
225 void CryptoKey::trace(Visitor* visitor) | |
226 { | |
227 visitor->trace(m_algorithm); | |
228 } | |
229 | |
230 } // namespace WebCore | 218 } // namespace WebCore |
OLD | NEW |