diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-04 19:29:58 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-04 19:29:58 +0000 |
commit | c2ad1e38df308c29d87f949fd9117341bbd6a96f (patch) | |
tree | 406cd61303883e99f63ec44b8cf4435e37b3e353 /base/sha1_unittest.cc | |
parent | 667d357e93f2dcc8afbbac71051dfedcc91daba3 (diff) | |
download | chromium_src-c2ad1e38df308c29d87f949fd9117341bbd6a96f.zip chromium_src-c2ad1e38df308c29d87f949fd9117341bbd6a96f.tar.gz chromium_src-c2ad1e38df308c29d87f949fd9117341bbd6a96f.tar.bz2 |
Implement FormStructure and an initial method, EncodeUploadRequest. This also adds SHA1HashString, a utility method to get the SHA-1 hash of an input string, with appropriate unit tests.
BUG=18201
TEST=none
Review URL: http://codereview.chromium.org/355003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30980 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/sha1_unittest.cc')
-rw-r--r-- | base/sha1_unittest.cc | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/base/sha1_unittest.cc b/base/sha1_unittest.cc new file mode 100644 index 0000000..e445e8f --- /dev/null +++ b/base/sha1_unittest.cc @@ -0,0 +1,56 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/sha1.h" + +#include <string> + +#include "base/basictypes.h" +#include "testing/gtest/include/gtest/gtest.h" + +TEST(SHA1Test, Test1) { + // Example A.1 from FIPS 180-2: one-block message. + std::string input = "abc"; + + int expected[] = { 0xa9, 0x99, 0x3e, 0x36, + 0x47, 0x06, 0x81, 0x6a, + 0xba, 0x3e, 0x25, 0x71, + 0x78, 0x50, 0xc2, 0x6c, + 0x9c, 0xd0, 0xd8, 0x9d }; + + std::string output = base::SHA1HashString(input); + for (size_t i = 0; i < base::SHA1_LENGTH; i++) + EXPECT_EQ(expected[i], output[i] & 0xFF); +} + +TEST(SHA1Test, Test2) { + // Example A.2 from FIPS 180-2: multi-block message. + std::string input = + "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; + + int expected[] = { 0x84, 0x98, 0x3e, 0x44, + 0x1c, 0x3b, 0xd2, 0x6e, + 0xba, 0xae, 0x4a, 0xa1, + 0xf9, 0x51, 0x29, 0xe5, + 0xe5, 0x46, 0x70, 0xf1 }; + + std::string output = base::SHA1HashString(input); + for (size_t i = 0; i < base::SHA1_LENGTH; i++) + EXPECT_EQ(expected[i], output[i] & 0xFF); +} + +TEST(SHA1Test, Test3) { + // Example A.3 from FIPS 180-2: long message. + std::string input(1000000, 'a'); + + int expected[] = { 0x34, 0xaa, 0x97, 0x3c, + 0xd4, 0xc4, 0xda, 0xa4, + 0xf6, 0x1e, 0xeb, 0x2b, + 0xdb, 0xad, 0x27, 0x31, + 0x65, 0x34, 0x01, 0x6f }; + + std::string output = base::SHA1HashString(input); + for (size_t i = 0; i < base::SHA1_LENGTH; i++) + EXPECT_EQ(expected[i], output[i] & 0xFF); +} |