diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2021-12-27 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-03-18 15:35:13 +0500 |
commit | f19f813537c7aea1c20749c914e756b54a9c3cf5 (patch) | |
tree | 816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /CPP/Common/Sha1Reg.cpp | |
parent | 98e06a519b63b81986abe76d28887f6984a7732b (diff) | |
download | 7zip-21.07.tar.gz 7zip-21.07.tar.bz2 7zip-21.07.zip |
'21.07'21.07
Diffstat (limited to 'CPP/Common/Sha1Reg.cpp')
-rw-r--r-- | CPP/Common/Sha1Reg.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/CPP/Common/Sha1Reg.cpp b/CPP/Common/Sha1Reg.cpp new file mode 100644 index 0000000..0cb2baf --- /dev/null +++ b/CPP/Common/Sha1Reg.cpp | |||
@@ -0,0 +1,70 @@ | |||
1 | // Sha1Reg.cpp | ||
2 | |||
3 | #include "StdAfx.h" | ||
4 | |||
5 | #include "../../C/Sha1.h" | ||
6 | |||
7 | #include "../Common/MyBuffer2.h" | ||
8 | #include "../Common/MyCom.h" | ||
9 | |||
10 | #include "../7zip/Common/RegisterCodec.h" | ||
11 | |||
12 | class CSha1Hasher: | ||
13 | public IHasher, | ||
14 | public ICompressSetCoderProperties, | ||
15 | public CMyUnknownImp | ||
16 | { | ||
17 | CAlignedBuffer _buf; | ||
18 | Byte mtDummy[1 << 7]; | ||
19 | |||
20 | CSha1 *Sha() { return (CSha1 *)(void *)(Byte *)_buf; } | ||
21 | public: | ||
22 | CSha1Hasher(): | ||
23 | _buf(sizeof(CSha1)) | ||
24 | { | ||
25 | Sha1_SetFunction(Sha(), 0); | ||
26 | Sha1_InitState(Sha()); | ||
27 | } | ||
28 | |||
29 | MY_UNKNOWN_IMP2(IHasher, ICompressSetCoderProperties) | ||
30 | INTERFACE_IHasher(;) | ||
31 | STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps); | ||
32 | }; | ||
33 | |||
34 | STDMETHODIMP_(void) CSha1Hasher::Init() throw() | ||
35 | { | ||
36 | Sha1_InitState(Sha()); | ||
37 | } | ||
38 | |||
39 | STDMETHODIMP_(void) CSha1Hasher::Update(const void *data, UInt32 size) throw() | ||
40 | { | ||
41 | Sha1_Update(Sha(), (const Byte *)data, size); | ||
42 | } | ||
43 | |||
44 | STDMETHODIMP_(void) CSha1Hasher::Final(Byte *digest) throw() | ||
45 | { | ||
46 | Sha1_Final(Sha(), digest); | ||
47 | } | ||
48 | |||
49 | |||
50 | STDMETHODIMP CSha1Hasher::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *coderProps, UInt32 numProps) | ||
51 | { | ||
52 | unsigned algo = 0; | ||
53 | for (UInt32 i = 0; i < numProps; i++) | ||
54 | { | ||
55 | const PROPVARIANT &prop = coderProps[i]; | ||
56 | if (propIDs[i] == NCoderPropID::kDefaultProp) | ||
57 | { | ||
58 | if (prop.vt != VT_UI4) | ||
59 | return E_INVALIDARG; | ||
60 | if (prop.ulVal > 2) | ||
61 | return E_NOTIMPL; | ||
62 | algo = (unsigned)prop.ulVal; | ||
63 | } | ||
64 | } | ||
65 | if (!Sha1_SetFunction(Sha(), algo)) | ||
66 | return E_NOTIMPL; | ||
67 | return S_OK; | ||
68 | } | ||
69 | |||
70 | REGISTER_HASHER(CSha1Hasher, 0x201, "SHA1", SHA1_DIGEST_SIZE) | ||