src/stream/ZStream_MD5.h

00001 /*  @(#) $Id: ZStream_MD5.h,v 1.9 2006/04/10 20:44:21 agreen Exp $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2000 Andrew Green and Learning in Motion, Inc.
00005 http://www.zoolib.org
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020 COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023 ------------------------------------------------------------ */
00024 
00025 #ifndef __ZStream_MD5__
00026 #define __ZStream_MD5__ 1
00027 #include "zconfig.h"
00028 #include "ZCONFIG_SPI.h"
00029 
00030 #ifndef ZCONFIG_StreamMD5_UseOpenSSL
00031 #       define ZCONFIG_StreamMD5_UseOpenSSL ZCONFIG_SPI_Enabled(openssl)
00032 #endif
00033 
00034 #include "ZStream.h"
00035 
00036 // =================================================================================================
00037 #pragma mark -
00038 #pragma mark * ZStream_MD5
00039 
00040 #if ZCONFIG_StreamMD5_UseOpenSSL
00041 #       include <openssl/md5.h>
00042 #endif
00043 
00044 namespace ZStream_MD5 {
00045 
00046 #if ZCONFIG_StreamMD5_UseOpenSSL
00047 
00048 typedef MD5_CTX Context;
00049 
00050 #else // ZCONFIG_StreamMD5_UseOpenSSL
00051 
00052 struct Context
00053         {
00054         uint32 fState[4];
00055         size_t fSpaceUsed;
00056         size_t fBuffersSent;
00057         union
00058                 {
00059                 uint32 fBuffer32[16];
00060                 uint8 fBuffer8[64];
00061                 };
00062         };
00063 
00064 #endif // ZCONFIG_StreamMD5_UseOpenSSL
00065 
00066 void sInit(Context& oContext);
00067 void sUpdate(Context& ioContext, const void* iData, size_t iCount);
00068 void sFinal(Context& ioContext, uint8 oDigest[16]);
00069 
00070 } // namespace ZStream_MD5
00071 
00072 // =================================================================================================
00073 #pragma mark -
00074 #pragma mark * ZStreamR_MD5
00075 
00077 
00078 class ZStreamR_MD5 : public ZStreamR
00079         {
00080 public:
00081         ZStreamR_MD5(const ZStreamR& iStreamSource);
00082         ZStreamR_MD5(uint8 oDigest[16], const ZStreamR& iStreamSource);
00083         ~ZStreamR_MD5();
00084 
00085 // From ZStreamR
00086         virtual void Imp_Read(void* iDest, size_t iCount, size_t* oCountRead);
00087         virtual size_t Imp_CountReadable();
00088 
00089 // Our protocol
00090         void GetDigest(uint8 oDigest[16]);
00091 
00092 protected:
00093         const ZStreamR& fStreamSource;
00094         ZStream_MD5::Context fContext;
00095         uint8* fDigest;
00096         };
00097 
00098 // =================================================================================================
00099 #pragma mark -
00100 #pragma mark * ZStreamW_MD5
00101 
00103 
00104 class ZStreamW_MD5 : public ZStreamW
00105         {
00106 public:
00107         ZStreamW_MD5(const ZStreamW& iStreamSink);
00108         ZStreamW_MD5(uint8 oDigest[16], const ZStreamW& iStreamSink);
00109         ~ZStreamW_MD5();
00110 
00111 // From ZStreamW
00112         virtual void Imp_Write(const void* iSource, size_t iCount, size_t* oCountWritten);
00113         virtual void Imp_Flush();
00114 
00115 // Our protocol
00116         void GetDigest(uint8 oDigest[16]);
00117 
00118 protected:
00119         const ZStreamW& fStreamSink;
00120         ZStream_MD5::Context fContext;
00121         uint8* fDigest;
00122         };
00123 
00124 // =================================================================================================
00125 
00126 #endif // __ZStream_MD5__

Generated on Thu Jul 26 11:21:53 2007 for ZooLib by  doxygen 1.4.7