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

Side by Side Diff: third_party/WebKit/Source/modules/crypto/NormalizeAlgorithm.cpp

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 22 matching lines...) Expand all
33 #include "bindings/core/v8/ArrayBufferOrArrayBufferView.h" 33 #include "bindings/core/v8/ArrayBufferOrArrayBufferView.h"
34 #include "bindings/core/v8/Dictionary.h" 34 #include "bindings/core/v8/Dictionary.h"
35 #include "bindings/core/v8/V8ArrayBuffer.h" 35 #include "bindings/core/v8/V8ArrayBuffer.h"
36 #include "bindings/core/v8/V8ArrayBufferView.h" 36 #include "bindings/core/v8/V8ArrayBufferView.h"
37 #include "bindings/modules/v8/V8CryptoKey.h" 37 #include "bindings/modules/v8/V8CryptoKey.h"
38 #include "core/dom/DOMArrayPiece.h" 38 #include "core/dom/DOMArrayPiece.h"
39 #include "core/dom/DOMTypedArray.h" 39 #include "core/dom/DOMTypedArray.h"
40 #include "public/platform/WebCryptoAlgorithmParams.h" 40 #include "public/platform/WebCryptoAlgorithmParams.h"
41 #include "public/platform/WebString.h" 41 #include "public/platform/WebString.h"
42 #include "wtf/MathExtras.h" 42 #include "wtf/MathExtras.h"
43 #include "wtf/PtrUtil.h"
44 #include "wtf/Vector.h" 43 #include "wtf/Vector.h"
45 #include "wtf/text/StringBuilder.h" 44 #include "wtf/text/StringBuilder.h"
46 #include <algorithm> 45 #include <algorithm>
47 #include <memory>
48 46
49 namespace blink { 47 namespace blink {
50 48
51 namespace { 49 namespace {
52 50
53 typedef ArrayBufferOrArrayBufferView BufferSource; 51 typedef ArrayBufferOrArrayBufferView BufferSource;
54 52
55 struct AlgorithmNameMapping { 53 struct AlgorithmNameMapping {
56 // Must be an upper case ASCII string. 54 // Must be an upper case ASCII string.
57 const char* const algorithmName; 55 const char* const algorithmName;
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 440
443 value.setString(algorithmName); 441 value.setString(algorithmName);
444 return true; 442 return true;
445 } 443 }
446 444
447 // Defined by the WebCrypto spec as: 445 // Defined by the WebCrypto spec as:
448 // 446 //
449 // dictionary AesCbcParams : Algorithm { 447 // dictionary AesCbcParams : Algorithm {
450 // required BufferSource iv; 448 // required BufferSource iv;
451 // }; 449 // };
452 bool parseAesCbcParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithm Params>& params, const ErrorContext& context, AlgorithmError* error) 450 bool parseAesCbcParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
453 { 451 {
454 BufferSource ivBufferSource; 452 BufferSource ivBufferSource;
455 if (!getBufferSource(raw, "iv", ivBufferSource, context, error)) 453 if (!getBufferSource(raw, "iv", ivBufferSource, context, error))
456 return false; 454 return false;
457 455
458 DOMArrayPiece iv(ivBufferSource); 456 DOMArrayPiece iv(ivBufferSource);
459 457
460 params = wrapUnique(new WebCryptoAesCbcParams(iv.bytes(), iv.byteLength())); 458 params = adoptPtr(new WebCryptoAesCbcParams(iv.bytes(), iv.byteLength()));
461 return true; 459 return true;
462 } 460 }
463 461
464 // Defined by the WebCrypto spec as: 462 // Defined by the WebCrypto spec as:
465 // 463 //
466 // dictionary AesKeyGenParams : Algorithm { 464 // dictionary AesKeyGenParams : Algorithm {
467 // [EnforceRange] required unsigned short length; 465 // [EnforceRange] required unsigned short length;
468 // }; 466 // };
469 bool parseAesKeyGenParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgori thmParams>& params, const ErrorContext& context, AlgorithmError* error) 467 bool parseAesKeyGenParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams >& params, const ErrorContext& context, AlgorithmError* error)
470 { 468 {
471 uint16_t length; 469 uint16_t length;
472 if (!getUint16(raw, "length", length, context, error)) 470 if (!getUint16(raw, "length", length, context, error))
473 return false; 471 return false;
474 472
475 params = wrapUnique(new WebCryptoAesKeyGenParams(length)); 473 params = adoptPtr(new WebCryptoAesKeyGenParams(length));
476 return true; 474 return true;
477 } 475 }
478 476
479 bool parseAlgorithmIdentifier(const AlgorithmIdentifier&, WebCryptoOperation, We bCryptoAlgorithm&, ErrorContext, AlgorithmError*); 477 bool parseAlgorithmIdentifier(const AlgorithmIdentifier&, WebCryptoOperation, We bCryptoAlgorithm&, ErrorContext, AlgorithmError*);
480 478
481 bool parseHash(const Dictionary& raw, WebCryptoAlgorithm& hash, ErrorContext con text, AlgorithmError* error) 479 bool parseHash(const Dictionary& raw, WebCryptoAlgorithm& hash, ErrorContext con text, AlgorithmError* error)
482 { 480 {
483 AlgorithmIdentifier rawHash; 481 AlgorithmIdentifier rawHash;
484 if (!getAlgorithmIdentifier(raw, "hash", rawHash, context, error)) 482 if (!getAlgorithmIdentifier(raw, "hash", rawHash, context, error))
485 return false; 483 return false;
486 484
487 context.add("hash"); 485 context.add("hash");
488 return parseAlgorithmIdentifier(rawHash, WebCryptoOperationDigest, hash, con text, error); 486 return parseAlgorithmIdentifier(rawHash, WebCryptoOperationDigest, hash, con text, error);
489 } 487 }
490 488
491 // Defined by the WebCrypto spec as: 489 // Defined by the WebCrypto spec as:
492 // 490 //
493 // dictionary HmacImportParams : Algorithm { 491 // dictionary HmacImportParams : Algorithm {
494 // HashAlgorithmIdentifier hash; 492 // HashAlgorithmIdentifier hash;
495 // [EnforceRange] unsigned long length; 493 // [EnforceRange] unsigned long length;
496 // }; 494 // };
497 // 495 //
498 // FIXME: http://crbug.com/438475: The current implementation differs from the 496 // FIXME: http://crbug.com/438475: The current implementation differs from the
499 // spec in that the "hash" parameter is required. This seems more sensible, and 497 // spec in that the "hash" parameter is required. This seems more sensible, and
500 // is being proposed as a change to the spec. (https://www.w3.org/Bugs/Public/sh ow_bug.cgi?id=27448). 498 // is being proposed as a change to the spec. (https://www.w3.org/Bugs/Public/sh ow_bug.cgi?id=27448).
501 bool parseHmacImportParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgor ithmParams>& params, const ErrorContext& context, AlgorithmError* error) 499 bool parseHmacImportParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParam s>& params, const ErrorContext& context, AlgorithmError* error)
502 { 500 {
503 WebCryptoAlgorithm hash; 501 WebCryptoAlgorithm hash;
504 if (!parseHash(raw, hash, context, error)) 502 if (!parseHash(raw, hash, context, error))
505 return false; 503 return false;
506 504
507 bool hasLength; 505 bool hasLength;
508 uint32_t length = 0; 506 uint32_t length = 0;
509 if (!getOptionalUint32(raw, "length", hasLength, length, context, error)) 507 if (!getOptionalUint32(raw, "length", hasLength, length, context, error))
510 return false; 508 return false;
511 509
512 params = wrapUnique(new WebCryptoHmacImportParams(hash, hasLength, length)); 510 params = adoptPtr(new WebCryptoHmacImportParams(hash, hasLength, length));
513 return true; 511 return true;
514 } 512 }
515 513
516 // Defined by the WebCrypto spec as: 514 // Defined by the WebCrypto spec as:
517 // 515 //
518 // dictionary HmacKeyGenParams : Algorithm { 516 // dictionary HmacKeyGenParams : Algorithm {
519 // required HashAlgorithmIdentifier hash; 517 // required HashAlgorithmIdentifier hash;
520 // [EnforceRange] unsigned long length; 518 // [EnforceRange] unsigned long length;
521 // }; 519 // };
522 bool parseHmacKeyGenParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgor ithmParams>& params, const ErrorContext& context, AlgorithmError* error) 520 bool parseHmacKeyGenParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParam s>& params, const ErrorContext& context, AlgorithmError* error)
523 { 521 {
524 WebCryptoAlgorithm hash; 522 WebCryptoAlgorithm hash;
525 if (!parseHash(raw, hash, context, error)) 523 if (!parseHash(raw, hash, context, error))
526 return false; 524 return false;
527 525
528 bool hasLength; 526 bool hasLength;
529 uint32_t length = 0; 527 uint32_t length = 0;
530 if (!getOptionalUint32(raw, "length", hasLength, length, context, error)) 528 if (!getOptionalUint32(raw, "length", hasLength, length, context, error))
531 return false; 529 return false;
532 530
533 params = wrapUnique(new WebCryptoHmacKeyGenParams(hash, hasLength, length)); 531 params = adoptPtr(new WebCryptoHmacKeyGenParams(hash, hasLength, length));
534 return true; 532 return true;
535 } 533 }
536 534
537 // Defined by the WebCrypto spec as: 535 // Defined by the WebCrypto spec as:
538 // 536 //
539 // dictionary RsaHashedImportParams : Algorithm { 537 // dictionary RsaHashedImportParams : Algorithm {
540 // required HashAlgorithmIdentifier hash; 538 // required HashAlgorithmIdentifier hash;
541 // }; 539 // };
542 bool parseRsaHashedImportParams(const Dictionary& raw, std::unique_ptr<WebCrypto AlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error) 540 bool parseRsaHashedImportParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithm Params>& params, const ErrorContext& context, AlgorithmError* error)
543 { 541 {
544 WebCryptoAlgorithm hash; 542 WebCryptoAlgorithm hash;
545 if (!parseHash(raw, hash, context, error)) 543 if (!parseHash(raw, hash, context, error))
546 return false; 544 return false;
547 545
548 params = wrapUnique(new WebCryptoRsaHashedImportParams(hash)); 546 params = adoptPtr(new WebCryptoRsaHashedImportParams(hash));
549 return true; 547 return true;
550 } 548 }
551 549
552 // Defined by the WebCrypto spec as: 550 // Defined by the WebCrypto spec as:
553 // 551 //
554 // dictionary RsaKeyGenParams : Algorithm { 552 // dictionary RsaKeyGenParams : Algorithm {
555 // [EnforceRange] required unsigned long modulusLength; 553 // [EnforceRange] required unsigned long modulusLength;
556 // required BigInteger publicExponent; 554 // required BigInteger publicExponent;
557 // }; 555 // };
558 // 556 //
559 // dictionary RsaHashedKeyGenParams : RsaKeyGenParams { 557 // dictionary RsaHashedKeyGenParams : RsaKeyGenParams {
560 // required HashAlgorithmIdentifier hash; 558 // required HashAlgorithmIdentifier hash;
561 // }; 559 // };
562 bool parseRsaHashedKeyGenParams(const Dictionary& raw, std::unique_ptr<WebCrypto AlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error) 560 bool parseRsaHashedKeyGenParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithm Params>& params, const ErrorContext& context, AlgorithmError* error)
563 { 561 {
564 uint32_t modulusLength; 562 uint32_t modulusLength;
565 if (!getUint32(raw, "modulusLength", modulusLength, context, error)) 563 if (!getUint32(raw, "modulusLength", modulusLength, context, error))
566 return false; 564 return false;
567 565
568 DOMUint8Array* publicExponent = nullptr; 566 DOMUint8Array* publicExponent = nullptr;
569 if (!getBigInteger(raw, "publicExponent", publicExponent, context, error)) 567 if (!getBigInteger(raw, "publicExponent", publicExponent, context, error))
570 return false; 568 return false;
571 569
572 WebCryptoAlgorithm hash; 570 WebCryptoAlgorithm hash;
573 if (!parseHash(raw, hash, context, error)) 571 if (!parseHash(raw, hash, context, error))
574 return false; 572 return false;
575 573
576 params = wrapUnique(new WebCryptoRsaHashedKeyGenParams(hash, modulusLength, static_cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent ->byteLength())); 574 params = adoptPtr(new WebCryptoRsaHashedKeyGenParams(hash, modulusLength, st atic_cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent-> byteLength()));
577 return true; 575 return true;
578 } 576 }
579 577
580 // Defined by the WebCrypto spec as: 578 // Defined by the WebCrypto spec as:
581 // 579 //
582 // dictionary AesCtrParams : Algorithm { 580 // dictionary AesCtrParams : Algorithm {
583 // required BufferSource counter; 581 // required BufferSource counter;
584 // [EnforceRange] required octet length; 582 // [EnforceRange] required octet length;
585 // }; 583 // };
586 bool parseAesCtrParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithm Params>& params, const ErrorContext& context, AlgorithmError* error) 584 bool parseAesCtrParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
587 { 585 {
588 BufferSource counterBufferSource; 586 BufferSource counterBufferSource;
589 if (!getBufferSource(raw, "counter", counterBufferSource, context, error)) 587 if (!getBufferSource(raw, "counter", counterBufferSource, context, error))
590 return false; 588 return false;
591 589
592 DOMArrayPiece counter(counterBufferSource); 590 DOMArrayPiece counter(counterBufferSource);
593 uint8_t length; 591 uint8_t length;
594 if (!getUint8(raw, "length", length, context, error)) 592 if (!getUint8(raw, "length", length, context, error))
595 return false; 593 return false;
596 594
597 params = wrapUnique(new WebCryptoAesCtrParams(length, counter.bytes(), count er.byteLength())); 595 params = adoptPtr(new WebCryptoAesCtrParams(length, counter.bytes(), counter .byteLength()));
598 return true; 596 return true;
599 } 597 }
600 598
601 // Defined by the WebCrypto spec as: 599 // Defined by the WebCrypto spec as:
602 // 600 //
603 // dictionary AesGcmParams : Algorithm { 601 // dictionary AesGcmParams : Algorithm {
604 // required BufferSource iv; 602 // required BufferSource iv;
605 // BufferSource additionalData; 603 // BufferSource additionalData;
606 // [EnforceRange] octet tagLength; 604 // [EnforceRange] octet tagLength;
607 // } 605 // }
608 bool parseAesGcmParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithm Params>& params, const ErrorContext& context, AlgorithmError* error) 606 bool parseAesGcmParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
609 { 607 {
610 BufferSource ivBufferSource; 608 BufferSource ivBufferSource;
611 if (!getBufferSource(raw, "iv", ivBufferSource, context, error)) 609 if (!getBufferSource(raw, "iv", ivBufferSource, context, error))
612 return false; 610 return false;
613 611
614 bool hasAdditionalData; 612 bool hasAdditionalData;
615 BufferSource additionalDataBufferSource; 613 BufferSource additionalDataBufferSource;
616 if (!getOptionalBufferSource(raw, "additionalData", hasAdditionalData, addit ionalDataBufferSource, context, error)) 614 if (!getOptionalBufferSource(raw, "additionalData", hasAdditionalData, addit ionalDataBufferSource, context, error))
617 return false; 615 return false;
618 616
619 uint8_t tagLength = 0; 617 uint8_t tagLength = 0;
620 bool hasTagLength; 618 bool hasTagLength;
621 if (!getOptionalUint8(raw, "tagLength", hasTagLength, tagLength, context, er ror)) 619 if (!getOptionalUint8(raw, "tagLength", hasTagLength, tagLength, context, er ror))
622 return false; 620 return false;
623 621
624 DOMArrayPiece iv(ivBufferSource); 622 DOMArrayPiece iv(ivBufferSource);
625 DOMArrayPiece additionalData(additionalDataBufferSource, DOMArrayPiece::Allo wNullPointToNullWithZeroSize); 623 DOMArrayPiece additionalData(additionalDataBufferSource, DOMArrayPiece::Allo wNullPointToNullWithZeroSize);
626 624
627 params = wrapUnique(new WebCryptoAesGcmParams(iv.bytes(), iv.byteLength(), h asAdditionalData, additionalData.bytes(), additionalData.byteLength(), hasTagLen gth, tagLength)); 625 params = adoptPtr(new WebCryptoAesGcmParams(iv.bytes(), iv.byteLength(), has AdditionalData, additionalData.bytes(), additionalData.byteLength(), hasTagLengt h, tagLength));
628 return true; 626 return true;
629 } 627 }
630 628
631 // Defined by the WebCrypto spec as: 629 // Defined by the WebCrypto spec as:
632 // 630 //
633 // dictionary RsaOaepParams : Algorithm { 631 // dictionary RsaOaepParams : Algorithm {
634 // BufferSource label; 632 // BufferSource label;
635 // }; 633 // };
636 bool parseRsaOaepParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorith mParams>& params, const ErrorContext& context, AlgorithmError* error) 634 bool parseRsaOaepParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
637 { 635 {
638 bool hasLabel; 636 bool hasLabel;
639 BufferSource labelBufferSource; 637 BufferSource labelBufferSource;
640 if (!getOptionalBufferSource(raw, "label", hasLabel, labelBufferSource, cont ext, error)) 638 if (!getOptionalBufferSource(raw, "label", hasLabel, labelBufferSource, cont ext, error))
641 return false; 639 return false;
642 640
643 DOMArrayPiece label(labelBufferSource, DOMArrayPiece::AllowNullPointToNullWi thZeroSize); 641 DOMArrayPiece label(labelBufferSource, DOMArrayPiece::AllowNullPointToNullWi thZeroSize);
644 params = wrapUnique(new WebCryptoRsaOaepParams(hasLabel, label.bytes(), labe l.byteLength())); 642 params = adoptPtr(new WebCryptoRsaOaepParams(hasLabel, label.bytes(), label. byteLength()));
645 return true; 643 return true;
646 } 644 }
647 645
648 // Defined by the WebCrypto spec as: 646 // Defined by the WebCrypto spec as:
649 // 647 //
650 // dictionary RsaPssParams : Algorithm { 648 // dictionary RsaPssParams : Algorithm {
651 // [EnforceRange] required unsigned long saltLength; 649 // [EnforceRange] required unsigned long saltLength;
652 // }; 650 // };
653 bool parseRsaPssParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithm Params>& params, const ErrorContext& context, AlgorithmError* error) 651 bool parseRsaPssParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
654 { 652 {
655 uint32_t saltLengthBytes; 653 uint32_t saltLengthBytes;
656 if (!getUint32(raw, "saltLength", saltLengthBytes, context, error)) 654 if (!getUint32(raw, "saltLength", saltLengthBytes, context, error))
657 return false; 655 return false;
658 656
659 params = wrapUnique(new WebCryptoRsaPssParams(saltLengthBytes)); 657 params = adoptPtr(new WebCryptoRsaPssParams(saltLengthBytes));
660 return true; 658 return true;
661 } 659 }
662 660
663 // Defined by the WebCrypto spec as: 661 // Defined by the WebCrypto spec as:
664 // 662 //
665 // dictionary EcdsaParams : Algorithm { 663 // dictionary EcdsaParams : Algorithm {
666 // required HashAlgorithmIdentifier hash; 664 // required HashAlgorithmIdentifier hash;
667 // }; 665 // };
668 bool parseEcdsaParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmP arams>& params, const ErrorContext& context, AlgorithmError* error) 666 bool parseEcdsaParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& p arams, const ErrorContext& context, AlgorithmError* error)
669 { 667 {
670 WebCryptoAlgorithm hash; 668 WebCryptoAlgorithm hash;
671 if (!parseHash(raw, hash, context, error)) 669 if (!parseHash(raw, hash, context, error))
672 return false; 670 return false;
673 671
674 params = wrapUnique(new WebCryptoEcdsaParams(hash)); 672 params = adoptPtr(new WebCryptoEcdsaParams(hash));
675 return true; 673 return true;
676 } 674 }
677 675
678 struct CurveNameMapping { 676 struct CurveNameMapping {
679 const char* const name; 677 const char* const name;
680 WebCryptoNamedCurve value; 678 WebCryptoNamedCurve value;
681 }; 679 };
682 680
683 const CurveNameMapping curveNameMappings[] = { 681 const CurveNameMapping curveNameMappings[] = {
684 { "P-256", WebCryptoNamedCurveP256 }, 682 { "P-256", WebCryptoNamedCurveP256 },
(...skipping 21 matching lines...) Expand all
706 704
707 setNotSupportedError(context.toString("Unrecognized namedCurve"), error); 705 setNotSupportedError(context.toString("Unrecognized namedCurve"), error);
708 return false; 706 return false;
709 } 707 }
710 708
711 // Defined by the WebCrypto spec as: 709 // Defined by the WebCrypto spec as:
712 // 710 //
713 // dictionary EcKeyGenParams : Algorithm { 711 // dictionary EcKeyGenParams : Algorithm {
714 // required NamedCurve namedCurve; 712 // required NamedCurve namedCurve;
715 // }; 713 // };
716 bool parseEcKeyGenParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorit hmParams>& params, const ErrorContext& context, AlgorithmError* error) 714 bool parseEcKeyGenParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams> & params, const ErrorContext& context, AlgorithmError* error)
717 { 715 {
718 WebCryptoNamedCurve namedCurve; 716 WebCryptoNamedCurve namedCurve;
719 if (!parseNamedCurve(raw, namedCurve, context, error)) 717 if (!parseNamedCurve(raw, namedCurve, context, error))
720 return false; 718 return false;
721 719
722 params = wrapUnique(new WebCryptoEcKeyGenParams(namedCurve)); 720 params = adoptPtr(new WebCryptoEcKeyGenParams(namedCurve));
723 return true; 721 return true;
724 } 722 }
725 723
726 // Defined by the WebCrypto spec as: 724 // Defined by the WebCrypto spec as:
727 // 725 //
728 // dictionary EcKeyImportParams : Algorithm { 726 // dictionary EcKeyImportParams : Algorithm {
729 // required NamedCurve namedCurve; 727 // required NamedCurve namedCurve;
730 // }; 728 // };
731 bool parseEcKeyImportParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgo rithmParams>& params, const ErrorContext& context, AlgorithmError* error) 729 bool parseEcKeyImportParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmPara ms>& params, const ErrorContext& context, AlgorithmError* error)
732 { 730 {
733 WebCryptoNamedCurve namedCurve; 731 WebCryptoNamedCurve namedCurve;
734 if (!parseNamedCurve(raw, namedCurve, context, error)) 732 if (!parseNamedCurve(raw, namedCurve, context, error))
735 return false; 733 return false;
736 734
737 params = wrapUnique(new WebCryptoEcKeyImportParams(namedCurve)); 735 params = adoptPtr(new WebCryptoEcKeyImportParams(namedCurve));
738 return true; 736 return true;
739 } 737 }
740 738
741 // Defined by the WebCrypto spec as: 739 // Defined by the WebCrypto spec as:
742 // 740 //
743 // dictionary EcdhKeyDeriveParams : Algorithm { 741 // dictionary EcdhKeyDeriveParams : Algorithm {
744 // required CryptoKey public; 742 // required CryptoKey public;
745 // }; 743 // };
746 bool parseEcdhKeyDeriveParams(const Dictionary& raw, std::unique_ptr<WebCryptoAl gorithmParams>& params, const ErrorContext& context, AlgorithmError* error) 744 bool parseEcdhKeyDeriveParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmPa rams>& params, const ErrorContext& context, AlgorithmError* error)
747 { 745 {
748 v8::Local<v8::Value> v8Value; 746 v8::Local<v8::Value> v8Value;
749 if (!raw.get("public", v8Value)) { 747 if (!raw.get("public", v8Value)) {
750 setTypeError(context.toString("public", "Missing required property"), er ror); 748 setTypeError(context.toString("public", "Missing required property"), er ror);
751 return false; 749 return false;
752 } 750 }
753 751
754 CryptoKey* cryptoKey = V8CryptoKey::toImplWithTypeCheck(raw.isolate(), v8Val ue); 752 CryptoKey* cryptoKey = V8CryptoKey::toImplWithTypeCheck(raw.isolate(), v8Val ue);
755 if (!cryptoKey) { 753 if (!cryptoKey) {
756 setTypeError(context.toString("public", "Must be a CryptoKey"), error); 754 setTypeError(context.toString("public", "Must be a CryptoKey"), error);
757 return false; 755 return false;
758 } 756 }
759 757
760 params = wrapUnique(new WebCryptoEcdhKeyDeriveParams(cryptoKey->key())); 758 params = adoptPtr(new WebCryptoEcdhKeyDeriveParams(cryptoKey->key()));
761 return true; 759 return true;
762 } 760 }
763 761
764 // Defined by the WebCrypto spec as: 762 // Defined by the WebCrypto spec as:
765 // 763 //
766 // dictionary Pbkdf2Params : Algorithm { 764 // dictionary Pbkdf2Params : Algorithm {
767 // required BufferSource salt; 765 // required BufferSource salt;
768 // [EnforceRange] required unsigned long iterations; 766 // [EnforceRange] required unsigned long iterations;
769 // required HashAlgorithmIdentifier hash; 767 // required HashAlgorithmIdentifier hash;
770 // }; 768 // };
771 bool parsePbkdf2Params(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithm Params>& params, const ErrorContext& context, AlgorithmError* error) 769 bool parsePbkdf2Params(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
772 { 770 {
773 BufferSource saltBufferSource; 771 BufferSource saltBufferSource;
774 if (!getBufferSource(raw, "salt", saltBufferSource, context, error)) 772 if (!getBufferSource(raw, "salt", saltBufferSource, context, error))
775 return false; 773 return false;
776 774
777 DOMArrayPiece salt(saltBufferSource); 775 DOMArrayPiece salt(saltBufferSource);
778 776
779 uint32_t iterations; 777 uint32_t iterations;
780 if (!getUint32(raw, "iterations", iterations, context, error)) 778 if (!getUint32(raw, "iterations", iterations, context, error))
781 return false; 779 return false;
782 780
783 WebCryptoAlgorithm hash; 781 WebCryptoAlgorithm hash;
784 if (!parseHash(raw, hash, context, error)) 782 if (!parseHash(raw, hash, context, error))
785 return false; 783 return false;
786 params = wrapUnique(new WebCryptoPbkdf2Params(hash, salt.bytes(), salt.byteL ength(), iterations)); 784 params = adoptPtr(new WebCryptoPbkdf2Params(hash, salt.bytes(), salt.byteLen gth(), iterations));
787 return true; 785 return true;
788 } 786 }
789 787
790 // Defined by the WebCrypto spec as: 788 // Defined by the WebCrypto spec as:
791 // 789 //
792 // dictionary AesDerivedKeyParams : Algorithm { 790 // dictionary AesDerivedKeyParams : Algorithm {
793 // [EnforceRange] required unsigned short length; 791 // [EnforceRange] required unsigned short length;
794 // }; 792 // };
795 bool parseAesDerivedKeyParams(const Dictionary& raw, std::unique_ptr<WebCryptoAl gorithmParams>& params, const ErrorContext& context, AlgorithmError* error) 793 bool parseAesDerivedKeyParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmPa rams>& params, const ErrorContext& context, AlgorithmError* error)
796 { 794 {
797 uint16_t length; 795 uint16_t length;
798 if (!getUint16(raw, "length", length, context, error)) 796 if (!getUint16(raw, "length", length, context, error))
799 return false; 797 return false;
800 798
801 params = wrapUnique(new WebCryptoAesDerivedKeyParams(length)); 799 params = adoptPtr(new WebCryptoAesDerivedKeyParams(length));
802 return true; 800 return true;
803 } 801 }
804 802
805 // FIXME: once the spec has been updated, check that the implementation is 803 // FIXME: once the spec has been updated, check that the implementation is
806 // still correct and update this comment. http://crbug.com/399095 804 // still correct and update this comment. http://crbug.com/399095
807 // 805 //
808 // The WebCrypto spec hasn't been updated yet to define HKDF 806 // The WebCrypto spec hasn't been updated yet to define HKDF
809 // (https://www.w3.org/Bugs/Public/show_bug.cgi?id=27425). The assumed 807 // (https://www.w3.org/Bugs/Public/show_bug.cgi?id=27425). The assumed
810 // parameters are: 808 // parameters are:
811 // 809 //
812 // dictionary HkdfParams : Algorithm { 810 // dictionary HkdfParams : Algorithm {
813 // required HashAlgorithmIdentifier hash; 811 // required HashAlgorithmIdentifier hash;
814 // required BufferSource salt; 812 // required BufferSource salt;
815 // required BufferSource info; 813 // required BufferSource info;
816 // }; 814 // };
817 bool parseHkdfParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmPa rams>& params, const ErrorContext& context, AlgorithmError* error) 815 bool parseHkdfParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& pa rams, const ErrorContext& context, AlgorithmError* error)
818 { 816 {
819 WebCryptoAlgorithm hash; 817 WebCryptoAlgorithm hash;
820 if (!parseHash(raw, hash, context, error)) 818 if (!parseHash(raw, hash, context, error))
821 return false; 819 return false;
822 BufferSource saltBufferSource; 820 BufferSource saltBufferSource;
823 if (!getBufferSource(raw, "salt", saltBufferSource, context, error)) 821 if (!getBufferSource(raw, "salt", saltBufferSource, context, error))
824 return false; 822 return false;
825 BufferSource infoBufferSource; 823 BufferSource infoBufferSource;
826 if (!getBufferSource(raw, "info", infoBufferSource, context, error)) 824 if (!getBufferSource(raw, "info", infoBufferSource, context, error))
827 return false; 825 return false;
828 826
829 DOMArrayPiece salt(saltBufferSource); 827 DOMArrayPiece salt(saltBufferSource);
830 DOMArrayPiece info(infoBufferSource); 828 DOMArrayPiece info(infoBufferSource);
831 829
832 params = wrapUnique(new WebCryptoHkdfParams(hash, salt.bytes(), salt.byteLen gth(), info.bytes(), info.byteLength())); 830 params = adoptPtr(new WebCryptoHkdfParams(hash, salt.bytes(), salt.byteLengt h(), info.bytes(), info.byteLength()));
833 return true; 831 return true;
834 } 832 }
835 833
836 bool parseAlgorithmParams(const Dictionary& raw, WebCryptoAlgorithmParamsType ty pe, std::unique_ptr<WebCryptoAlgorithmParams>& params, ErrorContext& context, Al gorithmError* error) 834 bool parseAlgorithmParams(const Dictionary& raw, WebCryptoAlgorithmParamsType ty pe, OwnPtr<WebCryptoAlgorithmParams>& params, ErrorContext& context, AlgorithmEr ror* error)
837 { 835 {
838 switch (type) { 836 switch (type) {
839 case WebCryptoAlgorithmParamsTypeNone: 837 case WebCryptoAlgorithmParamsTypeNone:
840 return true; 838 return true;
841 case WebCryptoAlgorithmParamsTypeAesCbcParams: 839 case WebCryptoAlgorithmParamsTypeAesCbcParams:
842 context.add("AesCbcParams"); 840 context.add("AesCbcParams");
843 return parseAesCbcParams(raw, params, context, error); 841 return parseAesCbcParams(raw, params, context, error);
844 case WebCryptoAlgorithmParamsTypeAesKeyGenParams: 842 case WebCryptoAlgorithmParamsTypeAesKeyGenParams:
845 context.add("AesKeyGenParams"); 843 context.add("AesKeyGenParams");
846 return parseAesKeyGenParams(raw, params, context, error); 844 return parseAesKeyGenParams(raw, params, context, error);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 const WebCryptoAlgorithmInfo* algorithmInfo = WebCryptoAlgorithm::lookupAlgo rithmInfo(algorithmId); 935 const WebCryptoAlgorithmInfo* algorithmInfo = WebCryptoAlgorithm::lookupAlgo rithmInfo(algorithmId);
938 936
939 if (algorithmInfo->operationToParamsType[op] == WebCryptoAlgorithmInfo::Unde fined) { 937 if (algorithmInfo->operationToParamsType[op] == WebCryptoAlgorithmInfo::Unde fined) {
940 context.add(algorithmInfo->name); 938 context.add(algorithmInfo->name);
941 setNotSupportedError(context.toString("Unsupported operation", operation ToString(op)), error); 939 setNotSupportedError(context.toString("Unsupported operation", operation ToString(op)), error);
942 return false; 940 return false;
943 } 941 }
944 942
945 WebCryptoAlgorithmParamsType paramsType = static_cast<WebCryptoAlgorithmPara msType>(algorithmInfo->operationToParamsType[op]); 943 WebCryptoAlgorithmParamsType paramsType = static_cast<WebCryptoAlgorithmPara msType>(algorithmInfo->operationToParamsType[op]);
946 944
947 std::unique_ptr<WebCryptoAlgorithmParams> params; 945 OwnPtr<WebCryptoAlgorithmParams> params;
948 if (!parseAlgorithmParams(raw, paramsType, params, context, error)) 946 if (!parseAlgorithmParams(raw, paramsType, params, context, error))
949 return false; 947 return false;
950 948
951 algorithm = WebCryptoAlgorithm(algorithmId, std::move(params)); 949 algorithm = WebCryptoAlgorithm(algorithmId, std::move(params));
952 return true; 950 return true;
953 } 951 }
954 952
955 bool parseAlgorithmIdentifier(const AlgorithmIdentifier& raw, WebCryptoOperation op, WebCryptoAlgorithm& algorithm, ErrorContext context, AlgorithmError* error) 953 bool parseAlgorithmIdentifier(const AlgorithmIdentifier& raw, WebCryptoOperation op, WebCryptoAlgorithm& algorithm, ErrorContext context, AlgorithmError* error)
956 { 954 {
957 context.add("Algorithm"); 955 context.add("Algorithm");
(...skipping 21 matching lines...) Expand all
979 } 977 }
980 978
981 } // namespace 979 } // namespace
982 980
983 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op, W ebCryptoAlgorithm& algorithm, AlgorithmError* error) 981 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op, W ebCryptoAlgorithm& algorithm, AlgorithmError* error)
984 { 982 {
985 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error); 983 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error);
986 } 984 }
987 985
988 } // namespace blink 986 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698