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

Unified Diff: base/sha2.cc

Issue 6276002: Abstracts SHA256 context for NSS / OpenSSL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Implements SHA256Context abstracting NSS / OpenSSL. Created 9 years, 11 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
Index: base/sha2.cc
diff --git a/base/sha2.cc b/base/sha2.cc
index c0fd0ab5d596eb7cd2e1202e32707bdd04f9cae6..709c29ef01a6fb7306f829c5be2cbea625482597 100644
--- a/base/sha2.cc
+++ b/base/sha2.cc
@@ -11,7 +11,7 @@
namespace base {
void SHA256HashString(const std::string& str, void* output, size_t len) {
- SHA256Context ctx;
+ ::SHA256Context ctx;
SHA256_Begin(&ctx);
SHA256_Update(&ctx, reinterpret_cast<const unsigned char*>(str.data()),
@@ -26,4 +26,36 @@ std::string SHA256HashString(const std::string& str) {
return output;
}
+namespace {
+
+class SHA256ContextNSS : public SHA256Context {
+ public:
+ SHA256ContextNSS() {
+ SHA256_Begin(&ctx_);
+ }
+
+ virtual ~SHA256ContextNSS() {
+ }
+
+ virtual void Update(const std::string& str) {
+ SHA256_Update(&ctx_, reinterpret_cast<const unsigned char*>(str.data()),
+ static_cast<unsigned int>(str.length()));
+
+ }
+
+ virtual void Finish(void* output, size_t len) {
+ SHA256_End(&ctx_, static_cast<unsigned char*>(output), NULL,
+ static_cast<unsigned int>(len));
+ }
+
+ private:
+ ::SHA256Context ctx_;
+};
+
+} // namespace
+
+SHA256Context* SHA256Context::Create() {
+ return new SHA256ContextNSS();
+}
+
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698