| OLD | NEW |
| 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 "base/base64.h" | 5 #include "base/base64.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "crypto/sha2.h" | 8 #include "crypto/sha2.h" |
| 9 #include "extensions/browser/computed_hashes.h" | 9 #include "extensions/browser/computed_hashes.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 EXPECT_EQ(hashes2, read_hashes2); | 71 EXPECT_EQ(hashes2, read_hashes2); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Note: the expected hashes used in this test were generated using linux | 74 // Note: the expected hashes used in this test were generated using linux |
| 75 // command line tools. E.g., from a bash prompt: | 75 // command line tools. E.g., from a bash prompt: |
| 76 // $ printf "hello world" | openssl dgst -sha256 -binary | base64 | 76 // $ printf "hello world" | openssl dgst -sha256 -binary | base64 |
| 77 // | 77 // |
| 78 // The file with multiple-blocks expectations were generated by doing: | 78 // The file with multiple-blocks expectations were generated by doing: |
| 79 // $ for i in `seq 500 ; do printf "hello world" ; done > hello.txt | 79 // $ for i in `seq 500 ; do printf "hello world" ; done > hello.txt |
| 80 // $ dd if=hello.txt bs=4096 count=1 | openssl dgst -sha256 -binary | base64 | 80 // $ dd if=hello.txt bs=4096 count=1 | openssl dgst -sha256 -binary | base64 |
| 81 // $ dd if=hello.txt skip=1 bs=4096 count=1 | \ | 81 // $ dd if=hello.txt skip=1 bs=4096 count=1 | |
| 82 // openssl dgst -sha256 -binary | base64 | 82 // openssl dgst -sha256 -binary | base64 |
| 83 TEST(ComputedHashes, ComputeHashesForContent) { | 83 TEST(ComputedHashes, ComputeHashesForContent) { |
| 84 const int block_size = 4096; | 84 const int block_size = 4096; |
| 85 | 85 |
| 86 // Simple short input. | 86 // Simple short input. |
| 87 std::string content1 = "hello world"; | 87 std::string content1 = "hello world"; |
| 88 std::string content1_expected_hash = | 88 std::string content1_expected_hash = |
| 89 "uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="; | 89 "uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="; |
| 90 std::vector<std::string> hashes1; | 90 std::vector<std::string> hashes1; |
| 91 ComputedHashes::ComputeHashesForContent(content1, block_size, &hashes1); | 91 ComputedHashes::ComputeHashesForContent(content1, block_size, &hashes1); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 108 // Now an empty input. | 108 // Now an empty input. |
| 109 std::string content3; | 109 std::string content3; |
| 110 std::vector<std::string> hashes3; | 110 std::vector<std::string> hashes3; |
| 111 ComputedHashes::ComputeHashesForContent(content3, block_size, &hashes3); | 111 ComputedHashes::ComputeHashesForContent(content3, block_size, &hashes3); |
| 112 ASSERT_EQ(1u, hashes3.size()); | 112 ASSERT_EQ(1u, hashes3.size()); |
| 113 ASSERT_EQ(std::string("47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU="), | 113 ASSERT_EQ(std::string("47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU="), |
| 114 Base64Encode(hashes3[0])); | 114 Base64Encode(hashes3[0])); |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace extensions | 117 } // namespace extensions |
| OLD | NEW |