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.

109 lines
3.8KB

  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_SHA256_JUCEHEADER__
  19. #define __JUCE_SHA256_JUCEHEADER__
  20. //==============================================================================
  21. /**
  22. SHA-256 secure hash generator.
  23. Create one of these objects from a block of source data or a stream, and it
  24. calculates the SHA-256 hash of that data.
  25. You can retrieve the hash as a raw 32-byte block, or as a 64-digit hex string.
  26. @see MD5
  27. */
  28. class JUCE_API SHA256
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates an empty SHA256 object.
  33. The default constructor just creates a hash filled with zeros. (This is not
  34. equal to the hash of an empty block of data).
  35. */
  36. SHA256() noexcept;
  37. /** Destructor. */
  38. ~SHA256() noexcept;
  39. /** Creates a copy of another SHA256. */
  40. SHA256 (const SHA256& other) noexcept;
  41. /** Copies another SHA256. */
  42. SHA256& operator= (const SHA256& other) noexcept;
  43. //==============================================================================
  44. /** Creates a hash from a block of raw data. */
  45. explicit SHA256 (const MemoryBlock& data);
  46. /** Creates a hash from a block of raw data. */
  47. SHA256 (const void* data, size_t numBytes);
  48. /** Creates a hash from the contents of a stream.
  49. This will read from the stream until the stream is exhausted, or until
  50. maxBytesToRead bytes have been read. If maxBytesToRead is negative, the entire
  51. stream will be read.
  52. */
  53. SHA256 (InputStream& input, int64 maxBytesToRead = -1);
  54. /** Reads a file and generates the hash of its contents.
  55. If the file can't be opened, the hash will be left uninitialised (i.e. full
  56. of zeros).
  57. */
  58. explicit SHA256 (const File& file);
  59. /** Creates a checksum from a UTF-8 buffer.
  60. E.g.
  61. @code SHA256 checksum (myString.toUTF8());
  62. @endcode
  63. */
  64. explicit SHA256 (const CharPointer_UTF8& utf8Text) noexcept;
  65. //==============================================================================
  66. /** Returns the hash as a 32-byte block of data. */
  67. MemoryBlock getRawData() const;
  68. /** Returns the checksum as a 64-digit hex string. */
  69. String toHexString() const;
  70. //==============================================================================
  71. bool operator== (const SHA256&) const noexcept;
  72. bool operator!= (const SHA256&) const noexcept;
  73. private:
  74. //==============================================================================
  75. uint8 result [32];
  76. void process (const void*, size_t);
  77. JUCE_LEAK_DETECTOR (SHA256);
  78. };
  79. #endif // __JUCE_SHA256_JUCEHEADER__