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

Unified Diff: base/sha1_portable.cc

Issue 6661025: Add base::SHA1HashBytes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing wtc's comments Created 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/sha1.h ('k') | base/sha1_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sha1_portable.cc
diff --git a/base/sha1_portable.cc b/base/sha1_portable.cc
index cc05a5c91f0601ac0fbe651df7f76a3398fef862..529fc905b7a84d882e3c9fef96b5063a69f6c61a 100644
--- a/base/sha1_portable.cc
+++ b/base/sha1_portable.cc
@@ -4,6 +4,8 @@
#include "base/sha1.h"
+#include <string.h>
+
#include "base/basictypes.h"
namespace base {
@@ -195,12 +197,19 @@ void SecureHashAlgorithm::Process() {
}
std::string SHA1HashString(const std::string& str) {
+ char hash[SecureHashAlgorithm::kDigestSizeBytes];
+ SHA1HashBytes(reinterpret_cast<const unsigned char*>(str.c_str()),
+ str.length(), reinterpret_cast<unsigned char*>(hash));
+ return std::string(hash, SecureHashAlgorithm::kDigestSizeBytes);
+}
+
+void SHA1HashBytes(const unsigned char* data, size_t len,
+ unsigned char* hash) {
SecureHashAlgorithm sha;
- sha.Update(str.c_str(), str.length());
+ sha.Update(data, len);
sha.Final();
- std::string out(reinterpret_cast<const char*>(sha.Digest()),
- SecureHashAlgorithm::kDigestSizeBytes);
- return out;
+
+ memcpy(hash, sha.Digest(), SecureHashAlgorithm::kDigestSizeBytes);
}
} // namespace base
« no previous file with comments | « base/sha1.h ('k') | base/sha1_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698