Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: Source/modules/crypto/SubtleCrypto.cpp

Issue 373423002: Split Dictionary's get and convert into DictionaryHelper. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed LICENSE and windows build Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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/SubtleCrypto.h" 32 #include "modules/crypto/SubtleCrypto.h"
33 33
34 #include "bindings/core/v8/Dictionary.h" 34 #include "bindings/core/v8/Dictionary.h"
35 #include "bindings/core/v8/DictionaryHelper.h"
35 #include "core/dom/ExecutionContext.h" 36 #include "core/dom/ExecutionContext.h"
36 #include "modules/crypto/CryptoKey.h" 37 #include "modules/crypto/CryptoKey.h"
37 #include "modules/crypto/CryptoResultImpl.h" 38 #include "modules/crypto/CryptoResultImpl.h"
38 #include "modules/crypto/NormalizeAlgorithm.h" 39 #include "modules/crypto/NormalizeAlgorithm.h"
39 #include "platform/JSONValues.h" 40 #include "platform/JSONValues.h"
40 #include "public/platform/Platform.h" 41 #include "public/platform/Platform.h"
41 #include "public/platform/WebCrypto.h" 42 #include "public/platform/WebCrypto.h"
42 #include "public/platform/WebCryptoAlgorithm.h" 43 #include "public/platform/WebCryptoAlgorithm.h"
43 #include "wtf/ArrayBufferView.h" 44 #include "wtf/ArrayBufferView.h"
44 45
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 ASSERT_NOT_REACHED(); 134 ASSERT_NOT_REACHED();
134 return ScriptPromise(); 135 return ScriptPromise();
135 } 136 }
136 137
137 return promise; 138 return promise;
138 } 139 }
139 140
140 static bool copyStringProperty(const char* property, const Dictionary& source, J SONObject* destination) 141 static bool copyStringProperty(const char* property, const Dictionary& source, J SONObject* destination)
141 { 142 {
142 String value; 143 String value;
143 if (!source.get(property, value)) 144 if (!DictionaryHelper::get(source, property, value))
144 return false; 145 return false;
145 destination->setString(property, value); 146 destination->setString(property, value);
146 return true; 147 return true;
147 } 148 }
148 149
149 static bool copySequenceOfStringProperty(const char* property, const Dictionary& source, JSONObject* destination) 150 static bool copySequenceOfStringProperty(const char* property, const Dictionary& source, JSONObject* destination)
150 { 151 {
151 Vector<String> value; 152 Vector<String> value;
152 if (!source.get(property, value)) 153 if (!DictionaryHelper::get(source, property, value))
153 return false; 154 return false;
154 RefPtr<JSONArray> jsonArray = JSONArray::create(); 155 RefPtr<JSONArray> jsonArray = JSONArray::create();
155 for (unsigned i = 0; i < value.size(); ++i) 156 for (unsigned i = 0; i < value.size(); ++i)
156 jsonArray->pushString(value[i]); 157 jsonArray->pushString(value[i]);
157 destination->setArray(property, jsonArray.release()); 158 destination->setArray(property, jsonArray.release());
158 return true; 159 return true;
159 } 160 }
160 161
161 // FIXME: At the time of writing this is not a part of the spec. It is based an 162 // FIXME: At the time of writing this is not a part of the spec. It is based an
162 // an unpublished editor's draft for: 163 // an unpublished editor's draft for:
163 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=24963 164 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=24963
164 // See http://crbug.com/373917. 165 // See http://crbug.com/373917.
165 static bool copyJwkDictionaryToJson(const Dictionary& dict, CString& jsonUtf8, C ryptoResult* result) 166 static bool copyJwkDictionaryToJson(const Dictionary& dict, CString& jsonUtf8, C ryptoResult* result)
166 { 167 {
167 RefPtr<JSONObject> jsonObject = JSONObject::create(); 168 RefPtr<JSONObject> jsonObject = JSONObject::create();
168 169
169 if (!copyStringProperty("kty", dict, jsonObject.get())) { 170 if (!copyStringProperty("kty", dict, jsonObject.get())) {
170 result->completeWithError(blink::WebCryptoErrorTypeData, "The required J WK property \"kty\" was missing"); 171 result->completeWithError(blink::WebCryptoErrorTypeData, "The required J WK property \"kty\" was missing");
171 return false; 172 return false;
172 } 173 }
173 174
174 copyStringProperty("use", dict, jsonObject.get()); 175 copyStringProperty("use", dict, jsonObject.get());
175 copySequenceOfStringProperty("key_ops", dict, jsonObject.get()); 176 copySequenceOfStringProperty("key_ops", dict, jsonObject.get());
176 copyStringProperty("alg", dict, jsonObject.get()); 177 copyStringProperty("alg", dict, jsonObject.get());
177 178
178 bool ext; 179 bool ext;
179 if (dict.get("ext", ext)) 180 if (DictionaryHelper::get(dict, "ext", ext))
180 jsonObject->setBoolean("ext", ext); 181 jsonObject->setBoolean("ext", ext);
181 182
182 const char* const propertyNames[] = { "d", "n", "e", "p", "q", "dp", "dq", " qi", "k" }; 183 const char* const propertyNames[] = { "d", "n", "e", "p", "q", "dp", "dq", " qi", "k" };
183 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(propertyNames); ++i) 184 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(propertyNames); ++i)
184 copyStringProperty(propertyNames[i], dict, jsonObject.get()); 185 copyStringProperty(propertyNames[i], dict, jsonObject.get());
185 186
186 String json = jsonObject->toJSONString(); 187 String json = jsonObject->toJSONString();
187 jsonUtf8 = json.utf8(); 188 jsonUtf8 = json.utf8();
188 return true; 189 return true;
189 } 190 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 return promise; 392 return promise;
392 393
393 if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, blink::WebCryptoO perationUnwrapKey, result.get())) 394 if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, blink::WebCryptoO perationUnwrapKey, result.get()))
394 return promise; 395 return promise;
395 396
396 blink::Platform::current()->crypto()->unwrapKey(format, wrappedKey.bytes(), wrappedKey.byteLength(), unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgo rithm, extractable, keyUsages, result->result()); 397 blink::Platform::current()->crypto()->unwrapKey(format, wrappedKey.bytes(), wrappedKey.byteLength(), unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgo rithm, extractable, keyUsages, result->result());
397 return promise; 398 return promise;
398 } 399 }
399 400
400 } // namespace WebCore 401 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698