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

Unified Diff: base/secure_hash_nss.cc

Issue 6276002: Abstracts SHA256 context for NSS / OpenSSL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moves to SecureHash (and other comments) 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/secure_hash_nss.cc
diff --git a/base/secure_hash_nss.cc b/base/secure_hash_nss.cc
new file mode 100644
index 0000000000000000000000000000000000000000..900404362ad44739c2cfddcf39931de452e8b6e1
--- /dev/null
+++ b/base/secure_hash_nss.cc
@@ -0,0 +1,49 @@
+// Copyright (c) 2006-2008 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/secure_hash.h"
+
+#include "base/logging.h"
+#include "base/stl_util-inl.h"
wtc 2011/01/25 19:06:43 Remove this header.
bulach 2011/01/25 20:33:41 Done.
+#include "base/third_party/nss/blapi.h"
+#include "base/third_party/nss/sha256.h"
+
+namespace base {
+
+namespace {
+
+class SecureHashSHA256NSS : public SecureHash {
+ public:
+ SecureHashSHA256NSS() {
+ SHA256_Begin(&ctx_);
+ }
+
+ virtual ~SecureHashSHA256NSS() {
+ }
+
+ 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_;
wtc 2011/01/25 19:06:43 Nit: you can remove :: now.
bulach 2011/01/25 20:33:41 Done.
+};
+
+} // namespace
+
+SecureHash* SecureHash::Create(Type type) {
+ if (type == TYPE_SHA256)
+ return new SecureHashSHA256NSS();
+ NOTIMPLEMENTED();
+ return NULL;
wtc 2011/01/25 19:06:43 Please use a switch statement to make it easy to a
bulach 2011/01/25 20:33:41 Done.
+}
+
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698