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.

116 lines
4.2KB

  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() noexcept;
  34. /** Creates a copy of another MD5. */
  35. MD5 (const MD5& other) noexcept;
  36. /** Copies another MD5. */
  37. MD5& operator= (const MD5& other) noexcept;
  38. //==============================================================================
  39. /** Creates a checksum for a block of binary data. */
  40. explicit MD5 (const MemoryBlock& data) noexcept;
  41. /** Creates a checksum for a block of binary data. */
  42. MD5 (const void* data, size_t numBytes) noexcept;
  43. /** Creates a checksum for the input from a stream.
  44. This will read up to the given number of bytes from the stream, and produce the
  45. checksum of that. If the number of bytes to read is negative, it'll read
  46. until the stream is exhausted.
  47. */
  48. MD5 (InputStream& input, int64 numBytesToRead = -1);
  49. /** Creates a checksum for a file. */
  50. explicit MD5 (const File& file);
  51. /** Creates a checksum from a UTF-8 buffer.
  52. E.g.
  53. @code MD5 checksum (myString.toUTF8());
  54. @endcode
  55. */
  56. explicit MD5 (const CharPointer_UTF8& utf8Text) noexcept;
  57. /** Destructor. */
  58. ~MD5() noexcept;
  59. //==============================================================================
  60. /** Returns the checksum as a 16-byte block of data. */
  61. MemoryBlock getRawChecksumData() const;
  62. /** Returns a pointer to the 16-byte array of result data. */
  63. const uint8* getChecksumDataArray() const noexcept { return result; }
  64. /** Returns the checksum as a 32-digit hex string. */
  65. String toHexString() const;
  66. /** Creates an MD5 from a little-endian UTF-32 encoded string.
  67. Note that this method is provided for backwards-compatibility with the old
  68. version of this class, which had a constructor that took a string and performed
  69. this operation on it. In new code, you shouldn't use this, and are recommended to
  70. use the constructor that takes a CharPointer_UTF8 instead.
  71. */
  72. static MD5 fromUTF32 (const String&);
  73. //==============================================================================
  74. bool operator== (const MD5&) const noexcept;
  75. bool operator!= (const MD5&) const noexcept;
  76. private:
  77. //==============================================================================
  78. uint8 result [16];
  79. void processData (const void*, size_t) noexcept;
  80. void processStream (InputStream&, int64);
  81. JUCE_LEAK_DETECTOR (MD5);
  82. };
  83. #endif // __JUCE_MD5_JUCEHEADER__