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

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

Issue 1233173002: Have ScriptPromiseResolver on the Oilpan heap always. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fix webusb ScriptPromiseResolver usage Created 5 years, 4 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
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 jsonUtf8 = json.utf8(); 114 jsonUtf8 = json.utf8();
115 return true; 115 return true;
116 } 116 }
117 117
118 SubtleCrypto::SubtleCrypto() 118 SubtleCrypto::SubtleCrypto()
119 { 119 {
120 } 120 }
121 121
122 ScriptPromise SubtleCrypto::encrypt(ScriptState* scriptState, const AlgorithmIde ntifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data) 122 ScriptPromise SubtleCrypto::encrypt(ScriptState* scriptState, const AlgorithmIde ntifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data)
123 { 123 {
124 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip tState); 124 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
125 ScriptPromise promise = result->promise(); 125 ScriptPromise promise = result->promise();
126 126
127 if (!canAccessWebCrypto(scriptState, result.get())) 127 if (!canAccessWebCrypto(scriptState, result))
128 return promise; 128 return promise;
129 129
130 WebCryptoAlgorithm algorithm; 130 WebCryptoAlgorithm algorithm;
131 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationEncrypt, algorithm, resu lt.get())) 131 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationEncrypt, algorithm, resu lt))
132 return promise; 132 return promise;
133 133
134 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageEncrypt, result. get())) 134 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageEncrypt, result) )
135 return promise; 135 return promise;
136 136
137 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, key->ke y()); 137 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, key->ke y());
138 Platform::current()->crypto()->encrypt(algorithm, key->key(), data.bytes(), data.byteLength(), result->result()); 138 Platform::current()->crypto()->encrypt(algorithm, key->key(), data.bytes(), data.byteLength(), result->result());
139 return promise; 139 return promise;
140 } 140 }
141 141
142 ScriptPromise SubtleCrypto::decrypt(ScriptState* scriptState, const AlgorithmIde ntifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data) 142 ScriptPromise SubtleCrypto::decrypt(ScriptState* scriptState, const AlgorithmIde ntifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data)
143 { 143 {
144 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip tState); 144 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
145 ScriptPromise promise = result->promise(); 145 ScriptPromise promise = result->promise();
146 146
147 if (!canAccessWebCrypto(scriptState, result.get())) 147 if (!canAccessWebCrypto(scriptState, result))
148 return promise; 148 return promise;
149 149
150 WebCryptoAlgorithm algorithm; 150 WebCryptoAlgorithm algorithm;
151 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDecrypt, algorithm, resu lt.get())) 151 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDecrypt, algorithm, resu lt))
152 return promise; 152 return promise;
153 153
154 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDecrypt, result. get())) 154 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDecrypt, result) )
155 return promise; 155 return promise;
156 156
157 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, key->ke y()); 157 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, key->ke y());
158 Platform::current()->crypto()->decrypt(algorithm, key->key(), data.bytes(), data.byteLength(), result->result()); 158 Platform::current()->crypto()->decrypt(algorithm, key->key(), data.bytes(), data.byteLength(), result->result());
159 return promise; 159 return promise;
160 } 160 }
161 161
162 ScriptPromise SubtleCrypto::sign(ScriptState* scriptState, const AlgorithmIdenti fier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data) 162 ScriptPromise SubtleCrypto::sign(ScriptState* scriptState, const AlgorithmIdenti fier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data)
163 { 163 {
164 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip tState); 164 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
165 ScriptPromise promise = result->promise(); 165 ScriptPromise promise = result->promise();
166 166
167 if (!canAccessWebCrypto(scriptState, result.get())) 167 if (!canAccessWebCrypto(scriptState, result))
168 return promise; 168 return promise;
169 169
170 WebCryptoAlgorithm algorithm; 170 WebCryptoAlgorithm algorithm;
171 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationSign, algorithm, result. get())) 171 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationSign, algorithm, result) )
172 return promise; 172 return promise;
173 173
174 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageSign, result.get ())) 174 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageSign, result))
175 return promise; 175 return promise;
176 176
177 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, key->ke y()); 177 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, key->ke y());
178 Platform::current()->crypto()->sign(algorithm, key->key(), data.bytes(), dat a.byteLength(), result->result()); 178 Platform::current()->crypto()->sign(algorithm, key->key(), data.bytes(), dat a.byteLength(), result->result());
179 return promise; 179 return promise;
180 } 180 }
181 181
182 ScriptPromise SubtleCrypto::verifySignature(ScriptState* scriptState, const Algo rithmIdentifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& signature, c onst DOMArrayPiece& data) 182 ScriptPromise SubtleCrypto::verifySignature(ScriptState* scriptState, const Algo rithmIdentifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& signature, c onst DOMArrayPiece& data)
183 { 183 {
184 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip tState); 184 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
185 ScriptPromise promise = result->promise(); 185 ScriptPromise promise = result->promise();
186 186
187 if (!canAccessWebCrypto(scriptState, result.get())) 187 if (!canAccessWebCrypto(scriptState, result))
188 return promise; 188 return promise;
189 189
190 WebCryptoAlgorithm algorithm; 190 WebCryptoAlgorithm algorithm;
191 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationVerify, algorithm, resul t.get())) 191 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationVerify, algorithm, resul t))
192 return promise; 192 return promise;
193 193
194 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageVerify, result.g et())) 194 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageVerify, result))
195 return promise; 195 return promise;
196 196
197 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, key->ke y()); 197 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, key->ke y());
198 Platform::current()->crypto()->verifySignature(algorithm, key->key(), signat ure.bytes(), signature.byteLength(), data.bytes(), data.byteLength(), result->re sult()); 198 Platform::current()->crypto()->verifySignature(algorithm, key->key(), signat ure.bytes(), signature.byteLength(), data.bytes(), data.byteLength(), result->re sult());
199 return promise; 199 return promise;
200 } 200 }
201 201
202 ScriptPromise SubtleCrypto::digest(ScriptState* scriptState, const AlgorithmIden tifier& rawAlgorithm, const DOMArrayPiece& data) 202 ScriptPromise SubtleCrypto::digest(ScriptState* scriptState, const AlgorithmIden tifier& rawAlgorithm, const DOMArrayPiece& data)
203 { 203 {
204 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip tState); 204 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
205 ScriptPromise promise = result->promise(); 205 ScriptPromise promise = result->promise();
206 206
207 if (!canAccessWebCrypto(scriptState, result.get())) 207 if (!canAccessWebCrypto(scriptState, result))
208 return promise; 208 return promise;
209 209
210 WebCryptoAlgorithm algorithm; 210 WebCryptoAlgorithm algorithm;
211 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDigest, algorithm, resul t.get())) 211 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDigest, algorithm, resul t))
212 return promise; 212 return promise;
213 213
214 histogramAlgorithm(scriptState->executionContext(), algorithm); 214 histogramAlgorithm(scriptState->executionContext(), algorithm);
215 Platform::current()->crypto()->digest(algorithm, data.bytes(), data.byteLeng th(), result->result()); 215 Platform::current()->crypto()->digest(algorithm, data.bytes(), data.byteLeng th(), result->result());
216 return promise; 216 return promise;
217 } 217 }
218 218
219 ScriptPromise SubtleCrypto::generateKey(ScriptState* scriptState, const Algorith mIdentifier& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages) 219 ScriptPromise SubtleCrypto::generateKey(ScriptState* scriptState, const Algorith mIdentifier& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages)
220 { 220 {
221 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip tState); 221 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
222 ScriptPromise promise = result->promise(); 222 ScriptPromise promise = result->promise();
223 223
224 if (!canAccessWebCrypto(scriptState, result.get())) 224 if (!canAccessWebCrypto(scriptState, result))
225 return promise; 225 return promise;
226 226
227 WebCryptoKeyUsageMask keyUsages; 227 WebCryptoKeyUsageMask keyUsages;
228 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result.get())) 228 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result))
229 return promise; 229 return promise;
230 230
231 WebCryptoAlgorithm algorithm; 231 WebCryptoAlgorithm algorithm;
232 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationGenerateKey, algorithm, result.get())) 232 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationGenerateKey, algorithm, result))
233 return promise; 233 return promise;
234 234
235 histogramAlgorithm(scriptState->executionContext(), algorithm); 235 histogramAlgorithm(scriptState->executionContext(), algorithm);
236 Platform::current()->crypto()->generateKey(algorithm, extractable, keyUsages , result->result()); 236 Platform::current()->crypto()->generateKey(algorithm, extractable, keyUsages , result->result());
237 return promise; 237 return promise;
238 } 238 }
239 239
240 ScriptPromise SubtleCrypto::importKey(ScriptState* scriptState, const String& ra wFormat, const ArrayBufferOrArrayBufferViewOrDictionary& keyData, const Algorith mIdentifier& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages) 240 ScriptPromise SubtleCrypto::importKey(ScriptState* scriptState, const String& ra wFormat, const ArrayBufferOrArrayBufferViewOrDictionary& keyData, const Algorith mIdentifier& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages)
241 { 241 {
242 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip tState); 242 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
243 ScriptPromise promise = result->promise(); 243 ScriptPromise promise = result->promise();
244 244
245 if (!canAccessWebCrypto(scriptState, result.get())) 245 if (!canAccessWebCrypto(scriptState, result))
246 return promise; 246 return promise;
247 247
248 WebCryptoKeyFormat format; 248 WebCryptoKeyFormat format;
249 if (!CryptoKey::parseFormat(rawFormat, format, result.get())) 249 if (!CryptoKey::parseFormat(rawFormat, format, result))
250 return promise; 250 return promise;
251 251
252 if (keyData.isDictionary()) { 252 if (keyData.isDictionary()) {
253 if (format != WebCryptoKeyFormatJwk) { 253 if (format != WebCryptoKeyFormatJwk) {
254 result->completeWithError(WebCryptoErrorTypeData, "Key data must be a buffer for non-JWK formats"); 254 result->completeWithError(WebCryptoErrorTypeData, "Key data must be a buffer for non-JWK formats");
255 return promise; 255 return promise;
256 } 256 }
257 } else if (format == WebCryptoKeyFormatJwk) { 257 } else if (format == WebCryptoKeyFormatJwk) {
258 result->completeWithError(WebCryptoErrorTypeData, "Key data must be an o bject for JWK import"); 258 result->completeWithError(WebCryptoErrorTypeData, "Key data must be an o bject for JWK import");
259 return promise; 259 return promise;
260 } 260 }
261 261
262 WebCryptoKeyUsageMask keyUsages; 262 WebCryptoKeyUsageMask keyUsages;
263 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result.get())) 263 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result))
264 return promise; 264 return promise;
265 265
266 WebCryptoAlgorithm algorithm; 266 WebCryptoAlgorithm algorithm;
267 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationImportKey, algorithm, re sult.get())) 267 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationImportKey, algorithm, re sult))
268 return promise; 268 return promise;
269 269
270 const unsigned char* ptr = nullptr; 270 const unsigned char* ptr = nullptr;
271 unsigned len = 0; 271 unsigned len = 0;
272 272
273 CString jsonUtf8; 273 CString jsonUtf8;
274 if (keyData.isArrayBuffer()) { 274 if (keyData.isArrayBuffer()) {
275 ptr = static_cast<const unsigned char*>(keyData.getAsArrayBuffer()->data ()); 275 ptr = static_cast<const unsigned char*>(keyData.getAsArrayBuffer()->data ());
276 len = keyData.getAsArrayBuffer()->byteLength(); 276 len = keyData.getAsArrayBuffer()->byteLength();
277 } else if (keyData.isArrayBufferView()) { 277 } else if (keyData.isArrayBufferView()) {
278 ptr = static_cast<const unsigned char*>(keyData.getAsArrayBufferView()-> baseAddress()); 278 ptr = static_cast<const unsigned char*>(keyData.getAsArrayBufferView()-> baseAddress());
279 len = keyData.getAsArrayBufferView()->byteLength(); 279 len = keyData.getAsArrayBufferView()->byteLength();
280 } else if (keyData.isDictionary()) { 280 } else if (keyData.isDictionary()) {
281 if (!copyJwkDictionaryToJson(keyData.getAsDictionary(), jsonUtf8, result .get())) 281 if (!copyJwkDictionaryToJson(keyData.getAsDictionary(), jsonUtf8, result ))
282 return promise; 282 return promise;
283 ptr = reinterpret_cast<const unsigned char*>(jsonUtf8.data()); 283 ptr = reinterpret_cast<const unsigned char*>(jsonUtf8.data());
284 len = jsonUtf8.length(); 284 len = jsonUtf8.length();
285 } 285 }
286 histogramAlgorithm(scriptState->executionContext(), algorithm); 286 histogramAlgorithm(scriptState->executionContext(), algorithm);
287 Platform::current()->crypto()->importKey(format, ptr, len, algorithm, extrac table, keyUsages, result->result()); 287 Platform::current()->crypto()->importKey(format, ptr, len, algorithm, extrac table, keyUsages, result->result());
288 return promise; 288 return promise;
289 } 289 }
290 290
291 ScriptPromise SubtleCrypto::exportKey(ScriptState* scriptState, const String& ra wFormat, CryptoKey* key) 291 ScriptPromise SubtleCrypto::exportKey(ScriptState* scriptState, const String& ra wFormat, CryptoKey* key)
292 { 292 {
293 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip tState); 293 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
294 ScriptPromise promise = result->promise(); 294 ScriptPromise promise = result->promise();
295 295
296 if (!canAccessWebCrypto(scriptState, result.get())) 296 if (!canAccessWebCrypto(scriptState, result))
297 return promise; 297 return promise;
298 298
299 WebCryptoKeyFormat format; 299 WebCryptoKeyFormat format;
300 if (!CryptoKey::parseFormat(rawFormat, format, result.get())) 300 if (!CryptoKey::parseFormat(rawFormat, format, result))
301 return promise; 301 return promise;
302 302
303 if (!key->extractable()) { 303 if (!key->extractable()) {
304 result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key is not e xtractable"); 304 result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key is not e xtractable");
305 return promise; 305 return promise;
306 } 306 }
307 307
308 histogramKey(scriptState->executionContext(), key->key()); 308 histogramKey(scriptState->executionContext(), key->key());
309 Platform::current()->crypto()->exportKey(format, key->key(), result->result( )); 309 Platform::current()->crypto()->exportKey(format, key->key(), result->result( ));
310 return promise; 310 return promise;
311 } 311 }
312 312
313 ScriptPromise SubtleCrypto::wrapKey(ScriptState* scriptState, const String& rawF ormat, CryptoKey* key, CryptoKey* wrappingKey, const AlgorithmIdentifier& rawWra pAlgorithm) 313 ScriptPromise SubtleCrypto::wrapKey(ScriptState* scriptState, const String& rawF ormat, CryptoKey* key, CryptoKey* wrappingKey, const AlgorithmIdentifier& rawWra pAlgorithm)
314 { 314 {
315 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip tState); 315 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
316 ScriptPromise promise = result->promise(); 316 ScriptPromise promise = result->promise();
317 317
318 if (!canAccessWebCrypto(scriptState, result.get())) 318 if (!canAccessWebCrypto(scriptState, result))
319 return promise; 319 return promise;
320 320
321 WebCryptoKeyFormat format; 321 WebCryptoKeyFormat format;
322 if (!CryptoKey::parseFormat(rawFormat, format, result.get())) 322 if (!CryptoKey::parseFormat(rawFormat, format, result))
323 return promise; 323 return promise;
324 324
325 WebCryptoAlgorithm wrapAlgorithm; 325 WebCryptoAlgorithm wrapAlgorithm;
326 if (!parseAlgorithm(rawWrapAlgorithm, WebCryptoOperationWrapKey, wrapAlgorit hm, result.get())) 326 if (!parseAlgorithm(rawWrapAlgorithm, WebCryptoOperationWrapKey, wrapAlgorit hm, result))
327 return promise; 327 return promise;
328 328
329 if (!key->extractable()) { 329 if (!key->extractable()) {
330 result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key is not e xtractable"); 330 result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key is not e xtractable");
331 return promise; 331 return promise;
332 } 332 }
333 333
334 if (!wrappingKey->canBeUsedForAlgorithm(wrapAlgorithm, WebCryptoKeyUsageWrap Key, result.get())) 334 if (!wrappingKey->canBeUsedForAlgorithm(wrapAlgorithm, WebCryptoKeyUsageWrap Key, result))
335 return promise; 335 return promise;
336 336
337 histogramAlgorithmAndKey(scriptState->executionContext(), wrapAlgorithm, wra ppingKey->key()); 337 histogramAlgorithmAndKey(scriptState->executionContext(), wrapAlgorithm, wra ppingKey->key());
338 histogramKey(scriptState->executionContext(), key->key()); 338 histogramKey(scriptState->executionContext(), key->key());
339 Platform::current()->crypto()->wrapKey(format, key->key(), wrappingKey->key( ), wrapAlgorithm, result->result()); 339 Platform::current()->crypto()->wrapKey(format, key->key(), wrappingKey->key( ), wrapAlgorithm, result->result());
340 return promise; 340 return promise;
341 } 341 }
342 342
343 ScriptPromise SubtleCrypto::unwrapKey(ScriptState* scriptState, const String& ra wFormat, const DOMArrayPiece& wrappedKey, CryptoKey* unwrappingKey, const Algori thmIdentifier& rawUnwrapAlgorithm, const AlgorithmIdentifier& rawUnwrappedKeyAlg orithm, bool extractable, const Vector<String>& rawKeyUsages) 343 ScriptPromise SubtleCrypto::unwrapKey(ScriptState* scriptState, const String& ra wFormat, const DOMArrayPiece& wrappedKey, CryptoKey* unwrappingKey, const Algori thmIdentifier& rawUnwrapAlgorithm, const AlgorithmIdentifier& rawUnwrappedKeyAlg orithm, bool extractable, const Vector<String>& rawKeyUsages)
344 { 344 {
345 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip tState); 345 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
346 ScriptPromise promise = result->promise(); 346 ScriptPromise promise = result->promise();
347 347
348 if (!canAccessWebCrypto(scriptState, result.get())) 348 if (!canAccessWebCrypto(scriptState, result))
349 return promise; 349 return promise;
350 350
351 WebCryptoKeyFormat format; 351 WebCryptoKeyFormat format;
352 if (!CryptoKey::parseFormat(rawFormat, format, result.get())) 352 if (!CryptoKey::parseFormat(rawFormat, format, result))
353 return promise; 353 return promise;
354 354
355 WebCryptoKeyUsageMask keyUsages; 355 WebCryptoKeyUsageMask keyUsages;
356 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result.get())) 356 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result))
357 return promise; 357 return promise;
358 358
359 WebCryptoAlgorithm unwrapAlgorithm; 359 WebCryptoAlgorithm unwrapAlgorithm;
360 if (!parseAlgorithm(rawUnwrapAlgorithm, WebCryptoOperationUnwrapKey, unwrapA lgorithm, result.get())) 360 if (!parseAlgorithm(rawUnwrapAlgorithm, WebCryptoOperationUnwrapKey, unwrapA lgorithm, result))
361 return promise; 361 return promise;
362 362
363 WebCryptoAlgorithm unwrappedKeyAlgorithm; 363 WebCryptoAlgorithm unwrappedKeyAlgorithm;
364 if (!parseAlgorithm(rawUnwrappedKeyAlgorithm, WebCryptoOperationImportKey, u nwrappedKeyAlgorithm, result.get())) 364 if (!parseAlgorithm(rawUnwrappedKeyAlgorithm, WebCryptoOperationImportKey, u nwrappedKeyAlgorithm, result))
365 return promise; 365 return promise;
366 366
367 if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, WebCryptoKeyUsage UnwrapKey, result.get())) 367 if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, WebCryptoKeyUsage UnwrapKey, result))
368 return promise; 368 return promise;
369 369
370 histogramAlgorithmAndKey(scriptState->executionContext(), unwrapAlgorithm, u nwrappingKey->key()); 370 histogramAlgorithmAndKey(scriptState->executionContext(), unwrapAlgorithm, u nwrappingKey->key());
371 histogramAlgorithm(scriptState->executionContext(), unwrappedKeyAlgorithm); 371 histogramAlgorithm(scriptState->executionContext(), unwrappedKeyAlgorithm);
372 Platform::current()->crypto()->unwrapKey(format, wrappedKey.bytes(), wrapped Key.byteLength(), unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages, result->result()); 372 Platform::current()->crypto()->unwrapKey(format, wrappedKey.bytes(), wrapped Key.byteLength(), unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages, result->result());
373 return promise; 373 return promise;
374 } 374 }
375 375
376 ScriptPromise SubtleCrypto::deriveBits(ScriptState* scriptState, const Algorithm Identifier& rawAlgorithm, CryptoKey* baseKey, unsigned lengthBits) 376 ScriptPromise SubtleCrypto::deriveBits(ScriptState* scriptState, const Algorithm Identifier& rawAlgorithm, CryptoKey* baseKey, unsigned lengthBits)
377 { 377 {
378 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip tState); 378 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
379 ScriptPromise promise = result->promise(); 379 ScriptPromise promise = result->promise();
380 380
381 if (!canAccessWebCrypto(scriptState, result.get())) 381 if (!canAccessWebCrypto(scriptState, result))
382 return promise; 382 return promise;
383 383
384 WebCryptoAlgorithm algorithm; 384 WebCryptoAlgorithm algorithm;
385 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDeriveBits, algorithm, r esult.get())) 385 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDeriveBits, algorithm, r esult))
386 return promise; 386 return promise;
387 387
388 if (!baseKey->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDeriveBits, result.get())) 388 if (!baseKey->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDeriveBits, result))
389 return promise; 389 return promise;
390 390
391 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, baseKey ->key()); 391 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, baseKey ->key());
392 Platform::current()->crypto()->deriveBits(algorithm, baseKey->key(), lengthB its, result->result()); 392 Platform::current()->crypto()->deriveBits(algorithm, baseKey->key(), lengthB its, result->result());
393 return promise; 393 return promise;
394 } 394 }
395 395
396 ScriptPromise SubtleCrypto::deriveKey(ScriptState* scriptState, const AlgorithmI dentifier& rawAlgorithm, CryptoKey* baseKey, const AlgorithmIdentifier& rawDeriv edKeyType, bool extractable, const Vector<String>& rawKeyUsages) 396 ScriptPromise SubtleCrypto::deriveKey(ScriptState* scriptState, const AlgorithmI dentifier& rawAlgorithm, CryptoKey* baseKey, const AlgorithmIdentifier& rawDeriv edKeyType, bool extractable, const Vector<String>& rawKeyUsages)
397 { 397 {
398 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip tState); 398 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
399 ScriptPromise promise = result->promise(); 399 ScriptPromise promise = result->promise();
400 400
401 if (!canAccessWebCrypto(scriptState, result.get())) 401 if (!canAccessWebCrypto(scriptState, result))
402 return promise; 402 return promise;
403 403
404 WebCryptoKeyUsageMask keyUsages; 404 WebCryptoKeyUsageMask keyUsages;
405 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result.get())) 405 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result))
406 return promise; 406 return promise;
407 407
408 WebCryptoAlgorithm algorithm; 408 WebCryptoAlgorithm algorithm;
409 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDeriveBits, algorithm, r esult.get())) 409 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDeriveBits, algorithm, r esult))
410 return promise; 410 return promise;
411 411
412 if (!baseKey->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDeriveKey, r esult.get())) 412 if (!baseKey->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDeriveKey, r esult))
413 return promise; 413 return promise;
414 414
415 WebCryptoAlgorithm importAlgorithm; 415 WebCryptoAlgorithm importAlgorithm;
416 if (!parseAlgorithm(rawDerivedKeyType, WebCryptoOperationImportKey, importAl gorithm, result.get())) 416 if (!parseAlgorithm(rawDerivedKeyType, WebCryptoOperationImportKey, importAl gorithm, result))
417 return promise; 417 return promise;
418 418
419 WebCryptoAlgorithm keyLengthAlgorithm; 419 WebCryptoAlgorithm keyLengthAlgorithm;
420 if (!parseAlgorithm(rawDerivedKeyType, WebCryptoOperationGetKeyLength, keyLe ngthAlgorithm, result.get())) 420 if (!parseAlgorithm(rawDerivedKeyType, WebCryptoOperationGetKeyLength, keyLe ngthAlgorithm, result))
421 return promise; 421 return promise;
422 422
423 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, baseKey ->key()); 423 histogramAlgorithmAndKey(scriptState->executionContext(), algorithm, baseKey ->key());
424 histogramAlgorithm(scriptState->executionContext(), importAlgorithm); 424 histogramAlgorithm(scriptState->executionContext(), importAlgorithm);
425 Platform::current()->crypto()->deriveKey(algorithm, baseKey->key(), importAl gorithm, keyLengthAlgorithm, extractable, keyUsages, result->result()); 425 Platform::current()->crypto()->deriveKey(algorithm, baseKey->key(), importAl gorithm, keyLengthAlgorithm, extractable, keyUsages, result->result());
426 return promise; 426 return promise;
427 } 427 }
428 428
429 } // namespace blink 429 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/crypto/CryptoResultImpl.cpp ('k') | Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698