OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/webcrypto/webcrypto_impl.h" | 5 #include "components/webcrypto/webcrypto_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 } | 378 } |
379 | 379 |
380 void DoEncrypt(scoped_ptr<EncryptState> passed_state) { | 380 void DoEncrypt(scoped_ptr<EncryptState> passed_state) { |
381 EncryptState* state = passed_state.get(); | 381 EncryptState* state = passed_state.get(); |
382 if (state->cancelled()) | 382 if (state->cancelled()) |
383 return; | 383 return; |
384 state->status = | 384 state->status = |
385 webcrypto::Encrypt(state->algorithm, state->key, | 385 webcrypto::Encrypt(state->algorithm, state->key, |
386 webcrypto::CryptoData(state->data), &state->buffer); | 386 webcrypto::CryptoData(state->data), &state->buffer); |
387 state->origin_thread->PostTask( | 387 state->origin_thread->PostTask( |
388 FROM_HERE, base::Bind(DoEncryptReply, Passed(&passed_state))); | 388 FROM_HERE, base::Bind(DoEncryptReply, base::Passed(&passed_state))); |
389 } | 389 } |
390 | 390 |
391 void DoDecryptReply(scoped_ptr<DecryptState> state) { | 391 void DoDecryptReply(scoped_ptr<DecryptState> state) { |
392 CompleteWithBufferOrError(state->status, state->buffer, &state->result); | 392 CompleteWithBufferOrError(state->status, state->buffer, &state->result); |
393 } | 393 } |
394 | 394 |
395 void DoDecrypt(scoped_ptr<DecryptState> passed_state) { | 395 void DoDecrypt(scoped_ptr<DecryptState> passed_state) { |
396 DecryptState* state = passed_state.get(); | 396 DecryptState* state = passed_state.get(); |
397 if (state->cancelled()) | 397 if (state->cancelled()) |
398 return; | 398 return; |
399 state->status = | 399 state->status = |
400 webcrypto::Decrypt(state->algorithm, state->key, | 400 webcrypto::Decrypt(state->algorithm, state->key, |
401 webcrypto::CryptoData(state->data), &state->buffer); | 401 webcrypto::CryptoData(state->data), &state->buffer); |
402 state->origin_thread->PostTask( | 402 state->origin_thread->PostTask( |
403 FROM_HERE, base::Bind(DoDecryptReply, Passed(&passed_state))); | 403 FROM_HERE, base::Bind(DoDecryptReply, base::Passed(&passed_state))); |
404 } | 404 } |
405 | 405 |
406 void DoDigestReply(scoped_ptr<DigestState> state) { | 406 void DoDigestReply(scoped_ptr<DigestState> state) { |
407 CompleteWithBufferOrError(state->status, state->buffer, &state->result); | 407 CompleteWithBufferOrError(state->status, state->buffer, &state->result); |
408 } | 408 } |
409 | 409 |
410 void DoDigest(scoped_ptr<DigestState> passed_state) { | 410 void DoDigest(scoped_ptr<DigestState> passed_state) { |
411 DigestState* state = passed_state.get(); | 411 DigestState* state = passed_state.get(); |
412 if (state->cancelled()) | 412 if (state->cancelled()) |
413 return; | 413 return; |
414 state->status = webcrypto::Digest( | 414 state->status = webcrypto::Digest( |
415 state->algorithm, webcrypto::CryptoData(state->data), &state->buffer); | 415 state->algorithm, webcrypto::CryptoData(state->data), &state->buffer); |
416 state->origin_thread->PostTask( | 416 state->origin_thread->PostTask( |
417 FROM_HERE, base::Bind(DoDigestReply, Passed(&passed_state))); | 417 FROM_HERE, base::Bind(DoDigestReply, base::Passed(&passed_state))); |
418 } | 418 } |
419 | 419 |
420 void DoGenerateKeyReply(scoped_ptr<GenerateKeyState> state) { | 420 void DoGenerateKeyReply(scoped_ptr<GenerateKeyState> state) { |
421 if (state->status.IsError()) { | 421 if (state->status.IsError()) { |
422 CompleteWithError(state->status, &state->result); | 422 CompleteWithError(state->status, &state->result); |
423 } else { | 423 } else { |
424 state->generate_key_result.Complete(&state->result); | 424 state->generate_key_result.Complete(&state->result); |
425 } | 425 } |
426 } | 426 } |
427 | 427 |
428 void DoGenerateKey(scoped_ptr<GenerateKeyState> passed_state) { | 428 void DoGenerateKey(scoped_ptr<GenerateKeyState> passed_state) { |
429 GenerateKeyState* state = passed_state.get(); | 429 GenerateKeyState* state = passed_state.get(); |
430 if (state->cancelled()) | 430 if (state->cancelled()) |
431 return; | 431 return; |
432 state->status = | 432 state->status = |
433 webcrypto::GenerateKey(state->algorithm, state->extractable, | 433 webcrypto::GenerateKey(state->algorithm, state->extractable, |
434 state->usages, &state->generate_key_result); | 434 state->usages, &state->generate_key_result); |
435 state->origin_thread->PostTask( | 435 state->origin_thread->PostTask( |
436 FROM_HERE, base::Bind(DoGenerateKeyReply, Passed(&passed_state))); | 436 FROM_HERE, base::Bind(DoGenerateKeyReply, base::Passed(&passed_state))); |
437 } | 437 } |
438 | 438 |
439 void DoImportKeyReply(scoped_ptr<ImportKeyState> state) { | 439 void DoImportKeyReply(scoped_ptr<ImportKeyState> state) { |
440 CompleteWithKeyOrError(state->status, state->key, &state->result); | 440 CompleteWithKeyOrError(state->status, state->key, &state->result); |
441 } | 441 } |
442 | 442 |
443 void DoImportKey(scoped_ptr<ImportKeyState> passed_state) { | 443 void DoImportKey(scoped_ptr<ImportKeyState> passed_state) { |
444 ImportKeyState* state = passed_state.get(); | 444 ImportKeyState* state = passed_state.get(); |
445 if (state->cancelled()) | 445 if (state->cancelled()) |
446 return; | 446 return; |
447 state->status = webcrypto::ImportKey( | 447 state->status = webcrypto::ImportKey( |
448 state->format, webcrypto::CryptoData(state->key_data), state->algorithm, | 448 state->format, webcrypto::CryptoData(state->key_data), state->algorithm, |
449 state->extractable, state->usages, &state->key); | 449 state->extractable, state->usages, &state->key); |
450 if (state->status.IsSuccess()) { | 450 if (state->status.IsSuccess()) { |
451 DCHECK(state->key.handle()); | 451 DCHECK(state->key.handle()); |
452 DCHECK(!state->key.algorithm().isNull()); | 452 DCHECK(!state->key.algorithm().isNull()); |
453 DCHECK_EQ(state->extractable, state->key.extractable()); | 453 DCHECK_EQ(state->extractable, state->key.extractable()); |
454 } | 454 } |
455 | 455 |
456 state->origin_thread->PostTask( | 456 state->origin_thread->PostTask( |
457 FROM_HERE, base::Bind(DoImportKeyReply, Passed(&passed_state))); | 457 FROM_HERE, base::Bind(DoImportKeyReply, base::Passed(&passed_state))); |
458 } | 458 } |
459 | 459 |
460 void DoExportKeyReply(scoped_ptr<ExportKeyState> state) { | 460 void DoExportKeyReply(scoped_ptr<ExportKeyState> state) { |
461 if (state->format != blink::WebCryptoKeyFormatJwk) { | 461 if (state->format != blink::WebCryptoKeyFormatJwk) { |
462 CompleteWithBufferOrError(state->status, state->buffer, &state->result); | 462 CompleteWithBufferOrError(state->status, state->buffer, &state->result); |
463 return; | 463 return; |
464 } | 464 } |
465 | 465 |
466 if (state->status.IsError()) { | 466 if (state->status.IsError()) { |
467 CompleteWithError(state->status, &state->result); | 467 CompleteWithError(state->status, &state->result); |
468 } else { | 468 } else { |
469 state->result.completeWithJson( | 469 state->result.completeWithJson( |
470 reinterpret_cast<const char*>(vector_as_array(&state->buffer)), | 470 reinterpret_cast<const char*>(vector_as_array(&state->buffer)), |
471 static_cast<unsigned int>(state->buffer.size())); | 471 static_cast<unsigned int>(state->buffer.size())); |
472 } | 472 } |
473 } | 473 } |
474 | 474 |
475 void DoExportKey(scoped_ptr<ExportKeyState> passed_state) { | 475 void DoExportKey(scoped_ptr<ExportKeyState> passed_state) { |
476 ExportKeyState* state = passed_state.get(); | 476 ExportKeyState* state = passed_state.get(); |
477 if (state->cancelled()) | 477 if (state->cancelled()) |
478 return; | 478 return; |
479 state->status = | 479 state->status = |
480 webcrypto::ExportKey(state->format, state->key, &state->buffer); | 480 webcrypto::ExportKey(state->format, state->key, &state->buffer); |
481 state->origin_thread->PostTask( | 481 state->origin_thread->PostTask( |
482 FROM_HERE, base::Bind(DoExportKeyReply, Passed(&passed_state))); | 482 FROM_HERE, base::Bind(DoExportKeyReply, base::Passed(&passed_state))); |
483 } | 483 } |
484 | 484 |
485 void DoSignReply(scoped_ptr<SignState> state) { | 485 void DoSignReply(scoped_ptr<SignState> state) { |
486 CompleteWithBufferOrError(state->status, state->buffer, &state->result); | 486 CompleteWithBufferOrError(state->status, state->buffer, &state->result); |
487 } | 487 } |
488 | 488 |
489 void DoSign(scoped_ptr<SignState> passed_state) { | 489 void DoSign(scoped_ptr<SignState> passed_state) { |
490 SignState* state = passed_state.get(); | 490 SignState* state = passed_state.get(); |
491 if (state->cancelled()) | 491 if (state->cancelled()) |
492 return; | 492 return; |
493 state->status = | 493 state->status = |
494 webcrypto::Sign(state->algorithm, state->key, | 494 webcrypto::Sign(state->algorithm, state->key, |
495 webcrypto::CryptoData(state->data), &state->buffer); | 495 webcrypto::CryptoData(state->data), &state->buffer); |
496 | 496 |
497 state->origin_thread->PostTask( | 497 state->origin_thread->PostTask( |
498 FROM_HERE, base::Bind(DoSignReply, Passed(&passed_state))); | 498 FROM_HERE, base::Bind(DoSignReply, base::Passed(&passed_state))); |
499 } | 499 } |
500 | 500 |
501 void DoVerifyReply(scoped_ptr<VerifySignatureState> state) { | 501 void DoVerifyReply(scoped_ptr<VerifySignatureState> state) { |
502 if (state->status.IsError()) { | 502 if (state->status.IsError()) { |
503 CompleteWithError(state->status, &state->result); | 503 CompleteWithError(state->status, &state->result); |
504 } else { | 504 } else { |
505 state->result.completeWithBoolean(state->verify_result); | 505 state->result.completeWithBoolean(state->verify_result); |
506 } | 506 } |
507 } | 507 } |
508 | 508 |
509 void DoVerify(scoped_ptr<VerifySignatureState> passed_state) { | 509 void DoVerify(scoped_ptr<VerifySignatureState> passed_state) { |
510 VerifySignatureState* state = passed_state.get(); | 510 VerifySignatureState* state = passed_state.get(); |
511 if (state->cancelled()) | 511 if (state->cancelled()) |
512 return; | 512 return; |
513 state->status = webcrypto::Verify( | 513 state->status = webcrypto::Verify( |
514 state->algorithm, state->key, webcrypto::CryptoData(state->signature), | 514 state->algorithm, state->key, webcrypto::CryptoData(state->signature), |
515 webcrypto::CryptoData(state->data), &state->verify_result); | 515 webcrypto::CryptoData(state->data), &state->verify_result); |
516 | 516 |
517 state->origin_thread->PostTask( | 517 state->origin_thread->PostTask( |
518 FROM_HERE, base::Bind(DoVerifyReply, Passed(&passed_state))); | 518 FROM_HERE, base::Bind(DoVerifyReply, base::Passed(&passed_state))); |
519 } | 519 } |
520 | 520 |
521 void DoWrapKeyReply(scoped_ptr<WrapKeyState> state) { | 521 void DoWrapKeyReply(scoped_ptr<WrapKeyState> state) { |
522 CompleteWithBufferOrError(state->status, state->buffer, &state->result); | 522 CompleteWithBufferOrError(state->status, state->buffer, &state->result); |
523 } | 523 } |
524 | 524 |
525 void DoWrapKey(scoped_ptr<WrapKeyState> passed_state) { | 525 void DoWrapKey(scoped_ptr<WrapKeyState> passed_state) { |
526 WrapKeyState* state = passed_state.get(); | 526 WrapKeyState* state = passed_state.get(); |
527 if (state->cancelled()) | 527 if (state->cancelled()) |
528 return; | 528 return; |
529 state->status = | 529 state->status = |
530 webcrypto::WrapKey(state->format, state->key, state->wrapping_key, | 530 webcrypto::WrapKey(state->format, state->key, state->wrapping_key, |
531 state->wrap_algorithm, &state->buffer); | 531 state->wrap_algorithm, &state->buffer); |
532 | 532 |
533 state->origin_thread->PostTask( | 533 state->origin_thread->PostTask( |
534 FROM_HERE, base::Bind(DoWrapKeyReply, Passed(&passed_state))); | 534 FROM_HERE, base::Bind(DoWrapKeyReply, base::Passed(&passed_state))); |
535 } | 535 } |
536 | 536 |
537 void DoUnwrapKeyReply(scoped_ptr<UnwrapKeyState> state) { | 537 void DoUnwrapKeyReply(scoped_ptr<UnwrapKeyState> state) { |
538 CompleteWithKeyOrError(state->status, state->unwrapped_key, &state->result); | 538 CompleteWithKeyOrError(state->status, state->unwrapped_key, &state->result); |
539 } | 539 } |
540 | 540 |
541 void DoUnwrapKey(scoped_ptr<UnwrapKeyState> passed_state) { | 541 void DoUnwrapKey(scoped_ptr<UnwrapKeyState> passed_state) { |
542 UnwrapKeyState* state = passed_state.get(); | 542 UnwrapKeyState* state = passed_state.get(); |
543 if (state->cancelled()) | 543 if (state->cancelled()) |
544 return; | 544 return; |
545 state->status = webcrypto::UnwrapKey( | 545 state->status = webcrypto::UnwrapKey( |
546 state->format, webcrypto::CryptoData(state->wrapped_key), | 546 state->format, webcrypto::CryptoData(state->wrapped_key), |
547 state->wrapping_key, state->unwrap_algorithm, | 547 state->wrapping_key, state->unwrap_algorithm, |
548 state->unwrapped_key_algorithm, state->extractable, state->usages, | 548 state->unwrapped_key_algorithm, state->extractable, state->usages, |
549 &state->unwrapped_key); | 549 &state->unwrapped_key); |
550 | 550 |
551 state->origin_thread->PostTask( | 551 state->origin_thread->PostTask( |
552 FROM_HERE, base::Bind(DoUnwrapKeyReply, Passed(&passed_state))); | 552 FROM_HERE, base::Bind(DoUnwrapKeyReply, base::Passed(&passed_state))); |
553 } | 553 } |
554 | 554 |
555 void DoDeriveBitsReply(scoped_ptr<DeriveBitsState> state) { | 555 void DoDeriveBitsReply(scoped_ptr<DeriveBitsState> state) { |
556 CompleteWithBufferOrError(state->status, state->derived_bytes, | 556 CompleteWithBufferOrError(state->status, state->derived_bytes, |
557 &state->result); | 557 &state->result); |
558 } | 558 } |
559 | 559 |
560 void DoDeriveBits(scoped_ptr<DeriveBitsState> passed_state) { | 560 void DoDeriveBits(scoped_ptr<DeriveBitsState> passed_state) { |
561 DeriveBitsState* state = passed_state.get(); | 561 DeriveBitsState* state = passed_state.get(); |
562 if (state->cancelled()) | 562 if (state->cancelled()) |
563 return; | 563 return; |
564 state->status = | 564 state->status = |
565 webcrypto::DeriveBits(state->algorithm, state->base_key, | 565 webcrypto::DeriveBits(state->algorithm, state->base_key, |
566 state->length_bits, &state->derived_bytes); | 566 state->length_bits, &state->derived_bytes); |
567 state->origin_thread->PostTask( | 567 state->origin_thread->PostTask( |
568 FROM_HERE, base::Bind(DoDeriveBitsReply, Passed(&passed_state))); | 568 FROM_HERE, base::Bind(DoDeriveBitsReply, base::Passed(&passed_state))); |
569 } | 569 } |
570 | 570 |
571 void DoDeriveKeyReply(scoped_ptr<DeriveKeyState> state) { | 571 void DoDeriveKeyReply(scoped_ptr<DeriveKeyState> state) { |
572 CompleteWithKeyOrError(state->status, state->derived_key, &state->result); | 572 CompleteWithKeyOrError(state->status, state->derived_key, &state->result); |
573 } | 573 } |
574 | 574 |
575 void DoDeriveKey(scoped_ptr<DeriveKeyState> passed_state) { | 575 void DoDeriveKey(scoped_ptr<DeriveKeyState> passed_state) { |
576 DeriveKeyState* state = passed_state.get(); | 576 DeriveKeyState* state = passed_state.get(); |
577 if (state->cancelled()) | 577 if (state->cancelled()) |
578 return; | 578 return; |
579 state->status = webcrypto::DeriveKey( | 579 state->status = webcrypto::DeriveKey( |
580 state->algorithm, state->base_key, state->import_algorithm, | 580 state->algorithm, state->base_key, state->import_algorithm, |
581 state->key_length_algorithm, state->extractable, state->usages, | 581 state->key_length_algorithm, state->extractable, state->usages, |
582 &state->derived_key); | 582 &state->derived_key); |
583 state->origin_thread->PostTask( | 583 state->origin_thread->PostTask( |
584 FROM_HERE, base::Bind(DoDeriveKeyReply, Passed(&passed_state))); | 584 FROM_HERE, base::Bind(DoDeriveKeyReply, base::Passed(&passed_state))); |
585 } | 585 } |
586 | 586 |
587 } // namespace | 587 } // namespace |
588 | 588 |
589 WebCryptoImpl::WebCryptoImpl() { | 589 WebCryptoImpl::WebCryptoImpl() { |
590 } | 590 } |
591 | 591 |
592 WebCryptoImpl::~WebCryptoImpl() { | 592 WebCryptoImpl::~WebCryptoImpl() { |
593 } | 593 } |
594 | 594 |
595 void WebCryptoImpl::encrypt(const blink::WebCryptoAlgorithm& algorithm, | 595 void WebCryptoImpl::encrypt(const blink::WebCryptoAlgorithm& algorithm, |
596 const blink::WebCryptoKey& key, | 596 const blink::WebCryptoKey& key, |
597 const unsigned char* data, | 597 const unsigned char* data, |
598 unsigned int data_size, | 598 unsigned int data_size, |
599 blink::WebCryptoResult result) { | 599 blink::WebCryptoResult result) { |
600 DCHECK(!algorithm.isNull()); | 600 DCHECK(!algorithm.isNull()); |
601 | 601 |
602 scoped_ptr<EncryptState> state( | 602 scoped_ptr<EncryptState> state( |
603 new EncryptState(algorithm, key, data, data_size, result)); | 603 new EncryptState(algorithm, key, data, data_size, result)); |
604 if (!CryptoThreadPool::PostTask(FROM_HERE, | 604 if (!CryptoThreadPool::PostTask( |
605 base::Bind(DoEncrypt, Passed(&state)))) { | 605 FROM_HERE, base::Bind(DoEncrypt, base::Passed(&state)))) { |
606 CompleteWithThreadPoolError(&result); | 606 CompleteWithThreadPoolError(&result); |
607 } | 607 } |
608 } | 608 } |
609 | 609 |
610 void WebCryptoImpl::decrypt(const blink::WebCryptoAlgorithm& algorithm, | 610 void WebCryptoImpl::decrypt(const blink::WebCryptoAlgorithm& algorithm, |
611 const blink::WebCryptoKey& key, | 611 const blink::WebCryptoKey& key, |
612 const unsigned char* data, | 612 const unsigned char* data, |
613 unsigned int data_size, | 613 unsigned int data_size, |
614 blink::WebCryptoResult result) { | 614 blink::WebCryptoResult result) { |
615 DCHECK(!algorithm.isNull()); | 615 DCHECK(!algorithm.isNull()); |
616 | 616 |
617 scoped_ptr<DecryptState> state( | 617 scoped_ptr<DecryptState> state( |
618 new DecryptState(algorithm, key, data, data_size, result)); | 618 new DecryptState(algorithm, key, data, data_size, result)); |
619 if (!CryptoThreadPool::PostTask(FROM_HERE, | 619 if (!CryptoThreadPool::PostTask( |
620 base::Bind(DoDecrypt, Passed(&state)))) { | 620 FROM_HERE, base::Bind(DoDecrypt, base::Passed(&state)))) { |
621 CompleteWithThreadPoolError(&result); | 621 CompleteWithThreadPoolError(&result); |
622 } | 622 } |
623 } | 623 } |
624 | 624 |
625 void WebCryptoImpl::digest(const blink::WebCryptoAlgorithm& algorithm, | 625 void WebCryptoImpl::digest(const blink::WebCryptoAlgorithm& algorithm, |
626 const unsigned char* data, | 626 const unsigned char* data, |
627 unsigned int data_size, | 627 unsigned int data_size, |
628 blink::WebCryptoResult result) { | 628 blink::WebCryptoResult result) { |
629 DCHECK(!algorithm.isNull()); | 629 DCHECK(!algorithm.isNull()); |
630 | 630 |
631 scoped_ptr<DigestState> state(new DigestState( | 631 scoped_ptr<DigestState> state(new DigestState( |
632 algorithm, blink::WebCryptoKey::createNull(), data, data_size, result)); | 632 algorithm, blink::WebCryptoKey::createNull(), data, data_size, result)); |
633 if (!CryptoThreadPool::PostTask(FROM_HERE, | 633 if (!CryptoThreadPool::PostTask(FROM_HERE, |
634 base::Bind(DoDigest, Passed(&state)))) { | 634 base::Bind(DoDigest, base::Passed(&state)))) { |
635 CompleteWithThreadPoolError(&result); | 635 CompleteWithThreadPoolError(&result); |
636 } | 636 } |
637 } | 637 } |
638 | 638 |
639 void WebCryptoImpl::generateKey(const blink::WebCryptoAlgorithm& algorithm, | 639 void WebCryptoImpl::generateKey(const blink::WebCryptoAlgorithm& algorithm, |
640 bool extractable, | 640 bool extractable, |
641 blink::WebCryptoKeyUsageMask usages, | 641 blink::WebCryptoKeyUsageMask usages, |
642 blink::WebCryptoResult result) { | 642 blink::WebCryptoResult result) { |
643 DCHECK(!algorithm.isNull()); | 643 DCHECK(!algorithm.isNull()); |
644 | 644 |
645 scoped_ptr<GenerateKeyState> state( | 645 scoped_ptr<GenerateKeyState> state( |
646 new GenerateKeyState(algorithm, extractable, usages, result)); | 646 new GenerateKeyState(algorithm, extractable, usages, result)); |
647 if (!CryptoThreadPool::PostTask(FROM_HERE, | 647 if (!CryptoThreadPool::PostTask( |
648 base::Bind(DoGenerateKey, Passed(&state)))) { | 648 FROM_HERE, base::Bind(DoGenerateKey, base::Passed(&state)))) { |
649 CompleteWithThreadPoolError(&result); | 649 CompleteWithThreadPoolError(&result); |
650 } | 650 } |
651 } | 651 } |
652 | 652 |
653 void WebCryptoImpl::importKey(blink::WebCryptoKeyFormat format, | 653 void WebCryptoImpl::importKey(blink::WebCryptoKeyFormat format, |
654 const unsigned char* key_data, | 654 const unsigned char* key_data, |
655 unsigned int key_data_size, | 655 unsigned int key_data_size, |
656 const blink::WebCryptoAlgorithm& algorithm, | 656 const blink::WebCryptoAlgorithm& algorithm, |
657 bool extractable, | 657 bool extractable, |
658 blink::WebCryptoKeyUsageMask usages, | 658 blink::WebCryptoKeyUsageMask usages, |
659 blink::WebCryptoResult result) { | 659 blink::WebCryptoResult result) { |
660 scoped_ptr<ImportKeyState> state(new ImportKeyState( | 660 scoped_ptr<ImportKeyState> state(new ImportKeyState( |
661 format, key_data, key_data_size, algorithm, extractable, usages, result)); | 661 format, key_data, key_data_size, algorithm, extractable, usages, result)); |
662 if (!CryptoThreadPool::PostTask(FROM_HERE, | 662 if (!CryptoThreadPool::PostTask( |
663 base::Bind(DoImportKey, Passed(&state)))) { | 663 FROM_HERE, base::Bind(DoImportKey, base::Passed(&state)))) { |
664 CompleteWithThreadPoolError(&result); | 664 CompleteWithThreadPoolError(&result); |
665 } | 665 } |
666 } | 666 } |
667 | 667 |
668 void WebCryptoImpl::exportKey(blink::WebCryptoKeyFormat format, | 668 void WebCryptoImpl::exportKey(blink::WebCryptoKeyFormat format, |
669 const blink::WebCryptoKey& key, | 669 const blink::WebCryptoKey& key, |
670 blink::WebCryptoResult result) { | 670 blink::WebCryptoResult result) { |
671 scoped_ptr<ExportKeyState> state(new ExportKeyState(format, key, result)); | 671 scoped_ptr<ExportKeyState> state(new ExportKeyState(format, key, result)); |
672 if (!CryptoThreadPool::PostTask(FROM_HERE, | 672 if (!CryptoThreadPool::PostTask( |
673 base::Bind(DoExportKey, Passed(&state)))) { | 673 FROM_HERE, base::Bind(DoExportKey, base::Passed(&state)))) { |
674 CompleteWithThreadPoolError(&result); | 674 CompleteWithThreadPoolError(&result); |
675 } | 675 } |
676 } | 676 } |
677 | 677 |
678 void WebCryptoImpl::sign(const blink::WebCryptoAlgorithm& algorithm, | 678 void WebCryptoImpl::sign(const blink::WebCryptoAlgorithm& algorithm, |
679 const blink::WebCryptoKey& key, | 679 const blink::WebCryptoKey& key, |
680 const unsigned char* data, | 680 const unsigned char* data, |
681 unsigned int data_size, | 681 unsigned int data_size, |
682 blink::WebCryptoResult result) { | 682 blink::WebCryptoResult result) { |
683 scoped_ptr<SignState> state( | 683 scoped_ptr<SignState> state( |
684 new SignState(algorithm, key, data, data_size, result)); | 684 new SignState(algorithm, key, data, data_size, result)); |
685 if (!CryptoThreadPool::PostTask(FROM_HERE, | 685 if (!CryptoThreadPool::PostTask(FROM_HERE, |
686 base::Bind(DoSign, Passed(&state)))) { | 686 base::Bind(DoSign, base::Passed(&state)))) { |
687 CompleteWithThreadPoolError(&result); | 687 CompleteWithThreadPoolError(&result); |
688 } | 688 } |
689 } | 689 } |
690 | 690 |
691 void WebCryptoImpl::verifySignature(const blink::WebCryptoAlgorithm& algorithm, | 691 void WebCryptoImpl::verifySignature(const blink::WebCryptoAlgorithm& algorithm, |
692 const blink::WebCryptoKey& key, | 692 const blink::WebCryptoKey& key, |
693 const unsigned char* signature, | 693 const unsigned char* signature, |
694 unsigned int signature_size, | 694 unsigned int signature_size, |
695 const unsigned char* data, | 695 const unsigned char* data, |
696 unsigned int data_size, | 696 unsigned int data_size, |
697 blink::WebCryptoResult result) { | 697 blink::WebCryptoResult result) { |
698 scoped_ptr<VerifySignatureState> state(new VerifySignatureState( | 698 scoped_ptr<VerifySignatureState> state(new VerifySignatureState( |
699 algorithm, key, signature, signature_size, data, data_size, result)); | 699 algorithm, key, signature, signature_size, data, data_size, result)); |
700 if (!CryptoThreadPool::PostTask(FROM_HERE, | 700 if (!CryptoThreadPool::PostTask(FROM_HERE, |
701 base::Bind(DoVerify, Passed(&state)))) { | 701 base::Bind(DoVerify, base::Passed(&state)))) { |
702 CompleteWithThreadPoolError(&result); | 702 CompleteWithThreadPoolError(&result); |
703 } | 703 } |
704 } | 704 } |
705 | 705 |
706 void WebCryptoImpl::wrapKey(blink::WebCryptoKeyFormat format, | 706 void WebCryptoImpl::wrapKey(blink::WebCryptoKeyFormat format, |
707 const blink::WebCryptoKey& key, | 707 const blink::WebCryptoKey& key, |
708 const blink::WebCryptoKey& wrapping_key, | 708 const blink::WebCryptoKey& wrapping_key, |
709 const blink::WebCryptoAlgorithm& wrap_algorithm, | 709 const blink::WebCryptoAlgorithm& wrap_algorithm, |
710 blink::WebCryptoResult result) { | 710 blink::WebCryptoResult result) { |
711 scoped_ptr<WrapKeyState> state( | 711 scoped_ptr<WrapKeyState> state( |
712 new WrapKeyState(format, key, wrapping_key, wrap_algorithm, result)); | 712 new WrapKeyState(format, key, wrapping_key, wrap_algorithm, result)); |
713 if (!CryptoThreadPool::PostTask(FROM_HERE, | 713 if (!CryptoThreadPool::PostTask( |
714 base::Bind(DoWrapKey, Passed(&state)))) { | 714 FROM_HERE, base::Bind(DoWrapKey, base::Passed(&state)))) { |
715 CompleteWithThreadPoolError(&result); | 715 CompleteWithThreadPoolError(&result); |
716 } | 716 } |
717 } | 717 } |
718 | 718 |
719 void WebCryptoImpl::unwrapKey( | 719 void WebCryptoImpl::unwrapKey( |
720 blink::WebCryptoKeyFormat format, | 720 blink::WebCryptoKeyFormat format, |
721 const unsigned char* wrapped_key, | 721 const unsigned char* wrapped_key, |
722 unsigned wrapped_key_size, | 722 unsigned wrapped_key_size, |
723 const blink::WebCryptoKey& wrapping_key, | 723 const blink::WebCryptoKey& wrapping_key, |
724 const blink::WebCryptoAlgorithm& unwrap_algorithm, | 724 const blink::WebCryptoAlgorithm& unwrap_algorithm, |
725 const blink::WebCryptoAlgorithm& unwrapped_key_algorithm, | 725 const blink::WebCryptoAlgorithm& unwrapped_key_algorithm, |
726 bool extractable, | 726 bool extractable, |
727 blink::WebCryptoKeyUsageMask usages, | 727 blink::WebCryptoKeyUsageMask usages, |
728 blink::WebCryptoResult result) { | 728 blink::WebCryptoResult result) { |
729 scoped_ptr<UnwrapKeyState> state(new UnwrapKeyState( | 729 scoped_ptr<UnwrapKeyState> state(new UnwrapKeyState( |
730 format, wrapped_key, wrapped_key_size, wrapping_key, unwrap_algorithm, | 730 format, wrapped_key, wrapped_key_size, wrapping_key, unwrap_algorithm, |
731 unwrapped_key_algorithm, extractable, usages, result)); | 731 unwrapped_key_algorithm, extractable, usages, result)); |
732 if (!CryptoThreadPool::PostTask(FROM_HERE, | 732 if (!CryptoThreadPool::PostTask( |
733 base::Bind(DoUnwrapKey, Passed(&state)))) { | 733 FROM_HERE, base::Bind(DoUnwrapKey, base::Passed(&state)))) { |
734 CompleteWithThreadPoolError(&result); | 734 CompleteWithThreadPoolError(&result); |
735 } | 735 } |
736 } | 736 } |
737 | 737 |
738 void WebCryptoImpl::deriveBits(const blink::WebCryptoAlgorithm& algorithm, | 738 void WebCryptoImpl::deriveBits(const blink::WebCryptoAlgorithm& algorithm, |
739 const blink::WebCryptoKey& base_key, | 739 const blink::WebCryptoKey& base_key, |
740 unsigned int length_bits, | 740 unsigned int length_bits, |
741 blink::WebCryptoResult result) { | 741 blink::WebCryptoResult result) { |
742 scoped_ptr<DeriveBitsState> state( | 742 scoped_ptr<DeriveBitsState> state( |
743 new DeriveBitsState(algorithm, base_key, length_bits, result)); | 743 new DeriveBitsState(algorithm, base_key, length_bits, result)); |
744 if (!CryptoThreadPool::PostTask(FROM_HERE, | 744 if (!CryptoThreadPool::PostTask( |
745 base::Bind(DoDeriveBits, Passed(&state)))) { | 745 FROM_HERE, base::Bind(DoDeriveBits, base::Passed(&state)))) { |
746 CompleteWithThreadPoolError(&result); | 746 CompleteWithThreadPoolError(&result); |
747 } | 747 } |
748 } | 748 } |
749 | 749 |
750 void WebCryptoImpl::deriveKey( | 750 void WebCryptoImpl::deriveKey( |
751 const blink::WebCryptoAlgorithm& algorithm, | 751 const blink::WebCryptoAlgorithm& algorithm, |
752 const blink::WebCryptoKey& base_key, | 752 const blink::WebCryptoKey& base_key, |
753 const blink::WebCryptoAlgorithm& import_algorithm, | 753 const blink::WebCryptoAlgorithm& import_algorithm, |
754 const blink::WebCryptoAlgorithm& key_length_algorithm, | 754 const blink::WebCryptoAlgorithm& key_length_algorithm, |
755 bool extractable, | 755 bool extractable, |
756 blink::WebCryptoKeyUsageMask usages, | 756 blink::WebCryptoKeyUsageMask usages, |
757 blink::WebCryptoResult result) { | 757 blink::WebCryptoResult result) { |
758 scoped_ptr<DeriveKeyState> state( | 758 scoped_ptr<DeriveKeyState> state( |
759 new DeriveKeyState(algorithm, base_key, import_algorithm, | 759 new DeriveKeyState(algorithm, base_key, import_algorithm, |
760 key_length_algorithm, extractable, usages, result)); | 760 key_length_algorithm, extractable, usages, result)); |
761 if (!CryptoThreadPool::PostTask(FROM_HERE, | 761 if (!CryptoThreadPool::PostTask( |
762 base::Bind(DoDeriveKey, Passed(&state)))) { | 762 FROM_HERE, base::Bind(DoDeriveKey, base::Passed(&state)))) { |
763 CompleteWithThreadPoolError(&result); | 763 CompleteWithThreadPoolError(&result); |
764 } | 764 } |
765 } | 765 } |
766 | 766 |
767 blink::WebCryptoDigestor* WebCryptoImpl::createDigestor( | 767 blink::WebCryptoDigestor* WebCryptoImpl::createDigestor( |
768 blink::WebCryptoAlgorithmId algorithm_id) { | 768 blink::WebCryptoAlgorithmId algorithm_id) { |
769 return webcrypto::CreateDigestor(algorithm_id).release(); | 769 return webcrypto::CreateDigestor(algorithm_id).release(); |
770 } | 770 } |
771 | 771 |
772 bool WebCryptoImpl::deserializeKeyForClone( | 772 bool WebCryptoImpl::deserializeKeyForClone( |
773 const blink::WebCryptoKeyAlgorithm& algorithm, | 773 const blink::WebCryptoKeyAlgorithm& algorithm, |
774 blink::WebCryptoKeyType type, | 774 blink::WebCryptoKeyType type, |
775 bool extractable, | 775 bool extractable, |
776 blink::WebCryptoKeyUsageMask usages, | 776 blink::WebCryptoKeyUsageMask usages, |
777 const unsigned char* key_data, | 777 const unsigned char* key_data, |
778 unsigned key_data_size, | 778 unsigned key_data_size, |
779 blink::WebCryptoKey& key) { | 779 blink::WebCryptoKey& key) { |
780 return webcrypto::DeserializeKeyForClone( | 780 return webcrypto::DeserializeKeyForClone( |
781 algorithm, type, extractable, usages, | 781 algorithm, type, extractable, usages, |
782 webcrypto::CryptoData(key_data, key_data_size), &key); | 782 webcrypto::CryptoData(key_data, key_data_size), &key); |
783 } | 783 } |
784 | 784 |
785 bool WebCryptoImpl::serializeKeyForClone( | 785 bool WebCryptoImpl::serializeKeyForClone( |
786 const blink::WebCryptoKey& key, | 786 const blink::WebCryptoKey& key, |
787 blink::WebVector<unsigned char>& key_data) { | 787 blink::WebVector<unsigned char>& key_data) { |
788 return webcrypto::SerializeKeyForClone(key, &key_data); | 788 return webcrypto::SerializeKeyForClone(key, &key_data); |
789 } | 789 } |
790 | 790 |
791 } // namespace webcrypto | 791 } // namespace webcrypto |
OLD | NEW |