| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_MD5_H_ | 5 #ifndef BASE_MD5_H_ |
| 6 #define BASE_MD5_H_ | 6 #define BASE_MD5_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/base_api.h" | 9 #include "base/base_api.h" |
| 10 #include "base/string_piece.h" |
| 12 | 11 |
| 13 namespace base { | 12 namespace base { |
| 14 | 13 |
| 15 // MD5 stands for Message Digest algorithm 5. | 14 // MD5 stands for Message Digest algorithm 5. |
| 16 // MD5 is a robust hash function, designed for cyptography, but often used | 15 // MD5 is a robust hash function, designed for cyptography, but often used |
| 17 // for file checksums. The code is complex and slow, but has few | 16 // for file checksums. The code is complex and slow, but has few |
| 18 // collisions. | 17 // collisions. |
| 19 // See Also: | 18 // See Also: |
| 20 // http://en.wikipedia.org/wiki/MD5 | 19 // http://en.wikipedia.org/wiki/MD5 |
| 21 | 20 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 45 typedef char MD5Context[88]; | 44 typedef char MD5Context[88]; |
| 46 | 45 |
| 47 // Computes the MD5 sum of the given data buffer with the given length. | 46 // Computes the MD5 sum of the given data buffer with the given length. |
| 48 // The given 'digest' structure will be filled with the result data. | 47 // The given 'digest' structure will be filled with the result data. |
| 49 BASE_API void MD5Sum(const void* data, size_t length, MD5Digest* digest); | 48 BASE_API void MD5Sum(const void* data, size_t length, MD5Digest* digest); |
| 50 | 49 |
| 51 // Initializes the given MD5 context structure for subsequent calls to | 50 // Initializes the given MD5 context structure for subsequent calls to |
| 52 // MD5Update(). | 51 // MD5Update(). |
| 53 BASE_API void MD5Init(MD5Context* context); | 52 BASE_API void MD5Init(MD5Context* context); |
| 54 | 53 |
| 55 // For the given buffer of data, updates the given MD5 context with the sum of | 54 // For the given buffer of |data| as a StringPiece, updates the given MD5 |
| 56 // the data. You can call this any number of times during the computation, | 55 // context with the sum of the data. You can call this any number of times |
| 57 // except that MD5Init() must have been called first. | 56 // during the computation, except that MD5Init() must have been called first. |
| 58 BASE_API void MD5Update(MD5Context* context, const void* data, size_t length); | 57 BASE_API void MD5Update(MD5Context* context, const StringPiece& data); |
| 59 | 58 |
| 60 // Finalizes the MD5 operation and fills the buffer with the digest. | 59 // Finalizes the MD5 operation and fills the buffer with the digest. |
| 61 BASE_API void MD5Final(MD5Digest* digest, MD5Context* context); | 60 BASE_API void MD5Final(MD5Digest* digest, MD5Context* context); |
| 62 | 61 |
| 63 // Converts a digest into human-readable hexadecimal. | 62 // Converts a digest into human-readable hexadecimal. |
| 64 BASE_API std::string MD5DigestToBase16(const MD5Digest& digest); | 63 BASE_API std::string MD5DigestToBase16(const MD5Digest& digest); |
| 65 | 64 |
| 66 // Returns the MD5 (in hexadecimal) of a string. | 65 // Returns the MD5 (in hexadecimal) of a string. |
| 67 BASE_API std::string MD5String(const std::string& str); | 66 BASE_API std::string MD5String(const StringPiece& str); |
| 68 | 67 |
| 69 } // namespace base | 68 } // namespace base |
| 70 | 69 |
| 71 // TODO(tfarina): Fix third_party/hunspell then remove this hack. | 70 // TODO(tfarina): Fix third_party/hunspell then remove this hack. |
| 72 using base::MD5Digest; | 71 using base::MD5Digest; |
| 73 | 72 |
| 74 #endif // BASE_MD5_H_ | 73 #endif // BASE_MD5_H_ |
| OLD | NEW |