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

Unified Diff: crypto/md5_calculator.cc

Issue 6873156: Move crypto_helpers from sync to base (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Move crypto_helpers to crypto instead of base. Created 9 years, 8 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: crypto/md5_calculator.cc
diff --git a/crypto/md5_calculator.cc b/crypto/md5_calculator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1b77a081033e0ce4c21a461bc73705ed80d6e742
--- /dev/null
+++ b/crypto/md5_calculator.cc
@@ -0,0 +1,44 @@
+// Copyright (c) 2011 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 "crypto/md5_calculator.h"
+
+#include <string>
+#include <vector>
+
+#include "base/format_macros.h"
+#include "base/logging.h"
+
+MD5Calculator::MD5Calculator() {
+ MD5Init(&context_);
+}
+
+MD5Calculator::~MD5Calculator() {}
+
+void MD5Calculator::AddData(const unsigned char* data, int length) {
+ CHECK(bin_digest_.empty());
+ MD5Update(&context_, data, length);
+}
+
+void MD5Calculator::CalcDigest() {
+ if (bin_digest_.empty()) {
+ MD5Digest digest;
+ MD5Final(&digest, &context_);
+ bin_digest_.assign(digest.a, digest.a + arraysize(digest.a));
+ }
+}
+
+const std::vector<uint8>& MD5Calculator::GetDigest() {
+ CalcDigest();
+ return bin_digest_;
+}
+
+std::string MD5Calculator::GetHexDigest() {
+ CalcDigest();
+ std::string hex =
+ base::HexEncode(reinterpret_cast<char*>(&bin_digest_.front()),
+ bin_digest_.size());
+ StringToLowerASCII(&hex);
+ return hex;
+}

Powered by Google App Engine
This is Rietveld 408576698