The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_MD5_JUCEHEADER__
  19. #define __JUCE_MD5_JUCEHEADER__
  20. //==============================================================================
  21. /**
  22. MD5 checksum class.
  23. Create one of these with a block of source data or a stream, and it calculates
  24. the MD5 checksum of that data.
  25. You can then retrieve this checksum as a 16-byte block, or as a hex string.
  26. @see SHA256
  27. */
  28. class JUCE_API MD5
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates a null MD5 object. */
  33. MD5();
  34. /** Creates a copy of another MD5. */
  35. MD5 (const MD5& other);
  36. /** Copies another MD5. */
  37. MD5& operator= (const MD5& other);
  38. //==============================================================================
  39. /** Creates a checksum for a block of binary data. */
  40. explicit MD5 (const MemoryBlock& data);
  41. /** Creates a checksum for a block of binary data. */
  42. MD5 (const void* data, size_t numBytes);
  43. /** Creates a checksum for a string.
  44. Note that this operates on the string as a block of unicode characters, so the
  45. result you get will differ from the value you'd get if the string was treated
  46. as a block of utf8 or ascii. Bear this in mind if you're comparing the result
  47. of this method with a checksum created by a different framework, which may have
  48. used a different encoding.
  49. */
  50. explicit MD5 (const String& text);
  51. /** Creates a checksum for the input from a stream.
  52. This will read up to the given number of bytes from the stream, and produce the
  53. checksum of that. If the number of bytes to read is negative, it'll read
  54. until the stream is exhausted.
  55. */
  56. MD5 (InputStream& input, int64 numBytesToRead = -1);
  57. /** Creates a checksum for a file. */
  58. explicit MD5 (const File& file);
  59. /** Destructor. */
  60. ~MD5();
  61. //==============================================================================
  62. /** Returns the checksum as a 16-byte block of data. */
  63. MemoryBlock getRawChecksumData() const;
  64. /** Returns the checksum as a 32-digit hex string. */
  65. String toHexString() const;
  66. //==============================================================================
  67. /** Compares this to another MD5. */
  68. bool operator== (const MD5& other) const;
  69. /** Compares this to another MD5. */
  70. bool operator!= (const MD5& other) const;
  71. private:
  72. //==============================================================================
  73. uint8 result [16];
  74. struct ProcessContext
  75. {
  76. uint8 buffer [64];
  77. uint32 state [4];
  78. uint32 count [2];
  79. ProcessContext();
  80. void processBlock (const void* data, size_t dataSize);
  81. void transform (const void* buffer);
  82. void finish (void* result);
  83. };
  84. void processStream (InputStream&, int64 numBytesToRead);
  85. JUCE_LEAK_DETECTOR (MD5);
  86. };
  87. #endif // __JUCE_MD5_JUCEHEADER__