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