Fix crash when host does not support midi-in; Add missing file
[juce-lv2.git] / juce / source / src / cryptography / juce_MD5.h
blob581fceace5976741799ea75b61dec8ef7a7bb27a
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCE_MD5_JUCEHEADER__
27 #define __JUCE_MD5_JUCEHEADER__
29 #include "../memory/juce_MemoryBlock.h"
30 #include "../io/streams/juce_InputStream.h"
31 #include "../io/files/juce_File.h"
34 //==============================================================================
35 /**
36 MD5 checksum class.
38 Create one of these with a block of source data or a string, and it calculates the
39 MD5 checksum of that data.
41 You can then retrieve this checksum as a 16-byte block, or as a hex string.
43 class JUCE_API MD5
45 public:
46 //==============================================================================
47 /** Creates a null MD5 object. */
48 MD5();
50 /** Creates a copy of another MD5. */
51 MD5 (const MD5& other);
53 /** Copies another MD5. */
54 MD5& operator= (const MD5& other);
56 //==============================================================================
57 /** Creates a checksum for a block of binary data. */
58 explicit MD5 (const MemoryBlock& data);
60 /** Creates a checksum for a block of binary data. */
61 MD5 (const void* data, size_t numBytes);
63 /** Creates a checksum for a string.
65 Note that this operates on the string as a block of unicode characters, so the
66 result you get will differ from the value you'd get if the string was treated
67 as a block of utf8 or ascii. Bear this in mind if you're comparing the result
68 of this method with a checksum created by a different framework, which may have
69 used a different encoding.
71 explicit MD5 (const String& text);
73 /** Creates a checksum for the input from a stream.
75 This will read up to the given number of bytes from the stream, and produce the
76 checksum of that. If the number of bytes to read is negative, it'll read
77 until the stream is exhausted.
79 MD5 (InputStream& input, int64 numBytesToRead = -1);
81 /** Creates a checksum for a file. */
82 explicit MD5 (const File& file);
84 /** Destructor. */
85 ~MD5();
87 //==============================================================================
88 /** Returns the checksum as a 16-byte block of data. */
89 MemoryBlock getRawChecksumData() const;
91 /** Returns the checksum as a 32-digit hex string. */
92 String toHexString() const;
95 //==============================================================================
96 /** Compares this to another MD5. */
97 bool operator== (const MD5& other) const;
99 /** Compares this to another MD5. */
100 bool operator!= (const MD5& other) const;
103 private:
104 //==============================================================================
105 uint8 result [16];
107 struct ProcessContext
109 uint8 buffer [64];
110 uint32 state [4];
111 uint32 count [2];
113 ProcessContext();
115 void processBlock (const void* data, size_t dataSize);
116 void transform (const void* buffer);
117 void finish (void* result);
120 void processStream (InputStream&, int64 numBytesToRead);
122 JUCE_LEAK_DETECTOR (MD5);
126 #endif // __JUCE_MD5_JUCEHEADER__