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

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

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

Powered by Google App Engine
This is Rietveld 408576698