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

Side by Side Diff: content/child/webcrypto/shared_crypto_unittest.cc

Issue 200763005: Support for the new WebCrypto digest by chunks API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated to latest WebCrypto API changes Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/webcrypto/shared_crypto.h" 5 #include "content/child/webcrypto/shared_crypto.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 std::vector<uint8> test_input = GetBytesFromHexString(test, "input"); 642 std::vector<uint8> test_input = GetBytesFromHexString(test, "input");
643 std::vector<uint8> test_output = GetBytesFromHexString(test, "output"); 643 std::vector<uint8> test_output = GetBytesFromHexString(test, "output");
644 644
645 blink::WebArrayBuffer output; 645 blink::WebArrayBuffer output;
646 ASSERT_STATUS_SUCCESS( 646 ASSERT_STATUS_SUCCESS(
647 Digest(test_algorithm, CryptoData(test_input), &output)); 647 Digest(test_algorithm, CryptoData(test_input), &output));
648 EXPECT_TRUE(ArrayBufferMatches(test_output, output)); 648 EXPECT_TRUE(ArrayBufferMatches(test_output, output));
649 } 649 }
650 } 650 }
651 651
652 TEST_F(SharedCryptoTest, DigestSampleSetsInChunks) {
653 scoped_ptr<base::ListValue> tests;
654 ASSERT_TRUE(ReadJsonTestFileToList("digest.json", &tests));
655
656 for (size_t test_index = 0; test_index < tests->GetSize(); ++test_index) {
657 SCOPED_TRACE(test_index);
658 base::DictionaryValue* test;
659 ASSERT_TRUE(tests->GetDictionary(test_index, &test));
660
661 blink::WebCryptoAlgorithm test_algorithm =
662 GetDigestAlgorithm(test, "algorithm");
663 std::vector<uint8> test_input = GetBytesFromHexString(test, "input");
664 std::vector<uint8> test_output = GetBytesFromHexString(test, "output");
665
666 // Test the chunk version of the digest functions. Test with 129 byte chunks
667 // because the SHA-512 chunk size is 128 bytes.
668 unsigned char* output;
669 unsigned int output_length;
670 static const size_t CHUNK_SIZE = 129;
eroman 2014/03/25 23:26:23 kChunkSizeBytes
jww 2014/03/26 00:42:31 Done.
671 size_t length = test_input.size();
672 scoped_ptr<blink::WebCryptoDigestor> digestor(
673 CreateDigestor(test_algorithm));
674 std::vector<uint8>::iterator begin = test_input.begin();
675 size_t chunk_index = 0;
676 while (begin != test_input.end()) {
677 size_t chunk_length = std::min(CHUNK_SIZE, length - chunk_index);
678 std::vector<uint8> chunk(begin, begin + chunk_length);
679 EXPECT_TRUE(digestor->consume(chunk.data(), chunk.size()));
680 chunk_index = chunk_index + chunk_length;
681 begin = begin + chunk_length;
682 }
683 EXPECT_TRUE(digestor->finish(output, output_length));
684 ExpectVectorMatches(test_output,
685 std::vector<uint8>(output, output + output_length));
686 }
687 }
688
652 TEST_F(SharedCryptoTest, HMACSampleSets) { 689 TEST_F(SharedCryptoTest, HMACSampleSets) {
653 scoped_ptr<base::ListValue> tests; 690 scoped_ptr<base::ListValue> tests;
654 ASSERT_TRUE(ReadJsonTestFileToList("hmac.json", &tests)); 691 ASSERT_TRUE(ReadJsonTestFileToList("hmac.json", &tests));
655 // TODO(padolph): Missing known answer tests for HMAC SHA384, and SHA512. 692 // TODO(padolph): Missing known answer tests for HMAC SHA384, and SHA512.
656 for (size_t test_index = 0; test_index < tests->GetSize(); ++test_index) { 693 for (size_t test_index = 0; test_index < tests->GetSize(); ++test_index) {
657 SCOPED_TRACE(test_index); 694 SCOPED_TRACE(test_index);
658 base::DictionaryValue* test; 695 base::DictionaryValue* test;
659 ASSERT_TRUE(tests->GetDictionary(test_index, &test)); 696 ASSERT_TRUE(tests->GetDictionary(test_index, &test));
660 697
661 blink::WebCryptoAlgorithm test_hash = GetDigestAlgorithm(test, "hash"); 698 blink::WebCryptoAlgorithm test_hash = GetDigestAlgorithm(test, "hash");
(...skipping 2385 matching lines...) Expand 10 before | Expand all | Expand 10 after
3047 algorithm, 3084 algorithm,
3048 CreateAesCbcAlgorithm(std::vector<uint8>(0, 16)), 3085 CreateAesCbcAlgorithm(std::vector<uint8>(0, 16)),
3049 true, 3086 true,
3050 blink::WebCryptoKeyUsageEncrypt, 3087 blink::WebCryptoKeyUsageEncrypt,
3051 &unwrapped_key)); 3088 &unwrapped_key));
3052 } 3089 }
3053 3090
3054 } // namespace webcrypto 3091 } // namespace webcrypto
3055 3092
3056 } // namespace content 3093 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698