Imported Upstream version 9.20
[platform/upstream/7zip.git] / CPP / 7zip / Archive / Common / OutStreamWithSha1.h
1 // OutStreamWithSha1.h\r
2 \r
3 #ifndef __OUT_STREAM_WITH_SHA1_H\r
4 #define __OUT_STREAM_WITH_SHA1_H\r
5 \r
6 #include "../../Crypto/Sha1.h"\r
7 \r
8 #include "../../../Common/MyCom.h"\r
9 \r
10 #include "../../IStream.h"\r
11 \r
12 class COutStreamWithSha1:\r
13   public ISequentialOutStream,\r
14   public CMyUnknownImp\r
15 {\r
16   CMyComPtr<ISequentialOutStream> _stream;\r
17   UInt64 _size;\r
18   NCrypto::NSha1::CContext _sha;\r
19   bool _calculate;\r
20 public:\r
21   MY_UNKNOWN_IMP\r
22   STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r
23   void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r
24   void ReleaseStream() { _stream.Release(); }\r
25   void Init(bool calculate = true)\r
26   {\r
27     _size = 0;\r
28     _calculate = calculate;\r
29     _sha.Init();\r
30   }\r
31   void InitSha1() { _sha.Init(); }\r
32   UInt64 GetSize() const { return _size; }\r
33   void Final(Byte *digest) { _sha.Final(digest); }\r
34 };\r
35 \r
36 #endif\r