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

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

Issue 2494333002: Replace wrapUnique(new T(args)) by makeUnique<T>(args) in Blink (Closed)
Patch Set: Drop redundant WTF:: Created 4 years, 1 month 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 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = wrapUnique(new WebCryptoAesKeyGenParams(length)); 534 params = 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
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 = wrapUnique(new WebCryptoHmacImportParams(hash, hasLength, length)); 576 params = 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 = wrapUnique(new WebCryptoHmacKeyGenParams(hash, hasLength, length)); 599 params = 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 = wrapUnique(new WebCryptoRsaHashedImportParams(hash)); 617 params = 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 // [EnforceRange] required unsigned long saltLength; 729 // [EnforceRange] required unsigned long saltLength;
730 // }; 730 // };
731 bool parseRsaPssParams(const Dictionary& raw, 731 bool parseRsaPssParams(const Dictionary& raw,
732 std::unique_ptr<WebCryptoAlgorithmParams>& params, 732 std::unique_ptr<WebCryptoAlgorithmParams>& params,
733 const ErrorContext& context, 733 const ErrorContext& context,
734 AlgorithmError* error) { 734 AlgorithmError* error) {
735 uint32_t saltLengthBytes; 735 uint32_t saltLengthBytes;
736 if (!getUint32(raw, "saltLength", saltLengthBytes, context, error)) 736 if (!getUint32(raw, "saltLength", saltLengthBytes, context, error))
737 return false; 737 return false;
738 738
739 params = wrapUnique(new WebCryptoRsaPssParams(saltLengthBytes)); 739 params = makeUnique<WebCryptoRsaPssParams>(saltLengthBytes);
740 return true; 740 return true;
741 } 741 }
742 742
743 // Defined by the WebCrypto spec as: 743 // Defined by the WebCrypto spec as:
744 // 744 //
745 // dictionary EcdsaParams : Algorithm { 745 // dictionary EcdsaParams : Algorithm {
746 // required HashAlgorithmIdentifier hash; 746 // required HashAlgorithmIdentifier hash;
747 // }; 747 // };
748 bool parseEcdsaParams(const Dictionary& raw, 748 bool parseEcdsaParams(const Dictionary& raw,
749 std::unique_ptr<WebCryptoAlgorithmParams>& params, 749 std::unique_ptr<WebCryptoAlgorithmParams>& params,
750 const ErrorContext& context, 750 const ErrorContext& context,
751 AlgorithmError* error) { 751 AlgorithmError* error) {
752 WebCryptoAlgorithm hash; 752 WebCryptoAlgorithm hash;
753 if (!parseHash(raw, hash, context, error)) 753 if (!parseHash(raw, hash, context, error))
754 return false; 754 return false;
755 755
756 params = wrapUnique(new WebCryptoEcdsaParams(hash)); 756 params = makeUnique<WebCryptoEcdsaParams>(hash);
757 return true; 757 return true;
758 } 758 }
759 759
760 struct CurveNameMapping { 760 struct CurveNameMapping {
761 const char* const name; 761 const char* const name;
762 WebCryptoNamedCurve value; 762 WebCryptoNamedCurve value;
763 }; 763 };
764 764
765 const CurveNameMapping curveNameMappings[] = { 765 const CurveNameMapping curveNameMappings[] = {
766 {"P-256", WebCryptoNamedCurveP256}, 766 {"P-256", WebCryptoNamedCurveP256},
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 // required NamedCurve namedCurve; 800 // required NamedCurve namedCurve;
801 // }; 801 // };
802 bool parseEcKeyGenParams(const Dictionary& raw, 802 bool parseEcKeyGenParams(const Dictionary& raw,
803 std::unique_ptr<WebCryptoAlgorithmParams>& params, 803 std::unique_ptr<WebCryptoAlgorithmParams>& params,
804 const ErrorContext& context, 804 const ErrorContext& context,
805 AlgorithmError* error) { 805 AlgorithmError* error) {
806 WebCryptoNamedCurve namedCurve; 806 WebCryptoNamedCurve namedCurve;
807 if (!parseNamedCurve(raw, namedCurve, context, error)) 807 if (!parseNamedCurve(raw, namedCurve, context, error))
808 return false; 808 return false;
809 809
810 params = wrapUnique(new WebCryptoEcKeyGenParams(namedCurve)); 810 params = makeUnique<WebCryptoEcKeyGenParams>(namedCurve);
811 return true; 811 return true;
812 } 812 }
813 813
814 // Defined by the WebCrypto spec as: 814 // Defined by the WebCrypto spec as:
815 // 815 //
816 // dictionary EcKeyImportParams : Algorithm { 816 // dictionary EcKeyImportParams : Algorithm {
817 // required NamedCurve namedCurve; 817 // required NamedCurve namedCurve;
818 // }; 818 // };
819 bool parseEcKeyImportParams(const Dictionary& raw, 819 bool parseEcKeyImportParams(const Dictionary& raw,
820 std::unique_ptr<WebCryptoAlgorithmParams>& params, 820 std::unique_ptr<WebCryptoAlgorithmParams>& params,
821 const ErrorContext& context, 821 const ErrorContext& context,
822 AlgorithmError* error) { 822 AlgorithmError* error) {
823 WebCryptoNamedCurve namedCurve; 823 WebCryptoNamedCurve namedCurve;
824 if (!parseNamedCurve(raw, namedCurve, context, error)) 824 if (!parseNamedCurve(raw, namedCurve, context, error))
825 return false; 825 return false;
826 826
827 params = wrapUnique(new WebCryptoEcKeyImportParams(namedCurve)); 827 params = makeUnique<WebCryptoEcKeyImportParams>(namedCurve);
828 return true; 828 return true;
829 } 829 }
830 830
831 // Defined by the WebCrypto spec as: 831 // Defined by the WebCrypto spec as:
832 // 832 //
833 // dictionary EcdhKeyDeriveParams : Algorithm { 833 // dictionary EcdhKeyDeriveParams : Algorithm {
834 // required CryptoKey public; 834 // required CryptoKey public;
835 // }; 835 // };
836 bool parseEcdhKeyDeriveParams(const Dictionary& raw, 836 bool parseEcdhKeyDeriveParams(const Dictionary& raw,
837 std::unique_ptr<WebCryptoAlgorithmParams>& params, 837 std::unique_ptr<WebCryptoAlgorithmParams>& params,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 // [EnforceRange] required unsigned short length; 888 // [EnforceRange] required unsigned short length;
889 // }; 889 // };
890 bool parseAesDerivedKeyParams(const Dictionary& raw, 890 bool parseAesDerivedKeyParams(const Dictionary& raw,
891 std::unique_ptr<WebCryptoAlgorithmParams>& params, 891 std::unique_ptr<WebCryptoAlgorithmParams>& params,
892 const ErrorContext& context, 892 const ErrorContext& context,
893 AlgorithmError* error) { 893 AlgorithmError* error) {
894 uint16_t length; 894 uint16_t length;
895 if (!getUint16(raw, "length", length, context, error)) 895 if (!getUint16(raw, "length", length, context, error))
896 return false; 896 return false;
897 897
898 params = wrapUnique(new WebCryptoAesDerivedKeyParams(length)); 898 params = makeUnique<WebCryptoAesDerivedKeyParams>(length);
899 return true; 899 return true;
900 } 900 }
901 901
902 // Defined by the WebCrypto spec as: 902 // Defined by the WebCrypto spec as:
903 // 903 //
904 // dictionary HkdfParams : Algorithm { 904 // dictionary HkdfParams : Algorithm {
905 // required HashAlgorithmIdentifier hash; 905 // required HashAlgorithmIdentifier hash;
906 // required BufferSource salt; 906 // required BufferSource salt;
907 // required BufferSource info; 907 // required BufferSource info;
908 // }; 908 // };
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 } // namespace 1091 } // namespace
1092 1092
1093 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, 1093 bool normalizeAlgorithm(const AlgorithmIdentifier& raw,
1094 WebCryptoOperation op, 1094 WebCryptoOperation op,
1095 WebCryptoAlgorithm& algorithm, 1095 WebCryptoAlgorithm& algorithm,
1096 AlgorithmError* error) { 1096 AlgorithmError* error) {
1097 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error); 1097 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error);
1098 } 1098 }
1099 1099
1100 } // namespace blink 1100 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698