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 14 matching lines...) Expand all Loading... |
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 #include "config.h" | 31 #include "config.h" |
32 #include "modules/crypto/CryptoKey.h" | 32 #include "modules/crypto/CryptoKey.h" |
33 | 33 |
34 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
| 35 #include "bindings/core/v8/V8Uint8Array.h" |
35 #include "core/dom/ExceptionCode.h" | 36 #include "core/dom/ExceptionCode.h" |
36 #include "platform/CryptoResult.h" | 37 #include "platform/CryptoResult.h" |
37 #include "public/platform/WebCryptoAlgorithmParams.h" | 38 #include "public/platform/WebCryptoAlgorithmParams.h" |
38 #include "public/platform/WebCryptoKeyAlgorithm.h" | 39 #include "public/platform/WebCryptoKeyAlgorithm.h" |
39 #include "public/platform/WebString.h" | 40 #include "public/platform/WebString.h" |
40 | 41 |
41 namespace blink { | 42 namespace blink { |
42 | 43 |
43 namespace { | 44 namespace { |
44 | 45 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 90 |
90 WebCryptoKeyUsageMask keyUsageStringToMask(const String& usageString) | 91 WebCryptoKeyUsageMask keyUsageStringToMask(const String& usageString) |
91 { | 92 { |
92 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) { | 93 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) { |
93 if (keyUsageMappings[i].name == usageString) | 94 if (keyUsageMappings[i].name == usageString) |
94 return keyUsageMappings[i].value; | 95 return keyUsageMappings[i].value; |
95 } | 96 } |
96 return 0; | 97 return 0; |
97 } | 98 } |
98 | 99 |
| 100 class DictionaryBuilder : public blink::WebCryptoKeyAlgorithmDictionary { |
| 101 public: |
| 102 explicit DictionaryBuilder(ScriptState* scriptState) |
| 103 : m_scriptState(scriptState) |
| 104 , m_dictionary(Dictionary::createEmpty(scriptState->isolate())) |
| 105 { |
| 106 } |
| 107 |
| 108 virtual void setString(const char* propertyName, const char* value) |
| 109 { |
| 110 m_dictionary.set(propertyName, value); |
| 111 } |
| 112 |
| 113 virtual void setUint(const char* propertyName, unsigned value) |
| 114 { |
| 115 m_dictionary.set(propertyName, value); |
| 116 } |
| 117 |
| 118 virtual void setAlgorithm(const char* propertyName, const blink::WebCryptoAl
gorithm& algorithm) |
| 119 { |
| 120 ASSERT(algorithm.paramsType() == blink::WebCryptoAlgorithmParamsTypeNone
); |
| 121 |
| 122 Dictionary algorithmValue = Dictionary::createEmpty(m_scriptState->isola
te()); |
| 123 algorithmValue.set("name", blink::WebCryptoAlgorithm::lookupAlgorithmInf
o(algorithm.id())->name); |
| 124 m_dictionary.set(propertyName, algorithmValue); |
| 125 } |
| 126 |
| 127 virtual void setUint8Array(const char* propertyName, const blink::WebVector<
unsigned char>& vector) |
| 128 { |
| 129 m_dictionary.set(propertyName, toV8(DOMUint8Array::create(vector.data(),
vector.size()), m_scriptState->context()->Global(), m_scriptState->isolate())); |
| 130 } |
| 131 |
| 132 const Dictionary& dictionary() const { return m_dictionary; } |
| 133 |
| 134 private: |
| 135 RefPtr<ScriptState> m_scriptState; |
| 136 Dictionary m_dictionary; |
| 137 }; |
| 138 |
99 } // namespace | 139 } // namespace |
100 | 140 |
101 CryptoKey::~CryptoKey() | 141 CryptoKey::~CryptoKey() |
102 { | 142 { |
103 } | 143 } |
104 | 144 |
105 CryptoKey::CryptoKey(const WebCryptoKey& key) | 145 CryptoKey::CryptoKey(const WebCryptoKey& key) |
106 : m_key(key) | 146 : m_key(key) |
107 { | 147 { |
108 } | 148 } |
109 | 149 |
110 String CryptoKey::type() const | 150 String CryptoKey::type() const |
111 { | 151 { |
112 return keyTypeToString(m_key.type()); | 152 return keyTypeToString(m_key.type()); |
113 } | 153 } |
114 | 154 |
115 bool CryptoKey::extractable() const | 155 bool CryptoKey::extractable() const |
116 { | 156 { |
117 return m_key.extractable(); | 157 return m_key.extractable(); |
118 } | 158 } |
119 | 159 |
| 160 ScriptValue CryptoKey::algorithm(ScriptState* scriptState) |
| 161 { |
| 162 DictionaryBuilder builder(scriptState); |
| 163 m_key.algorithm().writeToDictionary(&builder); |
| 164 return ScriptValue(scriptState, builder.dictionary().v8Value()); |
| 165 } |
| 166 |
120 // FIXME: This creates a new javascript array each time. What should happen | 167 // FIXME: This creates a new javascript array each time. What should happen |
121 // instead is return the same (immutable) array. (Javascript callers can | 168 // instead is return the same (immutable) array. (Javascript callers can |
122 // distinguish this by doing an == test on the arrays and seeing they are | 169 // distinguish this by doing an == test on the arrays and seeing they are |
123 // different). | 170 // different). |
124 Vector<String> CryptoKey::usages() const | 171 Vector<String> CryptoKey::usages() const |
125 { | 172 { |
126 Vector<String> result; | 173 Vector<String> result; |
127 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) { | 174 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) { |
128 WebCryptoKeyUsage usage = keyUsageMappings[i].value; | 175 WebCryptoKeyUsage usage = keyUsageMappings[i].value; |
129 if (m_key.usages() & usage) | 176 if (m_key.usages() & usage) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 if (!usage) { | 226 if (!usage) { |
180 result->completeWithError(WebCryptoErrorTypeType, "Invalid keyUsages
argument"); | 227 result->completeWithError(WebCryptoErrorTypeType, "Invalid keyUsages
argument"); |
181 return false; | 228 return false; |
182 } | 229 } |
183 mask |= usage; | 230 mask |= usage; |
184 } | 231 } |
185 return true; | 232 return true; |
186 } | 233 } |
187 | 234 |
188 } // namespace blink | 235 } // namespace blink |
OLD | NEW |