7zip/CPP/Common/CrcReg.cpp

78 lines
1.5 KiB
C++
Raw Normal View History

2021-12-27 01:00:00 +01:00
// CrcReg.cpp
#include "StdAfx.h"
#include "../../C/7zCrc.h"
#include "../../C/CpuArch.h"
#include "../Common/MyCom.h"
#include "../7zip/Common/RegisterCodec.h"
EXTERN_C_BEGIN
EXTERN_C_END
2023-06-21 02:00:00 +02:00
Z7_CLASS_IMP_COM_2(
CCrcHasher
, IHasher
, ICompressSetCoderProperties
)
2021-12-27 01:00:00 +01:00
UInt32 _crc;
2024-05-14 02:00:00 +02:00
Z7_CRC_UPDATE_FUNC _updateFunc;
2023-06-21 02:00:00 +02:00
Z7_CLASS_NO_COPY(CCrcHasher)
2021-12-27 01:00:00 +01:00
bool SetFunctions(UInt32 tSize);
public:
2023-06-21 02:00:00 +02:00
Byte _mtDummy[1 << 7]; // it's public to eliminate clang warning: unused private field
2021-12-27 01:00:00 +01:00
2023-06-21 02:00:00 +02:00
CCrcHasher(): _crc(CRC_INIT_VAL) { SetFunctions(0); }
2021-12-27 01:00:00 +01:00
};
bool CCrcHasher::SetFunctions(UInt32 tSize)
{
2024-05-14 02:00:00 +02:00
const Z7_CRC_UPDATE_FUNC f = z7_GetFunc_CrcUpdate(tSize);
2021-12-27 01:00:00 +01:00
if (!f)
{
2024-05-14 02:00:00 +02:00
_updateFunc = CrcUpdate;
2021-12-27 01:00:00 +01:00
return false;
}
_updateFunc = f;
return true;
}
2023-06-21 02:00:00 +02:00
Z7_COM7F_IMF(CCrcHasher::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *coderProps, UInt32 numProps))
2021-12-27 01:00:00 +01:00
{
for (UInt32 i = 0; i < numProps; i++)
{
if (propIDs[i] == NCoderPropID::kDefaultProp)
{
2023-06-21 02:00:00 +02:00
const PROPVARIANT &prop = coderProps[i];
2021-12-27 01:00:00 +01:00
if (prop.vt != VT_UI4)
return E_INVALIDARG;
if (!SetFunctions(prop.ulVal))
return E_NOTIMPL;
}
}
return S_OK;
}
2023-06-21 02:00:00 +02:00
Z7_COM7F_IMF2(void, CCrcHasher::Init())
2021-12-27 01:00:00 +01:00
{
_crc = CRC_INIT_VAL;
}
2023-06-21 02:00:00 +02:00
Z7_COM7F_IMF2(void, CCrcHasher::Update(const void *data, UInt32 size))
2021-12-27 01:00:00 +01:00
{
2024-05-14 02:00:00 +02:00
_crc = _updateFunc(_crc, data, size);
2021-12-27 01:00:00 +01:00
}
2023-06-21 02:00:00 +02:00
Z7_COM7F_IMF2(void, CCrcHasher::Final(Byte *digest))
2021-12-27 01:00:00 +01:00
{
2023-06-21 02:00:00 +02:00
const UInt32 val = CRC_GET_DIGEST(_crc);
SetUi32(digest, val)
2021-12-27 01:00:00 +01:00
}
REGISTER_HASHER(CCrcHasher, 0x1, "CRC32", 4)