aboutsummaryrefslogtreecommitdiff
path: root/CPP/Common
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/Common/Md5Reg.cpp44
-rw-r--r--CPP/Common/MyCom.h37
-rw-r--r--CPP/Common/MyString.cpp29
-rw-r--r--CPP/Common/MyString.h13
-rw-r--r--CPP/Common/MyXml.cpp4
-rw-r--r--CPP/Common/Sha3Reg.cpp76
-rw-r--r--CPP/Common/Sha512Prepare.cpp7
-rw-r--r--CPP/Common/Sha512Reg.cpp83
-rw-r--r--CPP/Common/Wildcard.cpp13
9 files changed, 263 insertions, 43 deletions
diff --git a/CPP/Common/Md5Reg.cpp b/CPP/Common/Md5Reg.cpp
new file mode 100644
index 0000000..026fd41
--- /dev/null
+++ b/CPP/Common/Md5Reg.cpp
@@ -0,0 +1,44 @@
1// Md5Reg.cpp
2
3#include "StdAfx.h"
4
5#include "../../C/Md5.h"
6
7#include "../Common/MyBuffer2.h"
8#include "../Common/MyCom.h"
9
10#include "../7zip/Common/RegisterCodec.h"
11
12Z7_CLASS_IMP_COM_1(
13 CMd5Hasher
14 , IHasher
15)
16 CAlignedBuffer1 _buf;
17public:
18 Byte _mtDummy[1 << 7];
19
20 CMd5 *Md5() { return (CMd5 *)(void *)(Byte *)_buf; }
21public:
22 CMd5Hasher():
23 _buf(sizeof(CMd5))
24 {
25 Md5_Init(Md5());
26 }
27};
28
29Z7_COM7F_IMF2(void, CMd5Hasher::Init())
30{
31 Md5_Init(Md5());
32}
33
34Z7_COM7F_IMF2(void, CMd5Hasher::Update(const void *data, UInt32 size))
35{
36 Md5_Update(Md5(), (const Byte *)data, size);
37}
38
39Z7_COM7F_IMF2(void, CMd5Hasher::Final(Byte *digest))
40{
41 Md5_Final(Md5(), digest);
42}
43
44REGISTER_HASHER(CMd5Hasher, 0x208, "MD5", MD5_DIGEST_SIZE)
diff --git a/CPP/Common/MyCom.h b/CPP/Common/MyCom.h
index a3cc3c8..7dc21ba 100644
--- a/CPP/Common/MyCom.h
+++ b/CPP/Common/MyCom.h
@@ -468,6 +468,19 @@ EXTERN_C_END
468 Z7_COM_QI_ENTRY(i7) \ 468 Z7_COM_QI_ENTRY(i7) \
469 ) 469 )
470 470
471#define Z7_COM_UNKNOWN_IMP_8(i1, i2, i3, i4, i5, i6, i7, i8) \
472 Z7_COM_UNKNOWN_IMP_SPEC( \
473 Z7_COM_QI_ENTRY_UNKNOWN(i1) \
474 Z7_COM_QI_ENTRY(i1) \
475 Z7_COM_QI_ENTRY(i2) \
476 Z7_COM_QI_ENTRY(i3) \
477 Z7_COM_QI_ENTRY(i4) \
478 Z7_COM_QI_ENTRY(i5) \
479 Z7_COM_QI_ENTRY(i6) \
480 Z7_COM_QI_ENTRY(i7) \
481 Z7_COM_QI_ENTRY(i8) \
482 )
483
471 484
472#define Z7_IFACES_IMP_UNK_1(i1) \ 485#define Z7_IFACES_IMP_UNK_1(i1) \
473 Z7_COM_UNKNOWN_IMP_1(i1) \ 486 Z7_COM_UNKNOWN_IMP_1(i1) \
@@ -508,6 +521,16 @@ EXTERN_C_END
508 Z7_IFACE_COM7_IMP(i5) \ 521 Z7_IFACE_COM7_IMP(i5) \
509 Z7_IFACE_COM7_IMP(i6) \ 522 Z7_IFACE_COM7_IMP(i6) \
510 523
524#define Z7_IFACES_IMP_UNK_7(i1, i2, i3, i4, i5, i6, i7) \
525 Z7_COM_UNKNOWN_IMP_7(i1, i2, i3, i4, i5, i6, i7) \
526 Z7_IFACE_COM7_IMP(i1) \
527 Z7_IFACE_COM7_IMP(i2) \
528 Z7_IFACE_COM7_IMP(i3) \
529 Z7_IFACE_COM7_IMP(i4) \
530 Z7_IFACE_COM7_IMP(i5) \
531 Z7_IFACE_COM7_IMP(i6) \
532 Z7_IFACE_COM7_IMP(i7) \
533
511 534
512#define Z7_CLASS_IMP_COM_0(c) \ 535#define Z7_CLASS_IMP_COM_0(c) \
513 Z7_class_final(c) : \ 536 Z7_class_final(c) : \
@@ -574,6 +597,20 @@ EXTERN_C_END
574 private: 597 private:
575 598
576 599
600#define Z7_CLASS_IMP_COM_7(c, i1, i2, i3, i4, i5, i6, i7) \
601 Z7_class_final(c) : \
602 public i1, \
603 public i2, \
604 public i3, \
605 public i4, \
606 public i5, \
607 public i6, \
608 public i7, \
609 public CMyUnknownImp { \
610 Z7_IFACES_IMP_UNK_7(i1, i2, i3, i4, i5, i6, i7) \
611 private:
612
613
577/* 614/*
578#define Z7_CLASS_IMP_NOQIB_0(c) \ 615#define Z7_CLASS_IMP_NOQIB_0(c) \
579 Z7_class_final(c) : \ 616 Z7_class_final(c) : \
diff --git a/CPP/Common/MyString.cpp b/CPP/Common/MyString.cpp
index b5f7e52..10e2331 100644
--- a/CPP/Common/MyString.cpp
+++ b/CPP/Common/MyString.cpp
@@ -208,35 +208,6 @@ bool StringsAreEqualNoCase(const wchar_t *s1, const wchar_t *s2) throw()
208 208
209// ---------- ASCII ---------- 209// ---------- ASCII ----------
210 210
211bool AString::IsPrefixedBy_Ascii_NoCase(const char *s) const throw()
212{
213 const char *s1 = _chars;
214 for (;;)
215 {
216 const char c2 = *s++;
217 if (c2 == 0)
218 return true;
219 const char c1 = *s1++;
220 if (MyCharLower_Ascii(c1) !=
221 MyCharLower_Ascii(c2))
222 return false;
223 }
224}
225
226bool UString::IsPrefixedBy_Ascii_NoCase(const char *s) const throw()
227{
228 const wchar_t *s1 = _chars;
229 for (;;)
230 {
231 const char c2 = *s++;
232 if (c2 == 0)
233 return true;
234 const wchar_t c1 = *s1++;
235 if (MyCharLower_Ascii(c1) != (unsigned char)MyCharLower_Ascii(c2))
236 return false;
237 }
238}
239
240bool StringsAreEqual_Ascii(const char *u, const char *a) throw() 211bool StringsAreEqual_Ascii(const char *u, const char *a) throw()
241{ 212{
242 for (;;) 213 for (;;)
diff --git a/CPP/Common/MyString.h b/CPP/Common/MyString.h
index ba9914e..639b874 100644
--- a/CPP/Common/MyString.h
+++ b/CPP/Common/MyString.h
@@ -429,11 +429,11 @@ public:
429 // int CompareNoCase(const char *s) const { return MyStringCompareNoCase(_chars, s); } 429 // int CompareNoCase(const char *s) const { return MyStringCompareNoCase(_chars, s); }
430 // int CompareNoCase(const AString &s) const { return MyStringCompareNoCase(_chars, s._chars); } 430 // int CompareNoCase(const AString &s) const { return MyStringCompareNoCase(_chars, s._chars); }
431 bool IsPrefixedBy(const char *s) const { return IsString1PrefixedByString2(_chars, s); } 431 bool IsPrefixedBy(const char *s) const { return IsString1PrefixedByString2(_chars, s); }
432 bool IsPrefixedBy_Ascii_NoCase(const char *s) const throw(); 432 bool IsPrefixedBy_Ascii_NoCase(const char *s) const { return IsString1PrefixedByString2_NoCase_Ascii(_chars, s); }
433 433
434 bool IsAscii() const 434 bool IsAscii() const
435 { 435 {
436 unsigned len = Len(); 436 const unsigned len = Len();
437 const char *s = _chars; 437 const char *s = _chars;
438 for (unsigned i = 0; i < len; i++) 438 for (unsigned i = 0; i < len; i++)
439 if ((unsigned char)s[i] >= 0x80) 439 if ((unsigned char)s[i] >= 0x80)
@@ -727,22 +727,23 @@ public:
727 // int CompareNoCase(const wchar_t *s) const { return MyStringCompareNoCase(_chars, s); } 727 // int CompareNoCase(const wchar_t *s) const { return MyStringCompareNoCase(_chars, s); }
728 // int CompareNoCase(const UString &s) const { return MyStringCompareNoCase(_chars, s._chars); } 728 // int CompareNoCase(const UString &s) const { return MyStringCompareNoCase(_chars, s._chars); }
729 bool IsPrefixedBy(const wchar_t *s) const { return IsString1PrefixedByString2(_chars, s); } 729 bool IsPrefixedBy(const wchar_t *s) const { return IsString1PrefixedByString2(_chars, s); }
730 bool IsPrefixedBy(const char *s) const { return IsString1PrefixedByString2(_chars, s); }
730 bool IsPrefixedBy_NoCase(const wchar_t *s) const { return IsString1PrefixedByString2_NoCase(_chars, s); } 731 bool IsPrefixedBy_NoCase(const wchar_t *s) const { return IsString1PrefixedByString2_NoCase(_chars, s); }
731 bool IsPrefixedBy_Ascii_NoCase(const char *s) const throw(); 732 bool IsPrefixedBy_Ascii_NoCase(const char *s) const { return IsString1PrefixedByString2_NoCase_Ascii(_chars, s); }
732 733
733 bool IsAscii() const 734 bool IsAscii() const
734 { 735 {
735 unsigned len = Len(); 736 const unsigned len = Len();
736 const wchar_t *s = _chars; 737 const wchar_t *s = _chars;
737 for (unsigned i = 0; i < len; i++) 738 for (unsigned i = 0; i < len; i++)
738 if (s[i] >= 0x80) 739 if ((unsigned)(int)s[i] >= 0x80)
739 return false; 740 return false;
740 return true; 741 return true;
741 } 742 }
742 int Find(wchar_t c) const { return FindCharPosInString(_chars, c); } 743 int Find(wchar_t c) const { return FindCharPosInString(_chars, c); }
743 int Find(wchar_t c, unsigned startIndex) const 744 int Find(wchar_t c, unsigned startIndex) const
744 { 745 {
745 int pos = FindCharPosInString(_chars + startIndex, c); 746 const int pos = FindCharPosInString(_chars + startIndex, c);
746 return pos < 0 ? -1 : (int)startIndex + pos; 747 return pos < 0 ? -1 : (int)startIndex + pos;
747 } 748 }
748 749
diff --git a/CPP/Common/MyXml.cpp b/CPP/Common/MyXml.cpp
index cc891fc..8364aae 100644
--- a/CPP/Common/MyXml.cpp
+++ b/CPP/Common/MyXml.cpp
@@ -24,7 +24,7 @@ static bool IsSpaceChar(char c)
24int CXmlItem::FindProp(const char *propName) const throw() 24int CXmlItem::FindProp(const char *propName) const throw()
25{ 25{
26 FOR_VECTOR (i, Props) 26 FOR_VECTOR (i, Props)
27 if (Props[i].Name == propName) 27 if (Props[i].Name.IsEqualTo(propName))
28 return (int)i; 28 return (int)i;
29 return -1; 29 return -1;
30} 30}
@@ -39,7 +39,7 @@ AString CXmlItem::GetPropVal(const char *propName) const
39 39
40bool CXmlItem::IsTagged(const char *tag) const throw() 40bool CXmlItem::IsTagged(const char *tag) const throw()
41{ 41{
42 return (IsTag && Name == tag); 42 return (IsTag && Name.IsEqualTo(tag));
43} 43}
44 44
45int CXmlItem::FindSubTag(const char *tag) const throw() 45int CXmlItem::FindSubTag(const char *tag) const throw()
diff --git a/CPP/Common/Sha3Reg.cpp b/CPP/Common/Sha3Reg.cpp
new file mode 100644
index 0000000..cd2e288
--- /dev/null
+++ b/CPP/Common/Sha3Reg.cpp
@@ -0,0 +1,76 @@
1// Sha3Reg.cpp
2
3#include "StdAfx.h"
4
5#include "../../C/Sha3.h"
6
7#include "../Common/MyBuffer2.h"
8#include "../Common/MyCom.h"
9
10#include "../7zip/Common/RegisterCodec.h"
11
12Z7_CLASS_IMP_COM_1(
13 CSha3Hasher
14 , IHasher
15)
16 unsigned _digestSize;
17 bool _isShake;
18 CAlignedBuffer1 _buf;
19public:
20 Byte _mtDummy[1 << 7];
21
22 CSha3 *Sha() { return (CSha3 *)(void *)(Byte *)_buf; }
23public:
24 CSha3Hasher(unsigned digestSize, bool isShake, unsigned blockSize):
25 _digestSize(digestSize),
26 _isShake(isShake),
27 _buf(sizeof(CSha3))
28 {
29 CSha3 *p = Sha();
30 Sha3_SET_blockSize(p, blockSize)
31 Sha3_Init(Sha());
32 }
33};
34
35Z7_COM7F_IMF2(void, CSha3Hasher::Init())
36{
37 Sha3_Init(Sha());
38}
39
40Z7_COM7F_IMF2(void, CSha3Hasher::Update(const void *data, UInt32 size))
41{
42 Sha3_Update(Sha(), (const Byte *)data, size);
43}
44
45Z7_COM7F_IMF2(void, CSha3Hasher::Final(Byte *digest))
46{
47 Sha3_Final(Sha(), digest, _digestSize, _isShake);
48}
49
50Z7_COM7F_IMF2(UInt32, CSha3Hasher::GetDigestSize())
51{
52 return (UInt32)_digestSize;
53}
54
55
56#define REGISTER_SHA3_HASHER_2(cls, id, name, digestSize, isShake, digestSize_for_blockSize) \
57 namespace N ## cls { \
58 static IHasher *CreateHasherSpec() \
59 { return new CSha3Hasher(digestSize / 8, isShake, \
60 SHA3_BLOCK_SIZE_FROM_DIGEST_SIZE(digestSize_for_blockSize / 8)); } \
61 static const CHasherInfo g_HasherInfo = { CreateHasherSpec, id, name, digestSize / 8 }; \
62 struct REGISTER_HASHER_NAME(cls) { REGISTER_HASHER_NAME(cls)() { RegisterHasher(&g_HasherInfo); }}; \
63 static REGISTER_HASHER_NAME(cls) g_RegisterHasher; }
64
65#define REGISTER_SHA3_HASHER( cls, id, name, size, isShake) \
66 REGISTER_SHA3_HASHER_2(cls, id, name, size, isShake, size)
67
68// REGISTER_SHA3_HASHER (Sha3_224_Hasher, 0x230, "SHA3-224", 224, false)
69REGISTER_SHA3_HASHER (Sha3_256_Hasher, 0x231, "SHA3-256", 256, false)
70// REGISTER_SHA3_HASHER (Sha3_386_Hasher, 0x232, "SHA3-384", 384, false)
71// REGISTER_SHA3_HASHER (Sha3_512_Hasher, 0x233, "SHA3-512", 512, false)
72// REGISTER_SHA3_HASHER (Shake128_Hasher, 0x240, "SHAKE128", 128, true)
73// REGISTER_SHA3_HASHER (Shake256_Hasher, 0x241, "SHAKE256", 256, true)
74// REGISTER_SHA3_HASHER_2 (Shake128_512_Hasher, 0x248, "SHAKE128-256", 256, true, 128) // -1344 (max)
75// REGISTER_SHA3_HASHER_2 (Shake256_512_Hasher, 0x249, "SHAKE256-512", 512, true, 256) // -1088 (max)
76// Shake supports different digestSize values for same blockSize
diff --git a/CPP/Common/Sha512Prepare.cpp b/CPP/Common/Sha512Prepare.cpp
new file mode 100644
index 0000000..e7beff5
--- /dev/null
+++ b/CPP/Common/Sha512Prepare.cpp
@@ -0,0 +1,7 @@
1// Sha512Prepare.cpp
2
3#include "StdAfx.h"
4
5#include "../../C/Sha512.h"
6
7static struct CSha512Prepare { CSha512Prepare() { Sha512Prepare(); } } g_Sha512Prepare;
diff --git a/CPP/Common/Sha512Reg.cpp b/CPP/Common/Sha512Reg.cpp
new file mode 100644
index 0000000..21df6ba
--- /dev/null
+++ b/CPP/Common/Sha512Reg.cpp
@@ -0,0 +1,83 @@
1// Sha512Reg.cpp
2
3#include "StdAfx.h"
4
5#include "../../C/Sha512.h"
6
7#include "../Common/MyBuffer2.h"
8#include "../Common/MyCom.h"
9
10#include "../7zip/Common/RegisterCodec.h"
11
12Z7_CLASS_IMP_COM_2(
13 CSha512Hasher
14 , IHasher
15 , ICompressSetCoderProperties
16)
17 unsigned _digestSize;
18 CAlignedBuffer1 _buf;
19public:
20 Byte _mtDummy[1 << 7];
21
22 CSha512 *Sha() { return (CSha512 *)(void *)(Byte *)_buf; }
23public:
24 CSha512Hasher(unsigned digestSize):
25 _digestSize(digestSize),
26 _buf(sizeof(CSha512))
27 {
28 Sha512_SetFunction(Sha(), 0);
29 Sha512_InitState(Sha(), _digestSize);
30 }
31};
32
33Z7_COM7F_IMF2(void, CSha512Hasher::Init())
34{
35 Sha512_InitState(Sha(), _digestSize);
36}
37
38Z7_COM7F_IMF2(void, CSha512Hasher::Update(const void *data, UInt32 size))
39{
40 Sha512_Update(Sha(), (const Byte *)data, size);
41}
42
43Z7_COM7F_IMF2(void, CSha512Hasher::Final(Byte *digest))
44{
45 Sha512_Final(Sha(), digest, _digestSize);
46}
47
48Z7_COM7F_IMF2(UInt32, CSha512Hasher::GetDigestSize())
49{
50 return (UInt32)_digestSize;
51}
52
53Z7_COM7F_IMF(CSha512Hasher::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *coderProps, UInt32 numProps))
54{
55 unsigned algo = 0;
56 for (UInt32 i = 0; i < numProps; i++)
57 {
58 if (propIDs[i] == NCoderPropID::kDefaultProp)
59 {
60 const PROPVARIANT &prop = coderProps[i];
61 if (prop.vt != VT_UI4)
62 return E_INVALIDARG;
63 if (prop.ulVal > 2)
64 return E_NOTIMPL;
65 algo = (unsigned)prop.ulVal;
66 }
67 }
68 if (!Sha512_SetFunction(Sha(), algo))
69 return E_NOTIMPL;
70 return S_OK;
71}
72
73#define REGISTER_SHA512_HASHER(cls, id, name, size) \
74 namespace N ## cls { \
75 static IHasher *CreateHasherSpec() { return new CSha512Hasher(size); } \
76 static const CHasherInfo g_HasherInfo = { CreateHasherSpec, id, name, size }; \
77 struct REGISTER_HASHER_NAME(cls) { REGISTER_HASHER_NAME(cls)() { RegisterHasher(&g_HasherInfo); }}; \
78 static REGISTER_HASHER_NAME(cls) g_RegisterHasher; }
79
80// REGISTER_SHA512_HASHER (Sha512_224_Hasher, 0x220, "SHA512-224", SHA512_224_DIGEST_SIZE)
81// REGISTER_SHA512_HASHER (Sha512_256_Hasher, 0x221, "SHA512-256", SHA512_256_DIGEST_SIZE)
82REGISTER_SHA512_HASHER (Sha384Hasher, 0x222, "SHA384", SHA512_384_DIGEST_SIZE)
83REGISTER_SHA512_HASHER (Sha512Hasher, 0x223, "SHA512", SHA512_DIGEST_SIZE)
diff --git a/CPP/Common/Wildcard.cpp b/CPP/Common/Wildcard.cpp
index 798cbd9..b561a89 100644
--- a/CPP/Common/Wildcard.cpp
+++ b/CPP/Common/Wildcard.cpp
@@ -255,7 +255,8 @@ ForDir nonrec [0, M) same as ForBoth-File
255 255
256bool CItem::AreAllAllowed() const 256bool CItem::AreAllAllowed() const
257{ 257{
258 return ForFile && ForDir && WildcardMatching && PathParts.Size() == 1 && PathParts.Front() == L"*"; 258 return ForFile && ForDir && WildcardMatching
259 && PathParts.Size() == 1 && PathParts.Front().IsEqualTo("*");
259} 260}
260 261
261bool CItem::CheckPath(const UStringVector &pathParts, bool isFile) const 262bool CItem::CheckPath(const UStringVector &pathParts, bool isFile) const
@@ -542,7 +543,7 @@ unsigned GetNumPrefixParts_if_DrivePath(UStringVector &pathParts)
542 { 543 {
543 if (pathParts.Size() < 4 544 if (pathParts.Size() < 4
544 || !pathParts[1].IsEmpty() 545 || !pathParts[1].IsEmpty()
545 || pathParts[2] != L"?") 546 || !pathParts[2].IsEqualTo("?"))
546 return 0; 547 return 0;
547 testIndex = 3; 548 testIndex = 3;
548 } 549 }
@@ -574,11 +575,11 @@ static unsigned GetNumPrefixParts(const UStringVector &pathParts)
574 return 1; 575 return 1;
575 if (pathParts.Size() == 2) 576 if (pathParts.Size() == 2)
576 return 2; 577 return 2;
577 if (pathParts[2] == L".") 578 if (pathParts[2].IsEqualTo("."))
578 return 3; 579 return 3;
579 580
580 unsigned networkParts = 2; 581 unsigned networkParts = 2;
581 if (pathParts[2] == L"?") 582 if (pathParts[2].IsEqualTo("?"))
582 { 583 {
583 if (pathParts.Size() == 3) 584 if (pathParts.Size() == 3)
584 return 3; 585 return 3;
@@ -642,7 +643,7 @@ void CCensor::AddItem(ECensorPathMode pathMode, bool include, const UString &pat
642 if (pathParts.Size() >= 3 643 if (pathParts.Size() >= 3
643 && pathParts[0].IsEmpty() 644 && pathParts[0].IsEmpty()
644 && pathParts[1].IsEmpty() 645 && pathParts[1].IsEmpty()
645 && pathParts[2] == L"?") 646 && pathParts[2].IsEqualTo("?"))
646 ignoreWildcardIndex = 2; 647 ignoreWildcardIndex = 2;
647 // #endif 648 // #endif
648 649
@@ -665,7 +666,7 @@ void CCensor::AddItem(ECensorPathMode pathMode, bool include, const UString &pat
665 for (unsigned i = numPrefixParts; i < pathParts.Size(); i++) 666 for (unsigned i = numPrefixParts; i < pathParts.Size(); i++)
666 { 667 {
667 const UString &part = pathParts[i]; 668 const UString &part = pathParts[i];
668 if (part == L".." || part == L".") 669 if (part.IsEqualTo("..") || part.IsEqualTo("."))
669 dotsIndex = (int)i; 670 dotsIndex = (int)i;
670 } 671 }
671 672