| OLD | NEW | 
|---|
| (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 } | 
| OLD | NEW | 
|---|