| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 // required BufferSource iv; | 507 // required BufferSource iv; |
| 508 // }; | 508 // }; |
| 509 bool parseAesCbcParams(const Dictionary& raw, | 509 bool parseAesCbcParams(const Dictionary& raw, |
| 510 std::unique_ptr<WebCryptoAlgorithmParams>& params, | 510 std::unique_ptr<WebCryptoAlgorithmParams>& params, |
| 511 const ErrorContext& context, | 511 const ErrorContext& context, |
| 512 AlgorithmError* error) { | 512 AlgorithmError* error) { |
| 513 WebVector<uint8_t> iv; | 513 WebVector<uint8_t> iv; |
| 514 if (!getBufferSource(raw, "iv", iv, context, error)) | 514 if (!getBufferSource(raw, "iv", iv, context, error)) |
| 515 return false; | 515 return false; |
| 516 | 516 |
| 517 params = wrapUnique(new WebCryptoAesCbcParams(std::move(iv))); | 517 params = WTF::wrapUnique(new WebCryptoAesCbcParams(std::move(iv))); |
| 518 return true; | 518 return true; |
| 519 } | 519 } |
| 520 | 520 |
| 521 // Defined by the WebCrypto spec as: | 521 // Defined by the WebCrypto spec as: |
| 522 // | 522 // |
| 523 // dictionary AesKeyGenParams : Algorithm { | 523 // dictionary AesKeyGenParams : Algorithm { |
| 524 // [EnforceRange] required unsigned short length; | 524 // [EnforceRange] required unsigned short length; |
| 525 // }; | 525 // }; |
| 526 bool parseAesKeyGenParams(const Dictionary& raw, | 526 bool parseAesKeyGenParams(const Dictionary& raw, |
| 527 std::unique_ptr<WebCryptoAlgorithmParams>& params, | 527 std::unique_ptr<WebCryptoAlgorithmParams>& params, |
| 528 const ErrorContext& context, | 528 const ErrorContext& context, |
| 529 AlgorithmError* error) { | 529 AlgorithmError* error) { |
| 530 uint16_t length; | 530 uint16_t length; |
| 531 if (!getUint16(raw, "length", length, context, error)) | 531 if (!getUint16(raw, "length", length, context, error)) |
| 532 return false; | 532 return false; |
| 533 | 533 |
| 534 params = makeUnique<WebCryptoAesKeyGenParams>(length); | 534 params = WTF::makeUnique<WebCryptoAesKeyGenParams>(length); |
| 535 return true; | 535 return true; |
| 536 } | 536 } |
| 537 | 537 |
| 538 bool parseAlgorithmIdentifier(const AlgorithmIdentifier&, | 538 bool parseAlgorithmIdentifier(const AlgorithmIdentifier&, |
| 539 WebCryptoOperation, | 539 WebCryptoOperation, |
| 540 WebCryptoAlgorithm&, | 540 WebCryptoAlgorithm&, |
| 541 ErrorContext, | 541 ErrorContext, |
| 542 AlgorithmError*); | 542 AlgorithmError*); |
| 543 | 543 |
| 544 bool parseHash(const Dictionary& raw, | 544 bool parseHash(const Dictionary& raw, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 566 AlgorithmError* error) { | 566 AlgorithmError* error) { |
| 567 WebCryptoAlgorithm hash; | 567 WebCryptoAlgorithm hash; |
| 568 if (!parseHash(raw, hash, context, error)) | 568 if (!parseHash(raw, hash, context, error)) |
| 569 return false; | 569 return false; |
| 570 | 570 |
| 571 bool hasLength; | 571 bool hasLength; |
| 572 uint32_t length = 0; | 572 uint32_t length = 0; |
| 573 if (!getOptionalUint32(raw, "length", hasLength, length, context, error)) | 573 if (!getOptionalUint32(raw, "length", hasLength, length, context, error)) |
| 574 return false; | 574 return false; |
| 575 | 575 |
| 576 params = makeUnique<WebCryptoHmacImportParams>(hash, hasLength, length); | 576 params = WTF::makeUnique<WebCryptoHmacImportParams>(hash, hasLength, length); |
| 577 return true; | 577 return true; |
| 578 } | 578 } |
| 579 | 579 |
| 580 // Defined by the WebCrypto spec as: | 580 // Defined by the WebCrypto spec as: |
| 581 // | 581 // |
| 582 // dictionary HmacKeyGenParams : Algorithm { | 582 // dictionary HmacKeyGenParams : Algorithm { |
| 583 // required HashAlgorithmIdentifier hash; | 583 // required HashAlgorithmIdentifier hash; |
| 584 // [EnforceRange] unsigned long length; | 584 // [EnforceRange] unsigned long length; |
| 585 // }; | 585 // }; |
| 586 bool parseHmacKeyGenParams(const Dictionary& raw, | 586 bool parseHmacKeyGenParams(const Dictionary& raw, |
| 587 std::unique_ptr<WebCryptoAlgorithmParams>& params, | 587 std::unique_ptr<WebCryptoAlgorithmParams>& params, |
| 588 const ErrorContext& context, | 588 const ErrorContext& context, |
| 589 AlgorithmError* error) { | 589 AlgorithmError* error) { |
| 590 WebCryptoAlgorithm hash; | 590 WebCryptoAlgorithm hash; |
| 591 if (!parseHash(raw, hash, context, error)) | 591 if (!parseHash(raw, hash, context, error)) |
| 592 return false; | 592 return false; |
| 593 | 593 |
| 594 bool hasLength; | 594 bool hasLength; |
| 595 uint32_t length = 0; | 595 uint32_t length = 0; |
| 596 if (!getOptionalUint32(raw, "length", hasLength, length, context, error)) | 596 if (!getOptionalUint32(raw, "length", hasLength, length, context, error)) |
| 597 return false; | 597 return false; |
| 598 | 598 |
| 599 params = makeUnique<WebCryptoHmacKeyGenParams>(hash, hasLength, length); | 599 params = WTF::makeUnique<WebCryptoHmacKeyGenParams>(hash, hasLength, length); |
| 600 return true; | 600 return true; |
| 601 } | 601 } |
| 602 | 602 |
| 603 // Defined by the WebCrypto spec as: | 603 // Defined by the WebCrypto spec as: |
| 604 // | 604 // |
| 605 // dictionary RsaHashedImportParams : Algorithm { | 605 // dictionary RsaHashedImportParams : Algorithm { |
| 606 // required HashAlgorithmIdentifier hash; | 606 // required HashAlgorithmIdentifier hash; |
| 607 // }; | 607 // }; |
| 608 bool parseRsaHashedImportParams( | 608 bool parseRsaHashedImportParams( |
| 609 const Dictionary& raw, | 609 const Dictionary& raw, |
| 610 std::unique_ptr<WebCryptoAlgorithmParams>& params, | 610 std::unique_ptr<WebCryptoAlgorithmParams>& params, |
| 611 const ErrorContext& context, | 611 const ErrorContext& context, |
| 612 AlgorithmError* error) { | 612 AlgorithmError* error) { |
| 613 WebCryptoAlgorithm hash; | 613 WebCryptoAlgorithm hash; |
| 614 if (!parseHash(raw, hash, context, error)) | 614 if (!parseHash(raw, hash, context, error)) |
| 615 return false; | 615 return false; |
| 616 | 616 |
| 617 params = makeUnique<WebCryptoRsaHashedImportParams>(hash); | 617 params = WTF::makeUnique<WebCryptoRsaHashedImportParams>(hash); |
| 618 return true; | 618 return true; |
| 619 } | 619 } |
| 620 | 620 |
| 621 // Defined by the WebCrypto spec as: | 621 // Defined by the WebCrypto spec as: |
| 622 // | 622 // |
| 623 // dictionary RsaKeyGenParams : Algorithm { | 623 // dictionary RsaKeyGenParams : Algorithm { |
| 624 // [EnforceRange] required unsigned long modulusLength; | 624 // [EnforceRange] required unsigned long modulusLength; |
| 625 // required BigInteger publicExponent; | 625 // required BigInteger publicExponent; |
| 626 // }; | 626 // }; |
| 627 // | 627 // |
| (...skipping 10 matching lines...) Expand all Loading... |
| 638 return false; | 638 return false; |
| 639 | 639 |
| 640 WebVector<uint8_t> publicExponent; | 640 WebVector<uint8_t> publicExponent; |
| 641 if (!getBigInteger(raw, "publicExponent", publicExponent, context, error)) | 641 if (!getBigInteger(raw, "publicExponent", publicExponent, context, error)) |
| 642 return false; | 642 return false; |
| 643 | 643 |
| 644 WebCryptoAlgorithm hash; | 644 WebCryptoAlgorithm hash; |
| 645 if (!parseHash(raw, hash, context, error)) | 645 if (!parseHash(raw, hash, context, error)) |
| 646 return false; | 646 return false; |
| 647 | 647 |
| 648 params = wrapUnique(new WebCryptoRsaHashedKeyGenParams( | 648 params = WTF::wrapUnique(new WebCryptoRsaHashedKeyGenParams( |
| 649 hash, modulusLength, std::move(publicExponent))); | 649 hash, modulusLength, std::move(publicExponent))); |
| 650 return true; | 650 return true; |
| 651 } | 651 } |
| 652 | 652 |
| 653 // Defined by the WebCrypto spec as: | 653 // Defined by the WebCrypto spec as: |
| 654 // | 654 // |
| 655 // dictionary AesCtrParams : Algorithm { | 655 // dictionary AesCtrParams : Algorithm { |
| 656 // required BufferSource counter; | 656 // required BufferSource counter; |
| 657 // [EnforceRange] required octet length; | 657 // [EnforceRange] required octet length; |
| 658 // }; | 658 // }; |
| 659 bool parseAesCtrParams(const Dictionary& raw, | 659 bool parseAesCtrParams(const Dictionary& raw, |
| 660 std::unique_ptr<WebCryptoAlgorithmParams>& params, | 660 std::unique_ptr<WebCryptoAlgorithmParams>& params, |
| 661 const ErrorContext& context, | 661 const ErrorContext& context, |
| 662 AlgorithmError* error) { | 662 AlgorithmError* error) { |
| 663 WebVector<uint8_t> counter; | 663 WebVector<uint8_t> counter; |
| 664 if (!getBufferSource(raw, "counter", counter, context, error)) | 664 if (!getBufferSource(raw, "counter", counter, context, error)) |
| 665 return false; | 665 return false; |
| 666 | 666 |
| 667 uint8_t length; | 667 uint8_t length; |
| 668 if (!getUint8(raw, "length", length, context, error)) | 668 if (!getUint8(raw, "length", length, context, error)) |
| 669 return false; | 669 return false; |
| 670 | 670 |
| 671 params = wrapUnique(new WebCryptoAesCtrParams(length, std::move(counter))); | 671 params = |
| 672 WTF::wrapUnique(new WebCryptoAesCtrParams(length, std::move(counter))); |
| 672 return true; | 673 return true; |
| 673 } | 674 } |
| 674 | 675 |
| 675 // Defined by the WebCrypto spec as: | 676 // Defined by the WebCrypto spec as: |
| 676 // | 677 // |
| 677 // dictionary AesGcmParams : Algorithm { | 678 // dictionary AesGcmParams : Algorithm { |
| 678 // required BufferSource iv; | 679 // required BufferSource iv; |
| 679 // BufferSource additionalData; | 680 // BufferSource additionalData; |
| 680 // [EnforceRange] octet tagLength; | 681 // [EnforceRange] octet tagLength; |
| 681 // } | 682 // } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 692 if (!getOptionalBufferSource(raw, "additionalData", hasAdditionalData, | 693 if (!getOptionalBufferSource(raw, "additionalData", hasAdditionalData, |
| 693 additionalData, context, error)) | 694 additionalData, context, error)) |
| 694 return false; | 695 return false; |
| 695 | 696 |
| 696 uint8_t tagLength = 0; | 697 uint8_t tagLength = 0; |
| 697 bool hasTagLength; | 698 bool hasTagLength; |
| 698 if (!getOptionalUint8(raw, "tagLength", hasTagLength, tagLength, context, | 699 if (!getOptionalUint8(raw, "tagLength", hasTagLength, tagLength, context, |
| 699 error)) | 700 error)) |
| 700 return false; | 701 return false; |
| 701 | 702 |
| 702 params = wrapUnique(new WebCryptoAesGcmParams( | 703 params = WTF::wrapUnique(new WebCryptoAesGcmParams( |
| 703 std::move(iv), hasAdditionalData, std::move(additionalData), hasTagLength, | 704 std::move(iv), hasAdditionalData, std::move(additionalData), hasTagLength, |
| 704 tagLength)); | 705 tagLength)); |
| 705 return true; | 706 return true; |
| 706 } | 707 } |
| 707 | 708 |
| 708 // Defined by the WebCrypto spec as: | 709 // Defined by the WebCrypto spec as: |
| 709 // | 710 // |
| 710 // dictionary RsaOaepParams : Algorithm { | 711 // dictionary RsaOaepParams : Algorithm { |
| 711 // BufferSource label; | 712 // BufferSource label; |
| 712 // }; | 713 // }; |
| 713 bool parseRsaOaepParams(const Dictionary& raw, | 714 bool parseRsaOaepParams(const Dictionary& raw, |
| 714 std::unique_ptr<WebCryptoAlgorithmParams>& params, | 715 std::unique_ptr<WebCryptoAlgorithmParams>& params, |
| 715 const ErrorContext& context, | 716 const ErrorContext& context, |
| 716 AlgorithmError* error) { | 717 AlgorithmError* error) { |
| 717 bool hasLabel; | 718 bool hasLabel; |
| 718 WebVector<uint8_t> label; | 719 WebVector<uint8_t> label; |
| 719 if (!getOptionalBufferSource(raw, "label", hasLabel, label, context, error)) | 720 if (!getOptionalBufferSource(raw, "label", hasLabel, label, context, error)) |
| 720 return false; | 721 return false; |
| 721 | 722 |
| 722 params = wrapUnique(new WebCryptoRsaOaepParams(hasLabel, std::move(label))); | 723 params = |
| 724 WTF::wrapUnique(new WebCryptoRsaOaepParams(hasLabel, std::move(label))); |
| 723 return true; | 725 return true; |
| 724 } | 726 } |
| 725 | 727 |
| 726 // Defined by the WebCrypto spec as: | 728 // Defined by the WebCrypto spec as: |
| 727 // | 729 // |
| 728 // dictionary RsaPssParams : Algorithm { | 730 // dictionary RsaPssParams : Algorithm { |
| 729 // [EnforceRange] required unsigned long saltLength; | 731 // [EnforceRange] required unsigned long saltLength; |
| 730 // }; | 732 // }; |
| 731 bool parseRsaPssParams(const Dictionary& raw, | 733 bool parseRsaPssParams(const Dictionary& raw, |
| 732 std::unique_ptr<WebCryptoAlgorithmParams>& params, | 734 std::unique_ptr<WebCryptoAlgorithmParams>& params, |
| 733 const ErrorContext& context, | 735 const ErrorContext& context, |
| 734 AlgorithmError* error) { | 736 AlgorithmError* error) { |
| 735 uint32_t saltLengthBytes; | 737 uint32_t saltLengthBytes; |
| 736 if (!getUint32(raw, "saltLength", saltLengthBytes, context, error)) | 738 if (!getUint32(raw, "saltLength", saltLengthBytes, context, error)) |
| 737 return false; | 739 return false; |
| 738 | 740 |
| 739 params = makeUnique<WebCryptoRsaPssParams>(saltLengthBytes); | 741 params = WTF::makeUnique<WebCryptoRsaPssParams>(saltLengthBytes); |
| 740 return true; | 742 return true; |
| 741 } | 743 } |
| 742 | 744 |
| 743 // Defined by the WebCrypto spec as: | 745 // Defined by the WebCrypto spec as: |
| 744 // | 746 // |
| 745 // dictionary EcdsaParams : Algorithm { | 747 // dictionary EcdsaParams : Algorithm { |
| 746 // required HashAlgorithmIdentifier hash; | 748 // required HashAlgorithmIdentifier hash; |
| 747 // }; | 749 // }; |
| 748 bool parseEcdsaParams(const Dictionary& raw, | 750 bool parseEcdsaParams(const Dictionary& raw, |
| 749 std::unique_ptr<WebCryptoAlgorithmParams>& params, | 751 std::unique_ptr<WebCryptoAlgorithmParams>& params, |
| 750 const ErrorContext& context, | 752 const ErrorContext& context, |
| 751 AlgorithmError* error) { | 753 AlgorithmError* error) { |
| 752 WebCryptoAlgorithm hash; | 754 WebCryptoAlgorithm hash; |
| 753 if (!parseHash(raw, hash, context, error)) | 755 if (!parseHash(raw, hash, context, error)) |
| 754 return false; | 756 return false; |
| 755 | 757 |
| 756 params = makeUnique<WebCryptoEcdsaParams>(hash); | 758 params = WTF::makeUnique<WebCryptoEcdsaParams>(hash); |
| 757 return true; | 759 return true; |
| 758 } | 760 } |
| 759 | 761 |
| 760 struct CurveNameMapping { | 762 struct CurveNameMapping { |
| 761 const char* const name; | 763 const char* const name; |
| 762 WebCryptoNamedCurve value; | 764 WebCryptoNamedCurve value; |
| 763 }; | 765 }; |
| 764 | 766 |
| 765 const CurveNameMapping curveNameMappings[] = { | 767 const CurveNameMapping curveNameMappings[] = { |
| 766 {"P-256", WebCryptoNamedCurveP256}, | 768 {"P-256", WebCryptoNamedCurveP256}, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 // required NamedCurve namedCurve; | 802 // required NamedCurve namedCurve; |
| 801 // }; | 803 // }; |
| 802 bool parseEcKeyGenParams(const Dictionary& raw, | 804 bool parseEcKeyGenParams(const Dictionary& raw, |
| 803 std::unique_ptr<WebCryptoAlgorithmParams>& params, | 805 std::unique_ptr<WebCryptoAlgorithmParams>& params, |
| 804 const ErrorContext& context, | 806 const ErrorContext& context, |
| 805 AlgorithmError* error) { | 807 AlgorithmError* error) { |
| 806 WebCryptoNamedCurve namedCurve; | 808 WebCryptoNamedCurve namedCurve; |
| 807 if (!parseNamedCurve(raw, namedCurve, context, error)) | 809 if (!parseNamedCurve(raw, namedCurve, context, error)) |
| 808 return false; | 810 return false; |
| 809 | 811 |
| 810 params = makeUnique<WebCryptoEcKeyGenParams>(namedCurve); | 812 params = WTF::makeUnique<WebCryptoEcKeyGenParams>(namedCurve); |
| 811 return true; | 813 return true; |
| 812 } | 814 } |
| 813 | 815 |
| 814 // Defined by the WebCrypto spec as: | 816 // Defined by the WebCrypto spec as: |
| 815 // | 817 // |
| 816 // dictionary EcKeyImportParams : Algorithm { | 818 // dictionary EcKeyImportParams : Algorithm { |
| 817 // required NamedCurve namedCurve; | 819 // required NamedCurve namedCurve; |
| 818 // }; | 820 // }; |
| 819 bool parseEcKeyImportParams(const Dictionary& raw, | 821 bool parseEcKeyImportParams(const Dictionary& raw, |
| 820 std::unique_ptr<WebCryptoAlgorithmParams>& params, | 822 std::unique_ptr<WebCryptoAlgorithmParams>& params, |
| 821 const ErrorContext& context, | 823 const ErrorContext& context, |
| 822 AlgorithmError* error) { | 824 AlgorithmError* error) { |
| 823 WebCryptoNamedCurve namedCurve; | 825 WebCryptoNamedCurve namedCurve; |
| 824 if (!parseNamedCurve(raw, namedCurve, context, error)) | 826 if (!parseNamedCurve(raw, namedCurve, context, error)) |
| 825 return false; | 827 return false; |
| 826 | 828 |
| 827 params = makeUnique<WebCryptoEcKeyImportParams>(namedCurve); | 829 params = WTF::makeUnique<WebCryptoEcKeyImportParams>(namedCurve); |
| 828 return true; | 830 return true; |
| 829 } | 831 } |
| 830 | 832 |
| 831 // Defined by the WebCrypto spec as: | 833 // Defined by the WebCrypto spec as: |
| 832 // | 834 // |
| 833 // dictionary EcdhKeyDeriveParams : Algorithm { | 835 // dictionary EcdhKeyDeriveParams : Algorithm { |
| 834 // required CryptoKey public; | 836 // required CryptoKey public; |
| 835 // }; | 837 // }; |
| 836 bool parseEcdhKeyDeriveParams(const Dictionary& raw, | 838 bool parseEcdhKeyDeriveParams(const Dictionary& raw, |
| 837 std::unique_ptr<WebCryptoAlgorithmParams>& params, | 839 std::unique_ptr<WebCryptoAlgorithmParams>& params, |
| 838 const ErrorContext& context, | 840 const ErrorContext& context, |
| 839 AlgorithmError* error) { | 841 AlgorithmError* error) { |
| 840 v8::Local<v8::Value> v8Value; | 842 v8::Local<v8::Value> v8Value; |
| 841 if (!raw.get("public", v8Value)) { | 843 if (!raw.get("public", v8Value)) { |
| 842 setTypeError(context.toString("public", "Missing required property"), | 844 setTypeError(context.toString("public", "Missing required property"), |
| 843 error); | 845 error); |
| 844 return false; | 846 return false; |
| 845 } | 847 } |
| 846 | 848 |
| 847 CryptoKey* cryptoKey = | 849 CryptoKey* cryptoKey = |
| 848 V8CryptoKey::toImplWithTypeCheck(raw.isolate(), v8Value); | 850 V8CryptoKey::toImplWithTypeCheck(raw.isolate(), v8Value); |
| 849 if (!cryptoKey) { | 851 if (!cryptoKey) { |
| 850 setTypeError(context.toString("public", "Must be a CryptoKey"), error); | 852 setTypeError(context.toString("public", "Must be a CryptoKey"), error); |
| 851 return false; | 853 return false; |
| 852 } | 854 } |
| 853 | 855 |
| 854 params = wrapUnique(new WebCryptoEcdhKeyDeriveParams(cryptoKey->key())); | 856 params = WTF::wrapUnique(new WebCryptoEcdhKeyDeriveParams(cryptoKey->key())); |
| 855 return true; | 857 return true; |
| 856 } | 858 } |
| 857 | 859 |
| 858 // Defined by the WebCrypto spec as: | 860 // Defined by the WebCrypto spec as: |
| 859 // | 861 // |
| 860 // dictionary Pbkdf2Params : Algorithm { | 862 // dictionary Pbkdf2Params : Algorithm { |
| 861 // required BufferSource salt; | 863 // required BufferSource salt; |
| 862 // [EnforceRange] required unsigned long iterations; | 864 // [EnforceRange] required unsigned long iterations; |
| 863 // required HashAlgorithmIdentifier hash; | 865 // required HashAlgorithmIdentifier hash; |
| 864 // }; | 866 // }; |
| 865 bool parsePbkdf2Params(const Dictionary& raw, | 867 bool parsePbkdf2Params(const Dictionary& raw, |
| 866 std::unique_ptr<WebCryptoAlgorithmParams>& params, | 868 std::unique_ptr<WebCryptoAlgorithmParams>& params, |
| 867 const ErrorContext& context, | 869 const ErrorContext& context, |
| 868 AlgorithmError* error) { | 870 AlgorithmError* error) { |
| 869 WebVector<uint8_t> salt; | 871 WebVector<uint8_t> salt; |
| 870 if (!getBufferSource(raw, "salt", salt, context, error)) | 872 if (!getBufferSource(raw, "salt", salt, context, error)) |
| 871 return false; | 873 return false; |
| 872 | 874 |
| 873 uint32_t iterations; | 875 uint32_t iterations; |
| 874 if (!getUint32(raw, "iterations", iterations, context, error)) | 876 if (!getUint32(raw, "iterations", iterations, context, error)) |
| 875 return false; | 877 return false; |
| 876 | 878 |
| 877 WebCryptoAlgorithm hash; | 879 WebCryptoAlgorithm hash; |
| 878 if (!parseHash(raw, hash, context, error)) | 880 if (!parseHash(raw, hash, context, error)) |
| 879 return false; | 881 return false; |
| 880 params = | 882 params = WTF::wrapUnique( |
| 881 wrapUnique(new WebCryptoPbkdf2Params(hash, std::move(salt), iterations)); | 883 new WebCryptoPbkdf2Params(hash, std::move(salt), iterations)); |
| 882 return true; | 884 return true; |
| 883 } | 885 } |
| 884 | 886 |
| 885 // Defined by the WebCrypto spec as: | 887 // Defined by the WebCrypto spec as: |
| 886 // | 888 // |
| 887 // dictionary AesDerivedKeyParams : Algorithm { | 889 // dictionary AesDerivedKeyParams : Algorithm { |
| 888 // [EnforceRange] required unsigned short length; | 890 // [EnforceRange] required unsigned short length; |
| 889 // }; | 891 // }; |
| 890 bool parseAesDerivedKeyParams(const Dictionary& raw, | 892 bool parseAesDerivedKeyParams(const Dictionary& raw, |
| 891 std::unique_ptr<WebCryptoAlgorithmParams>& params, | 893 std::unique_ptr<WebCryptoAlgorithmParams>& params, |
| 892 const ErrorContext& context, | 894 const ErrorContext& context, |
| 893 AlgorithmError* error) { | 895 AlgorithmError* error) { |
| 894 uint16_t length; | 896 uint16_t length; |
| 895 if (!getUint16(raw, "length", length, context, error)) | 897 if (!getUint16(raw, "length", length, context, error)) |
| 896 return false; | 898 return false; |
| 897 | 899 |
| 898 params = makeUnique<WebCryptoAesDerivedKeyParams>(length); | 900 params = WTF::makeUnique<WebCryptoAesDerivedKeyParams>(length); |
| 899 return true; | 901 return true; |
| 900 } | 902 } |
| 901 | 903 |
| 902 // Defined by the WebCrypto spec as: | 904 // Defined by the WebCrypto spec as: |
| 903 // | 905 // |
| 904 // dictionary HkdfParams : Algorithm { | 906 // dictionary HkdfParams : Algorithm { |
| 905 // required HashAlgorithmIdentifier hash; | 907 // required HashAlgorithmIdentifier hash; |
| 906 // required BufferSource salt; | 908 // required BufferSource salt; |
| 907 // required BufferSource info; | 909 // required BufferSource info; |
| 908 // }; | 910 // }; |
| 909 bool parseHkdfParams(const Dictionary& raw, | 911 bool parseHkdfParams(const Dictionary& raw, |
| 910 std::unique_ptr<WebCryptoAlgorithmParams>& params, | 912 std::unique_ptr<WebCryptoAlgorithmParams>& params, |
| 911 const ErrorContext& context, | 913 const ErrorContext& context, |
| 912 AlgorithmError* error) { | 914 AlgorithmError* error) { |
| 913 WebCryptoAlgorithm hash; | 915 WebCryptoAlgorithm hash; |
| 914 if (!parseHash(raw, hash, context, error)) | 916 if (!parseHash(raw, hash, context, error)) |
| 915 return false; | 917 return false; |
| 916 WebVector<uint8_t> salt; | 918 WebVector<uint8_t> salt; |
| 917 if (!getBufferSource(raw, "salt", salt, context, error)) | 919 if (!getBufferSource(raw, "salt", salt, context, error)) |
| 918 return false; | 920 return false; |
| 919 WebVector<uint8_t> info; | 921 WebVector<uint8_t> info; |
| 920 if (!getBufferSource(raw, "info", info, context, error)) | 922 if (!getBufferSource(raw, "info", info, context, error)) |
| 921 return false; | 923 return false; |
| 922 | 924 |
| 923 params = wrapUnique( | 925 params = WTF::wrapUnique( |
| 924 new WebCryptoHkdfParams(hash, std::move(salt), std::move(info))); | 926 new WebCryptoHkdfParams(hash, std::move(salt), std::move(info))); |
| 925 return true; | 927 return true; |
| 926 } | 928 } |
| 927 | 929 |
| 928 bool parseAlgorithmParams(const Dictionary& raw, | 930 bool parseAlgorithmParams(const Dictionary& raw, |
| 929 WebCryptoAlgorithmParamsType type, | 931 WebCryptoAlgorithmParamsType type, |
| 930 std::unique_ptr<WebCryptoAlgorithmParams>& params, | 932 std::unique_ptr<WebCryptoAlgorithmParams>& params, |
| 931 ErrorContext& context, | 933 ErrorContext& context, |
| 932 AlgorithmError* error) { | 934 AlgorithmError* error) { |
| 933 switch (type) { | 935 switch (type) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 } // namespace | 1093 } // namespace |
| 1092 | 1094 |
| 1093 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, | 1095 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, |
| 1094 WebCryptoOperation op, | 1096 WebCryptoOperation op, |
| 1095 WebCryptoAlgorithm& algorithm, | 1097 WebCryptoAlgorithm& algorithm, |
| 1096 AlgorithmError* error) { | 1098 AlgorithmError* error) { |
| 1097 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error); | 1099 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error); |
| 1098 } | 1100 } |
| 1099 | 1101 |
| 1100 } // namespace blink | 1102 } // namespace blink |
| OLD | NEW |