summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-22 21:24:50 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-22 21:24:50 +0000
commitea73fc7bcc5e674c15f07b3c5704b372274ae06f (patch)
tree6523b42c6a923c0c7def207d2d0fceb6ac45917c /crypto
parent54d37a339429f6106c7a4e7deb8a67e3970a6a2b (diff)
downloadchromium_src-ea73fc7bcc5e674c15f07b3c5704b372274ae06f.zip
chromium_src-ea73fc7bcc5e674c15f07b3c5704b372274ae06f.tar.gz
chromium_src-ea73fc7bcc5e674c15f07b3c5704b372274ae06f.tar.bz2
Convert SHA256_LENGTH from a constant-in-anonymous-enum to a static const. This defines the constant where it's declared to preserve the existing readability.
Normally this makes things like DCHECK_EQ() unhappy, but when I'd originally tested this I didn't seem to need to make any changes due to that. Will be watching the trybots... The original motiviation for this change was to find a way to eliminate some cases of passing anonymous-typed values as template arguments (which happens when you use a value from the enum in e.g. EXPECT_EQ()), which is technically illegal in C++03, though we don't warn about it. Simply naming the enum would have done this, but in general naming enums used to declare constants like this is bizarre ("enum Constants { ... }"?). BUG=92247 TEST=Compiles Review URL: http://codereview.chromium.org/7823004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102369 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'crypto')
-rw-r--r--crypto/secure_hash_unittest.cc4
-rw-r--r--crypto/sha2.cc2
-rw-r--r--crypto/sha2.h4
-rw-r--r--crypto/sha2_unittest.cc16
4 files changed, 12 insertions, 14 deletions
diff --git a/crypto/secure_hash_unittest.cc b/crypto/secure_hash_unittest.cc
index 49b9da5..6ac9285 100644
--- a/crypto/secure_hash_unittest.cc
+++ b/crypto/secure_hash_unittest.cc
@@ -21,7 +21,7 @@ TEST(SecureHashTest, TestUpdate) {
0x04, 0x6d, 0x39, 0xcc,
0xc7, 0x11, 0x2c, 0xd0 };
- uint8 output3[crypto::SHA256_LENGTH];
+ uint8 output3[crypto::kSHA256Length];
scoped_ptr<crypto::SecureHash> ctx(crypto::SecureHash::Create(
crypto::SecureHash::SHA256));
@@ -29,6 +29,6 @@ TEST(SecureHashTest, TestUpdate) {
ctx->Update(input3.data(), input3.size());
ctx->Finish(output3, sizeof(output3));
- for (size_t i = 0; i < crypto::SHA256_LENGTH; i++)
+ for (size_t i = 0; i < crypto::kSHA256Length; i++)
EXPECT_EQ(expected3[i], static_cast<int>(output3[i]));
}
diff --git a/crypto/sha2.cc b/crypto/sha2.cc
index a757df6..da51cc5 100644
--- a/crypto/sha2.cc
+++ b/crypto/sha2.cc
@@ -17,7 +17,7 @@ void SHA256HashString(const std::string& str, void* output, size_t len) {
}
std::string SHA256HashString(const std::string& str) {
- std::string output(SHA256_LENGTH, 0);
+ std::string output(kSHA256Length, 0);
SHA256HashString(str, string_as_array(&output), output.size());
return output;
}
diff --git a/crypto/sha2.h b/crypto/sha2.h
index 18acf2b..6b2f83c 100644
--- a/crypto/sha2.h
+++ b/crypto/sha2.h
@@ -16,9 +16,7 @@ namespace crypto {
//
// Functions for SHA-384 and SHA-512 can be added when the need arises.
-enum {
- SHA256_LENGTH = 32 // length in bytes of a SHA-256 hash
-};
+static const size_t kSHA256Length = 32; // length in bytes of a SHA-256 hash
// Computes the SHA-256 hash of the input string 'str' and stores the first
// 'len' bytes of the hash in the output buffer 'output'. If 'len' > 32,
diff --git a/crypto/sha2_unittest.cc b/crypto/sha2_unittest.cc
index 8a28a5b..78da136 100644
--- a/crypto/sha2_unittest.cc
+++ b/crypto/sha2_unittest.cc
@@ -19,9 +19,9 @@ TEST(Sha256Test, Test1) {
0xb4, 0x10, 0xff, 0x61,
0xf2, 0x00, 0x15, 0xad };
- uint8 output1[crypto::SHA256_LENGTH];
+ uint8 output1[crypto::kSHA256Length];
crypto::SHA256HashString(input1, output1, sizeof(output1));
- for (size_t i = 0; i < crypto::SHA256_LENGTH; i++)
+ for (size_t i = 0; i < crypto::kSHA256Length; i++)
EXPECT_EQ(expected1[i], static_cast<int>(output1[i]));
uint8 output_truncated1[4]; // 4 bytes == 32 bits
@@ -45,8 +45,8 @@ TEST(Sha256Test, Test1_String) {
0xf2, 0x00, 0x15, 0xad };
std::string output1 = crypto::SHA256HashString(input1);
- ASSERT_EQ(crypto::SHA256_LENGTH, output1.size());
- for (size_t i = 0; i < crypto::SHA256_LENGTH; i++)
+ ASSERT_EQ(crypto::kSHA256Length, output1.size());
+ for (size_t i = 0; i < crypto::kSHA256Length; i++)
EXPECT_EQ(expected1[i], static_cast<uint8>(output1[i]));
}
@@ -63,9 +63,9 @@ TEST(Sha256Test, Test2) {
0xf6, 0xec, 0xed, 0xd4,
0x19, 0xdb, 0x06, 0xc1 };
- uint8 output2[crypto::SHA256_LENGTH];
+ uint8 output2[crypto::kSHA256Length];
crypto::SHA256HashString(input2, output2, sizeof(output2));
- for (size_t i = 0; i < crypto::SHA256_LENGTH; i++)
+ for (size_t i = 0; i < crypto::kSHA256Length; i++)
EXPECT_EQ(expected2[i], static_cast<int>(output2[i]));
uint8 output_truncated2[6];
@@ -87,9 +87,9 @@ TEST(Sha256Test, Test3) {
0x04, 0x6d, 0x39, 0xcc,
0xc7, 0x11, 0x2c, 0xd0 };
- uint8 output3[crypto::SHA256_LENGTH];
+ uint8 output3[crypto::kSHA256Length];
crypto::SHA256HashString(input3, output3, sizeof(output3));
- for (size_t i = 0; i < crypto::SHA256_LENGTH; i++)
+ for (size_t i = 0; i < crypto::kSHA256Length; i++)
EXPECT_EQ(expected3[i], static_cast<int>(output3[i]));
uint8 output_truncated3[12];