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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 ASSERT_NOT_REACHED(); | 133 ASSERT_NOT_REACHED(); |
134 return ScriptPromise(); | 134 return ScriptPromise(); |
135 } | 135 } |
136 | 136 |
137 return promise; | 137 return promise; |
138 } | 138 } |
139 | 139 |
140 static bool copyStringProperty(const char* property, const Dictionary& source, J
SONObject* destination) | 140 static bool copyStringProperty(const char* property, const Dictionary& source, J
SONObject* destination) |
141 { | 141 { |
142 String value; | 142 String value; |
143 if (!source.get(property, value)) | 143 if (!DictionaryHelper::get(source, property, value)) |
144 return false; | 144 return false; |
145 destination->setString(property, value); | 145 destination->setString(property, value); |
146 return true; | 146 return true; |
147 } | 147 } |
148 | 148 |
149 static bool copySequenceOfStringProperty(const char* property, const Dictionary&
source, JSONObject* destination) | 149 static bool copySequenceOfStringProperty(const char* property, const Dictionary&
source, JSONObject* destination) |
150 { | 150 { |
151 Vector<String> value; | 151 Vector<String> value; |
152 if (!source.get(property, value)) | 152 if (!DictionaryHelper::get(source, property, value)) |
153 return false; | 153 return false; |
154 RefPtr<JSONArray> jsonArray = JSONArray::create(); | 154 RefPtr<JSONArray> jsonArray = JSONArray::create(); |
155 for (unsigned i = 0; i < value.size(); ++i) | 155 for (unsigned i = 0; i < value.size(); ++i) |
156 jsonArray->pushString(value[i]); | 156 jsonArray->pushString(value[i]); |
157 destination->setArray(property, jsonArray.release()); | 157 destination->setArray(property, jsonArray.release()); |
158 return true; | 158 return true; |
159 } | 159 } |
160 | 160 |
161 // FIXME: At the time of writing this is not a part of the spec. It is based an | 161 // 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: | 162 // an unpublished editor's draft for: |
163 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=24963 | 163 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=24963 |
164 // See http://crbug.com/373917. | 164 // See http://crbug.com/373917. |
165 static bool copyJwkDictionaryToJson(const Dictionary& dict, CString& jsonUtf8, C
ryptoResult* result) | 165 static bool copyJwkDictionaryToJson(const Dictionary& dict, CString& jsonUtf8, C
ryptoResult* result) |
166 { | 166 { |
167 RefPtr<JSONObject> jsonObject = JSONObject::create(); | 167 RefPtr<JSONObject> jsonObject = JSONObject::create(); |
168 | 168 |
169 if (!copyStringProperty("kty", dict, jsonObject.get())) { | 169 if (!copyStringProperty("kty", dict, jsonObject.get())) { |
170 result->completeWithError(blink::WebCryptoErrorTypeData, "The required J
WK property \"kty\" was missing"); | 170 result->completeWithError(blink::WebCryptoErrorTypeData, "The required J
WK property \"kty\" was missing"); |
171 return false; | 171 return false; |
172 } | 172 } |
173 | 173 |
174 copyStringProperty("use", dict, jsonObject.get()); | 174 copyStringProperty("use", dict, jsonObject.get()); |
175 copySequenceOfStringProperty("key_ops", dict, jsonObject.get()); | 175 copySequenceOfStringProperty("key_ops", dict, jsonObject.get()); |
176 copyStringProperty("alg", dict, jsonObject.get()); | 176 copyStringProperty("alg", dict, jsonObject.get()); |
177 | 177 |
178 bool ext; | 178 bool ext; |
179 if (dict.get("ext", ext)) | 179 if (DictionaryHelper::get(dict, "ext", ext)) |
180 jsonObject->setBoolean("ext", ext); | 180 jsonObject->setBoolean("ext", ext); |
181 | 181 |
182 const char* const propertyNames[] = { "d", "n", "e", "p", "q", "dp", "dq", "
qi", "k" }; | 182 const char* const propertyNames[] = { "d", "n", "e", "p", "q", "dp", "dq", "
qi", "k" }; |
183 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(propertyNames); ++i) | 183 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(propertyNames); ++i) |
184 copyStringProperty(propertyNames[i], dict, jsonObject.get()); | 184 copyStringProperty(propertyNames[i], dict, jsonObject.get()); |
185 | 185 |
186 String json = jsonObject->toJSONString(); | 186 String json = jsonObject->toJSONString(); |
187 jsonUtf8 = json.utf8(); | 187 jsonUtf8 = json.utf8(); |
188 return true; | 188 return true; |
189 } | 189 } |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 return promise; | 391 return promise; |
392 | 392 |
393 if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, blink::WebCryptoO
perationUnwrapKey, result.get())) | 393 if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, blink::WebCryptoO
perationUnwrapKey, result.get())) |
394 return promise; | 394 return promise; |
395 | 395 |
396 blink::Platform::current()->crypto()->unwrapKey(format, wrappedKey.bytes(),
wrappedKey.byteLength(), unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgo
rithm, extractable, keyUsages, result->result()); | 396 blink::Platform::current()->crypto()->unwrapKey(format, wrappedKey.bytes(),
wrappedKey.byteLength(), unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgo
rithm, extractable, keyUsages, result->result()); |
397 return promise; | 397 return promise; |
398 } | 398 } |
399 | 399 |
400 } // namespace WebCore | 400 } // namespace WebCore |
OLD | NEW |