File indexing completed on 2024-06-23 05:48:48
0001 /* 0002 This file is part of the Okteta Kasten module, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2009 Friedrich W. H. Kossebau <kossebau@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "modsum8bytearraychecksumalgorithm.hpp" 0010 0011 // Okteta core 0012 #include <Okteta/AbstractByteArrayModel> 0013 // KF 0014 #include <KLocalizedString> 0015 // Qt 0016 #include <QtGlobal> 0017 0018 ModSum8ByteArrayChecksumAlgorithm::ModSum8ByteArrayChecksumAlgorithm() 0019 : AbstractByteArrayChecksumAlgorithm( 0020 i18nc("name of the checksum algorithm", "Modular sum 8-bit"), 0021 QStringLiteral("ModularSum8") 0022 ) 0023 {} 0024 0025 ModSum8ByteArrayChecksumAlgorithm::~ModSum8ByteArrayChecksumAlgorithm() = default; 0026 0027 AbstractByteArrayChecksumParameterSet* ModSum8ByteArrayChecksumAlgorithm::parameterSet() { return &mParameterSet; } 0028 0029 bool ModSum8ByteArrayChecksumAlgorithm::calculateChecksum(QString* result, 0030 const Okteta::AbstractByteArrayModel* model, const Okteta::AddressRange& range) const 0031 { 0032 quint8 modSum = 0x00; 0033 Okteta::Address nextBlockEnd = range.start() + CalculatedByteCountSignalLimit; 0034 for (Okteta::Address i = range.start(); i <= range.end(); ++i) { 0035 modSum += (quint8)(model->byte(i)); 0036 #if 0 0037 const uchar value = (crcBits & 0xFF) + model->datum(i); 0038 crcBits >>= 8; 0039 crcBits ^= lookupTable[value]; 0040 #endif 0041 if (i >= nextBlockEnd) { 0042 nextBlockEnd += CalculatedByteCountSignalLimit; 0043 Q_EMIT calculatedBytes(range.localIndex(i) + 1); 0044 } 0045 } 0046 0047 modSum = ~modSum + 1; 0048 0049 *result = QStringLiteral("%1").arg(modSum, 2, 16, QChar::fromLatin1('0')); 0050 return true; 0051 } 0052 0053 #include "moc_modsum8bytearraychecksumalgorithm.cpp"