summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-19 11:22:38 +0000
committerjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-19 11:22:38 +0000
commit9a8b16173c117f60cc6e0eea400e38164f2f1bf5 (patch)
treefb4f20ee2e48952739036e743041f16ad3c2f45e
parent29eb3f3c55cc13e0c6cd96ff1482b7c94574e259 (diff)
downloadchromium_src-9a8b16173c117f60cc6e0eea400e38164f2f1bf5.zip
chromium_src-9a8b16173c117f60cc6e0eea400e38164f2f1bf5.tar.gz
chromium_src-9a8b16173c117f60cc6e0eea400e38164f2f1bf5.tar.bz2
Remove direct dependency of extensions on NSS library
BUG=None TEST=ExtensionTest.GenerateId Review URL: http://codereview.chromium.org/3851004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63042 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/common/extensions/extension.cc10
-rw-r--r--chrome/common/extensions/extension_unittest.cc15
2 files changed, 18 insertions, 7 deletions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 0d1b8be..f86a910 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -14,10 +14,10 @@
#include "base/file_util.h"
#include "base/i18n/rtl.h"
#include "base/logging.h"
+#include "base/sha2.h"
#include "base/singleton.h"
#include "base/stl_util-inl.h"
#include "base/third_party/nss/blapi.h"
-#include "base/third_party/nss/sha256.h"
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
@@ -463,15 +463,11 @@ GURL Extension::GetResourceURL(const GURL& extension_url,
bool Extension::GenerateId(const std::string& input, std::string* output) {
CHECK(output);
- if (input.length() == 0)
+ if (input.empty())
return false;
- const uint8* ubuf = reinterpret_cast<const unsigned char*>(input.data());
- SHA256Context ctx;
- SHA256_Begin(&ctx);
- SHA256_Update(&ctx, ubuf, input.length());
uint8 hash[Extension::kIdSize];
- SHA256_End(&ctx, hash, NULL, sizeof(hash));
+ base::SHA256HashString(input, hash, sizeof(hash));
*output = StringToLowerASCII(base::HexEncode(hash, sizeof(hash)));
ConvertHexadecimalToIDAlphabet(output);
diff --git a/chrome/common/extensions/extension_unittest.cc b/chrome/common/extensions/extension_unittest.cc
index 4b8b8c8..d2a7049 100644
--- a/chrome/common/extensions/extension_unittest.cc
+++ b/chrome/common/extensions/extension_unittest.cc
@@ -1142,3 +1142,18 @@ TEST(ExtensionTest, GetDistinctHosts) {
Extension::GetDistinctHosts(actual));
}
}
+
+TEST(ExtensionTest, GenerateId) {
+ std::string result;
+ EXPECT_FALSE(Extension::GenerateId("", &result));
+
+ EXPECT_TRUE(Extension::GenerateId("test", &result));
+ EXPECT_EQ(result, "jpignaibiiemhngfjkcpokkamffknabf");
+
+ EXPECT_TRUE(Extension::GenerateId("_", &result));
+ EXPECT_EQ(result, "ncocknphbhhlhkikpnnlmbcnbgdempcd");
+
+ EXPECT_TRUE(Extension::GenerateId(
+ "this_string_is_longer_than_a_single_sha256_hash_digest", &result));
+ EXPECT_EQ(result, "jimneklojkjdibfkgiiophfhjhbdgcfi");
+}