1 // OutStreamWithSha1.h 2 3 #ifndef ZIP7_INC_OUT_STREAM_WITH_SHA1_H 4 #define ZIP7_INC_OUT_STREAM_WITH_SHA1_H 5 6 #include "../../../../C/Sha1.h" 7 8 #include "../../../Common/MyBuffer2.h" 9 #include "../../../Common/MyCom.h" 10 11 #include "../../IStream.h" 12 13 Z7_CLASS_IMP_NOQIB_1( 14 COutStreamWithSha1 15 , ISequentialOutStream 16 ) 17 bool _calculate; 18 CMyComPtr<ISequentialOutStream> _stream; 19 CAlignedBuffer1 _sha; 20 UInt64 _size; 21 Sha()22 CSha1 *Sha() { return (CSha1 *)(void *)(Byte *)_sha; } 23 public: COutStreamWithSha1()24 COutStreamWithSha1(): _sha(sizeof(CSha1)) {} SetStream(ISequentialOutStream * stream)25 void SetStream(ISequentialOutStream *stream) { _stream = stream; } ReleaseStream()26 void ReleaseStream() { _stream.Release(); } 27 void Init(bool calculate = true) 28 { 29 _calculate = calculate; 30 _size = 0; 31 Sha1_Init(Sha()); 32 } InitSha1()33 void InitSha1() { Sha1_Init(Sha()); } GetSize()34 UInt64 GetSize() const { return _size; } Final(Byte * digest)35 void Final(Byte *digest) { Sha1_Final(Sha(), digest); } 36 }; 37 38 39 Z7_CLASS_IMP_NOQIB_1( 40 CInStreamWithSha1 41 , ISequentialInStream 42 ) 43 CMyComPtr<ISequentialInStream> _stream; 44 CAlignedBuffer1 _sha; 45 UInt64 _size; 46 47 CSha1 *Sha() { return (CSha1 *)(void *)(Byte *)_sha; } 48 public: 49 CInStreamWithSha1(): _sha(sizeof(CSha1)) {} 50 void SetStream(ISequentialInStream *stream) { _stream = stream; } 51 void Init() 52 { 53 _size = 0; 54 Sha1_Init(Sha()); 55 } 56 void ReleaseStream() { _stream.Release(); } 57 UInt64 GetSize() const { return _size; } 58 void Final(Byte *digest) { Sha1_Final(Sha(), digest); } 59 }; 60 61 #endif 62