| 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;
|
| +}
|
|
|