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