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.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_MD5_H_INCLUDED
  18. #define JUCE_MD5_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. MD5 checksum class.
  22. Create one of these with a block of source data or a stream, and it calculates
  23. the MD5 checksum of that data.
  24. You can then retrieve this checksum as a 16-byte block, or as a hex string.
  25. @see SHA256
  26. */
  27. class JUCE_API MD5
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates a null MD5 object. */
  32. MD5() noexcept;
  33. /** Creates a copy of another MD5. */
  34. MD5 (const MD5& other) noexcept;
  35. /** Copies another MD5. */
  36. MD5& operator= (const MD5& other) noexcept;
  37. //==============================================================================
  38. /** Creates a checksum for a block of binary data. */
  39. explicit MD5 (const MemoryBlock& data) noexcept;
  40. /** Creates a checksum for a block of binary data. */
  41. MD5 (const void* data, size_t numBytes) noexcept;
  42. /** Creates a checksum for the input from a stream.
  43. This will read up to the given number of bytes from the stream, and produce the
  44. checksum of that. If the number of bytes to read is negative, it'll read
  45. until the stream is exhausted.
  46. */
  47. MD5 (InputStream& input, int64 numBytesToRead = -1);
  48. /** Creates a checksum for a file. */
  49. explicit MD5 (const File& file);
  50. /** Creates a checksum from a UTF-8 buffer.
  51. E.g.
  52. @code MD5 checksum (myString.toUTF8());
  53. @endcode
  54. */
  55. explicit MD5 (CharPointer_UTF8 utf8Text) noexcept;
  56. /** Destructor. */
  57. ~MD5() noexcept;
  58. //==============================================================================
  59. /** Returns the checksum as a 16-byte block of data. */
  60. MemoryBlock getRawChecksumData() const;
  61. /** Returns a pointer to the 16-byte array of result data. */
  62. const uint8* getChecksumDataArray() const noexcept { return result; }
  63. /** Returns the checksum as a 32-digit hex string. */
  64. String toHexString() const;
  65. /** Creates an MD5 from a little-endian UTF-32 encoded string.
  66. Note that this method is provided for backwards-compatibility with the old
  67. version of this class, which had a constructor that took a string and performed
  68. this operation on it. In new code, you shouldn't use this, and are recommended to
  69. use the constructor that takes a CharPointer_UTF8 instead.
  70. */
  71. static MD5 fromUTF32 (StringRef);
  72. //==============================================================================
  73. bool operator== (const MD5&) const noexcept;
  74. bool operator!= (const MD5&) const noexcept;
  75. private:
  76. //==============================================================================
  77. uint8 result [16];
  78. void processData (const void*, size_t) noexcept;
  79. void processStream (InputStream&, int64);
  80. JUCE_LEAK_DETECTOR (MD5)
  81. };
  82. #endif // JUCE_MD5_H_INCLUDED