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

Unified Diff: base/md5.cc

Issue 7466003: MD5Update function uses StringPiece instead of raw buffer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove line from license. Created 9 years, 5 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/md5.h ('k') | base/md5_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/md5.cc
diff --git a/base/md5.cc b/base/md5.cc
index 2211a285e5badf8ef181c3910b10c73e347be4ce..754994c0e562b45b2bc4b90cc2a7c612d14ec5a7 100644
--- a/base/md5.cc
+++ b/base/md5.cc
@@ -1,5 +1,8 @@
+// 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.
+
// The original file was copied from sqlite, and was in the public domain.
-// Modifications Copyright 2006 Google Inc. All Rights Reserved
/*
* This code implements the MD5 message-digest algorithm.
@@ -164,7 +167,9 @@ void MD5Init(MD5Context* context) {
* Update context to reflect the concatenation of another buffer full
* of bytes.
*/
-void MD5Update(MD5Context* context, const void* inbuf, size_t len) {
+void MD5Update(MD5Context* context, const StringPiece& data) {
+ const unsigned char* inbuf = (const unsigned char*)data.data();
+ size_t len = data.size();
struct Context *ctx = (struct Context *)context;
const unsigned char* buf = (const unsigned char*)inbuf;
uint32 t;
@@ -273,11 +278,12 @@ std::string MD5DigestToBase16(const MD5Digest& digest) {
void MD5Sum(const void* data, size_t length, MD5Digest* digest) {
MD5Context ctx;
MD5Init(&ctx);
- MD5Update(&ctx, static_cast<const unsigned char*>(data), length);
+ MD5Update(&ctx,
+ StringPiece(reinterpret_cast<const char*>(data), length));
MD5Final(digest, &ctx);
}
-std::string MD5String(const std::string& str) {
+std::string MD5String(const StringPiece& str) {
MD5Digest digest;
MD5Sum(str.data(), str.length(), &digest);
return MD5DigestToBase16(digest);
« no previous file with comments | « base/md5.h ('k') | base/md5_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698