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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "crypto/md5_calculator.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/format_macros.h"
11 #include "base/logging.h"
12
13 MD5Calculator::MD5Calculator() {
14 MD5Init(&context_);
15 }
16
17 MD5Calculator::~MD5Calculator() {}
18
19 void MD5Calculator::AddData(const unsigned char* data, int length) {
20 CHECK(bin_digest_.empty());
21 MD5Update(&context_, data, length);
22 }
23
24 void MD5Calculator::CalcDigest() {
25 if (bin_digest_.empty()) {
26 MD5Digest digest;
27 MD5Final(&digest, &context_);
28 bin_digest_.assign(digest.a, digest.a + arraysize(digest.a));
29 }
30 }
31
32 const std::vector<uint8>& MD5Calculator::GetDigest() {
33 CalcDigest();
34 return bin_digest_;
35 }
36
37 std::string MD5Calculator::GetHexDigest() {
38 CalcDigest();
39 std::string hex =
40 base::HexEncode(reinterpret_cast<char*>(&bin_digest_.front()),
41 bin_digest_.size());
42 StringToLowerASCII(&hex);
43 return hex;
44 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698