diff --git a/kasten/controllers/CMakeLists.txt b/kasten/controllers/CMakeLists.txt index 22e19b78..d779bc2e 100644 --- a/kasten/controllers/CMakeLists.txt +++ b/kasten/controllers/CMakeLists.txt @@ -1,701 +1,704 @@ set(OKTETAKASTENCONTROLLERS_VERSION ${OKTETAKASTEN_LIB_VERSION}) set(OKTETAKASTENCONTROLLERS_SO_VERSION ${OKTETAKASTEN_LIB_SOVERSION}) set( LIBFRAMESPRINT_REL_DIR ../../libs/framesprint ) add_definitions(-DTRANSLATION_DOMAIN=\"liboktetakasten\") include_directories( view/libbytearraychecksum view/libbytearrayfilter view/libfinddialog ${LIBFRAMESPRINT_REL_DIR} ) set(HAVE_QCA2 ${Qca-qt5_FOUND}) configure_file( config-qca2.hpp.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-qca2.hpp ) macro(OKTETAKASTENCONTROLLERS_ADD_SUBLIBRARY _subdir) okteta_add_sublibrary(Controllers NAMESPACE Okteta Kasten REVERSE_NAMESPACE_INCLUDEDIR SUBDIR ${_subdir} ${ARGN} ) endmacro() macro(OKTETAKASTENCONTROLLERS_ADD_SUBLIBRARY_STRUCTURES_TESTED _subdir) okteta_add_sublibrary(Controllers NAMESPACE Okteta Kasten REVERSE_NAMESPACE_INCLUDEDIR SOURCE_TAG structures_tested SUBDIR ${_subdir} ${ARGN} ) endmacro() oktetakastencontrollers_add_sublibrary(document/info PUBLIC DocumentInfoToolFactory DocumentInfoToolViewFactory PRIVATE ByteArrayModelIoDevice DocumentInfoView DocumentInfoTool DocumentInfoToolView ) # unused, TODO: remove? if (FALSE) oktetakastencontrollers_add_sublibrary(document/overwriteonly PUBLIC OverwriteOnlyControllerFactory PRIVATE OverwriteOnlyController ) endif() oktetakastencontrollers_add_sublibrary(view/overwritemode PUBLIC OverwriteModeControllerFactory PRIVATE OverwriteModeController ) oktetakastencontrollers_add_sublibrary(view/info PUBLIC InfoToolFactory InfoToolViewFactory PRIVATE CreateStatisticJob StatisticTableModel InfoView InfoTool InfoToolView KCFG infoviewsettings.kcfgc ) oktetakastencontrollers_add_sublibrary(view/stringsextract PUBLIC StringsExtractToolFactory StringsExtractToolViewFactory PRIVATE ExtractStringsJob ContainedStringTableModel StringsExtractView ContainedString StringsExtractTool StringsExtractToolView ) oktetakastencontrollers_add_sublibrary(view/libbytearraychecksum PRIVATE AbstractByteArrayChecksumAlgorithm AbstractByteArrayChecksumParameterSet AbstractByteArrayChecksumParameterSetEdit ByteArrayChecksumAlgorithmFactory ByteArrayChecksumParameterSetEditFactory ) if( Qca-qt5_FOUND ) set( QCA2CHECKSUM_CLASSES Qca2ByteArrayChecksumAlgorithm ) endif() oktetakastencontrollers_add_sublibrary(view/libbytearraychecksum/algorithm PRIVATE Crc32ByteArrayChecksumAlgorithm + Crc64ByteArrayChecksumAlgorithm Adler32ByteArrayChecksumAlgorithm ModSum8ByteArrayChecksumAlgorithm ModSum16ByteArrayChecksumAlgorithm ModSum32ByteArrayChecksumAlgorithm ModSum64ByteArrayChecksumAlgorithm ## NEWCHECKSUM(start) ## Here add the names of your classes of your checksum algorithm, ## e.g. ## MyByteArrayChecksumAlgorithm ## NEWCHECKSUM(end) NoByteArrayChecksumParameterSet NoByteArrayChecksumParameterSetEdit ModSumByteArrayChecksumParameterSet ModSumByteArrayChecksumParameterSetEdit + Crc64ByteArrayChecksumParameterSet + Crc64ByteArrayChecksumParameterSetEdit ## NEWCHECKSUMPARAMETERSET(start) ## Here add the names of your classes of your checksum parameter set and ## of the widget to edit the checksum parameter set, ## e.g. ## MyByteArrayChecksumParameterSet ## MyByteArrayChecksumParameterSetEdit ## NEWCHECKSUMPARAMETERSET(end) ${QCA2CHECKSUM_CLASSES} ) oktetakastencontrollers_add_sublibrary(view/checksum PUBLIC ChecksumToolFactory ChecksumToolViewFactory PRIVATE ChecksumCalculateJob ChecksumLogging ChecksumView ChecksumTool ChecksumToolView ) oktetakastencontrollers_add_sublibrary(view/libfinddialog PUBLIC FindDirection PRIVATE AbstractFindDialog ) oktetakastencontrollers_add_sublibrary(view/poddecoder/typecodecs PRIVATE Binary8Codec Octal8Codec Hexadecimal8Codec UInt8Codec UInt16Codec UInt32Codec UInt64Codec SInt8Codec SInt16Codec SInt32Codec SInt64Codec Float32Codec Float64Codec Char8Codec Utf8Codec ) oktetakastencontrollers_add_sublibrary(view/poddecoder PUBLIC PODDecoderToolFactory PODDecoderToolViewFactory PRIVATE PODData PODTableModel PODDelegate PODTableView PODDecoderTool PODDecoderToolView ) oktetakastencontrollers_add_sublibrary(view/poddecoder/typeeditors SOURCE_TAG typeeditor PRIVATE AbstractValue8Editor Binary8Editor Octal8Editor Hexadecimal8Editor UIntSpinBox SIntSpinBox Float32Editor Float64Editor Char8Editor Utf8Editor ) oktetakastencontrollers_add_sublibrary(view/bytetable PUBLIC ByteTableToolFactory ByteTableToolViewFactory PRIVATE ByteTableModel ByteTableView ByteTableTool ByteTableToolView KCFG bytetableviewsettings.kcfgc ) oktetakastencontrollers_add_sublibrary(view/search PUBLIC SearchControllerFactory PRIVATE SearchUserQueryable SearchDialog SearchJob SearchTool SearchController ) oktetakastencontrollers_add_sublibrary(view/replace PUBLIC ReplaceControllerFactory PRIVATE ReplaceUserQueryable ReplaceController ReplaceDialog ReplacePrompt ReplaceJob ReplaceTool ) oktetakastencontrollers_add_sublibrary(view/libbytearrayfilter PRIVATE AbstractByteArrayFilter AbstractByteArrayFilterParameterSet AbstractByteArrayFilterParameterSetEdit ByteArrayFilterFactory ByteArrayFilterParameterSetEditFactory ) oktetakastencontrollers_add_sublibrary(view/libbytearrayfilter/filter PRIVATE NoByteArrayFilterParameterSet OperandByteArrayFilterParameterSet ReverseByteArrayFilterParameterSet RotateByteArrayFilterParameterSet ## NEWFILTERPARAMETERSET(start) ## Here add the names of your classes of your filter parameter set, ## e.g. ## MyByteArrayFilterParameterSet ## NEWFILTERPARAMETERSET(end) AndByteArrayFilter OrByteArrayFilter XorByteArrayFilter InvertByteArrayFilter ReverseByteArrayFilter RotateByteArrayFilter ShiftByteArrayFilter ## NEWFILTER(start) ## Here add the names of your classes of your filter, ## e.g. ## MyByteArrayFilter ## NEWFILTER(end) NoByteArrayFilterParameterSetedit OperandByteArrayFilterParameterSetedit ReverseByteArrayFilterParameterSetedit RotateByteArrayFilterParameterSetedit ## NEWFILTERPARAMETERSET(start) ## Here add the names of your classes of your widget to edit the filter parameter set, ## e.g. ## MyByteArrayFilterParameterSetedit ## NEWFILTERPARAMETERSET(end) ) oktetakastencontrollers_add_sublibrary(view/filter PUBLIC FilterToolFactory FilterToolViewFactory PRIVATE FilterJob FilterView FilterTool FilterToolView ) oktetakastencontrollers_add_sublibrary(view/charsetconversion PUBLIC CharsetConversionToolFactory CharsetConversionToolViewFactory PRIVATE CharsetConversionJob CharsetConversionView CharsetConversionTool CharsetConversionToolView ) oktetakastencontrollers_add_sublibrary(view/gotooffset PUBLIC GotoOffsetControllerFactory PRIVATE GotoOffsetTool GotoOffsetView GotoOffsetToolView GotoOffsetController ) oktetakastencontrollers_add_sublibrary(view/selectrange PUBLIC SelectRangeControllerFactory PRIVATE SelectRangeTool SelectRangeView SelectRangeToolView SelectRangeController ) oktetakastencontrollers_add_sublibrary(view/bookmarks PUBLIC BookmarksControllerFactory PRIVATE BookmarkEditPopup BookmarksController ) oktetakastencontrollers_add_sublibrary(view/bookmarks PUBLIC BookmarksToolFactory BookmarksToolViewFactory PRIVATE BookmarkListModel BookmarksView BookmarksTool BookmarksToolView ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/datatypes PRIVATE TopLevelDataInformation DataInformation DataInformationbase DummyDataInformation DataInformationwithchildren StructureDataInformation TaggedUnionDataInformation UnionDataInformation PrimitiveFactory PrimitiveDataType ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/datatypes/array PRIVATE ArrayDataInformation AbstractArrayData ComplexArrayData PrimitiveArrayData ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/datatypes/primitive PRIVATE PointerDataInformation CharDataInformation DoubleDataInformation FloatDataInformation SIntDataInformation UIntDataInformation BoolDataInformation FlagDataInformation PrimitiveDataInformation BasicPrimitiveDataInformation EnumDataInformation EnumDefinition ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/datatypes/primitive/bitfield PRIVATE AbstractBitfieldDataInformation BoolBitfieldDataInformation SignedBitfieldDataInformation UnsignedBitfieldDataInformation ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/datatypes/strings PRIVATE StringDataInformation StringData AsciiStringData Latin1StringData Utf8StringData Utf16StringData Utf32StringData EbcdicStringData ) oktetakastencontrollers_add_sublibrary_structures_tested(../../core/codecs PRIVATE Ebcdic1047CharCodec ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/script PRIVATE ScriptEngineInitializer ScriptHandler ScriptHandlerInfo ScriptUtils ScriptLogger ScriptLoggerView SafeReference ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/script/classes PRIVATE DefaultScriptClass ArrayScriptClass PrimitiveScriptClass EnumScriptClass PointerScriptClass BitfieldScriptClass StringScriptClass StructUnionScriptClass ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/parsers PRIVATE AbstractStructureParser OsdParser ScriptFileParser ScriptValueConverter DataInformationFactory ParserUtils ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/settings KCFG structureviewpreferences.kcfgc ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures PRIVATE AllPrimitiveTypes StructLogging ) #these source files are not needed by the static library for unit tests, therefore keep them separate oktetakastencontrollers_add_sublibrary(view/structures/settings PRIVATE StructureAddRemoveWidget StructuresSelectionDialog StructureViewSettingsWidget StructuresManagerView UI structureviewsettingswidget.ui ) oktetakastencontrollers_add_sublibrary(view/structures PUBLIC StructuresToolFactory StructuresToolViewFactory PRIVATE StructuresManager StructuresTool StructureTreeModel StructureDefinitionFile # view/structures/modeltest.cpp StructureView StructuresToolView StructureViewItemDelegate ) # structurestool.h cannot be installed as it pulls (too) many private uninstalled headers # KF5 TODO: any tools/controllers and views should be created by the resp. factories # since some time, no more directly. # So on next ABI change depublish tools/controllers & their views # For now keeping all installed, in case someone is using them still/already. # structtoolview.h is not useful, but we keep installing the header just in case someone includes it oktetakastencontrollers_add_sublibrary(${LIBFRAMESPRINT_REL_DIR} PRIVATE AbstractFrameRenderer FramesToPaperPrinter HeaderFooterFrameRenderer ) oktetakastencontrollers_add_sublibrary(view/print PUBLIC PrintControllerFactory PRIVATE PrintTool PrintJob AbstractColumnFrameRenderer PrintColumnStylist ByteArrayFrameRenderer PrintDialog PrintController ) set_source_files_properties(view/print/printtool.cpp PROPERTIES COMPILE_FLAGS -DOKTETA_VERSION=\\\"${Okteta_VERSION}\\\" ) oktetakastencontrollers_add_sublibrary(view/viewconfig PUBLIC ViewConfigControllerFactory PRIVATE BytesPerLineDialog BytesPerGroupDialog ViewConfigController ) oktetakastencontrollers_add_sublibrary(view/viewstatus PUBLIC ViewStatusControllerFactory PRIVATE ViewStatusController ) oktetakastencontrollers_add_sublibrary(view/viewmode PUBLIC ViewModeControllerFactory PRIVATE ViewModeController ) oktetakastencontrollers_add_sublibrary(view/viewprofiles PUBLIC ViewProfilesManageControllerFactory # TODO: two controllers in one subdir ViewProfileControllerFactory PRIVATE ViewProfileEdit ViewProfileEditDialog ViewProfileTableModel ViewProfilesManageDialog ViewProfileController ViewProfilesManageController ) oktetakastencontrollers_add_sublibrary(view/viewcontextmenu PUBLIC ViewContextMenuControllerFactory PRIVATE ViewContextMenuController ) # create a static library for the unit tests. This means we don't have to compile the sources twice add_library(poddecoder-typeeditors STATIC ${oktetakastencontrollers_typeeditor_LIB_SRCS}) set_target_properties( poddecoder-typeeditors PROPERTIES POSITION_INDEPENDENT_CODE TRUE ) target_link_libraries( poddecoder-typeeditors PUBLIC OktetaGui PRIVATE KF5::Completion ) add_library( structureview-tested-srcs STATIC ${oktetakastencontrollers_structures_tested_LIB_SRCS} ) set_target_properties( structureview-tested-srcs PROPERTIES POSITION_INDEPENDENT_CODE TRUE ) target_link_libraries( structureview-tested-srcs PUBLIC OktetaCore KF5::ConfigGui KF5::I18n KF5::Service Qt5::Script Qt5::Xml Qt5::Widgets PRIVATE KF5::Completion KF5::ConfigWidgets ) if(BUILD_TESTING) #structures view unit tests ecm_add_tests( test/primitivearraytest.cpp test/arraydatainformationtest.cpp test/basicdatainformationtest.cpp test/primitivedatainformationtest.cpp test/scriptclassestest.cpp test/uniondatainformationtest.cpp test/allprimitivetypestest.cpp test/scriptvalueconvertertest.cpp test/osdparsertest.cpp test/commonparsertest.cpp test/jsparsertest.cpp test/customtostringtest.cpp test/locktooffsettest.cpp NAME_PREFIX structures- LINK_LIBRARIES structureview-tested-srcs Qt5::Test poddecoder-typeeditors ) #replace tool unit tests ecm_add_test( view/search/searchjob.cpp view/replace/replacejob.cpp test/replacejobtest.cpp TEST_NAME replacejobtest LINK_LIBRARIES OktetaKastenGui OktetaKastenCore Qt5::Test ) endif() list(APPEND oktetakastencontrollers_LIB_HDRS ${CMAKE_CURRENT_BINARY_DIR}/config-qca2.hpp ) set(OPTIONAL_PRIVATE) if( Qca-qt5_FOUND ) set(OPTIONAL_PRIVATE qca-qt5) endif() okteta_add_library(Controllers NAMESPACE Okteta Kasten PUBLIC OktetaKastenGui OktetaKastenCore KastenGui KastenCore PRIVATE structureview-tested-srcs poddecoder-typeeditors KF5::NewStuff KF5::I18n KF5::ConfigWidgets KF5::KCMUtils KF5::IconThemes KF5::Completion Qt5::PrintSupport Qt5::Script ${OPTIONAL_PRIVATE} VERSION ${OKTETAKASTENCONTROLLERS_VERSION} SOVERSION ${OKTETAKASTENCONTROLLERS_SO_VERSION} ABIVERSION ${OKTETAKASTEN_ABI_VERSION} ${KASTEN_ABI_VERSION} SOURCES ${oktetakastencontrollers_LIB_SRCS} HEADERS ${oktetakastencontrollers_LIB_HDRS} CCHEADERS ${oktetakastencontrollers_LIB_CCHDRS} NO_VERSIONED_INCLUDEDIR NO_VERSIONED_PACKAGE_NAME REVERSE_NAMESPACE_INCLUDEDIR REVERSE_NAMESPACE_LIB NO_TARGET_NAMESPACE ) if(NOT KF5_VERSION VERSION_LESS "5.57.0") install(FILES view/structures/kns/okteta-structures.knsrc DESTINATION ${KDE_INSTALL_KNSRCDIR}) else() install( FILES view/structures/kns/okteta-structures.knsrc DESTINATION ${KDE_INSTALL_CONFDIR} ) endif() set( elf_structure_FILES view/structures/examples/okteta/structures/elf/metadata.desktop view/structures/examples/okteta/structures/elf/main.osd ) install( FILES ${elf_structure_FILES} DESTINATION ${KDE_INSTALL_DATADIR}/okteta/structures/elf ) set( png_structure_FILES view/structures/examples/okteta/structures/png/metadata.desktop view/structures/examples/okteta/structures/png/main.osd ) install( FILES ${png_structure_FILES} DESTINATION ${KDE_INSTALL_DATADIR}/okteta/structures/png ) install( FILES view/structures/examples/okteta/structures/uuid.js DESTINATION ${KDE_INSTALL_DATADIR}/okteta/structures/ ) install( FILES view/structures/settings/structureviewpreferences.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR} ) configure_file( view/structures/struct2osd.in ${CMAKE_CURRENT_BINARY_DIR}/struct2osd @ONLY ) install( PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/struct2osd DESTINATION ${KDE_INSTALL_BINDIR} ) install( FILES view/structures/gccxml-to-osd.xsl DESTINATION ${KDE_INSTALL_DATADIR}/okteta/structures/ ) okteta_add_cmakeconfig(Controllers NAMESPACE Okteta Kasten ) if( KASTEN_BUILD_INTERNAL_TEMPLATES ) include_directories( view/libbytearrayfilter/filter view/libbytearraychecksum/algorithm ) okteta_add_sublibrary(ControllersTemplates NAMESPACE Okteta Kasten SUBDIR view/libbytearrayfilter/filter/template PRIVATE Template_ByteArrayFilter Template_ByteArrayFilterParameterSet Template_ByteArrayFilterParameterSetEdit ) okteta_add_sublibrary(ControllersTemplates NAMESPACE Okteta Kasten SUBDIR view/libbytearraychecksum/algorithm/template PRIVATE Template_ByteArrayCheckSumAlgorithm Template_ByteArrayChecksumParameterSet Template_ByteArrayChecksumParameterSetEdit ) add_library( oktetakastencontrollertemplates STATIC ${oktetakastencontrollerstemplates_LIB_SRCS} ) # MSVC needs this target_compile_definitions( oktetakastencontrollertemplates PUBLIC OKTETAKASTENCONTROLLERS_STATIC_DEFINE=1 ) target_link_libraries( oktetakastencontrollertemplates KF5::I18n Qt5::Widgets OktetaCore ) endif() diff --git a/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumalgorithm.cpp b/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumalgorithm.cpp new file mode 100644 index 00000000..df5cb1fa --- /dev/null +++ b/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumalgorithm.cpp @@ -0,0 +1,133 @@ +/* + This file is part of the Okteta Kasten module, made within the KDE community. + + Copyright 2019 Lars Maier + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "crc64bytearraychecksumalgorithm.hpp" + +// Okteta core +#include +// KF +#include + +struct Crc64AlgorithmSpec +{ + quint64 polynomial; + quint64 initialValue; + quint64 finalXorValue; + bool inputReflected; + bool outputReflected; +}; + +static const Crc64AlgorithmSpec algorithms[] = { + // ECMA-182 + { 0x42F0E1EBA9EA3693, 0x0, 0x0, false, false }, + + // ISO-3309 + { 0x000000000000001B, 0xFFFFFFFFFFFFFFFFllu,0xFFFFFFFFFFFFFFFFllu, true, true} + + // Add more algorithms here +}; + +static void fillTable(quint64 poly, quint64 *table) +{ + for (size_t i = 0; i < 256; i++) { + quint64 crc = 0; + for (size_t j = 0; j < 8; j++) { + bool b = (i >> (7u - j)) & 0x01u; + if ((crc >> 63u) != b) { + crc = (crc << 1u) ^ poly; + } else { + crc = (crc << 1u); + } + } + table[i] = crc; + } +} + +static quint64 reflect64(quint64 x) +{ + quint64 y = 0; + for (size_t i = 0; i < 64; i++) { + if ((x >> i) & 0x01u) { + y |= 0x01lu << (63 - i); + } + } + + return y; +} + +static uchar reflect8(uchar x) +{ + uchar y = 0; + + for (size_t i = 0; i < 8; i++) { + if ((x >> i) & 0x01u) { + y |= 0x01u << (7 - i); + } + } + + return y; +} + +Crc64ByteArrayChecksumAlgorithm::Crc64ByteArrayChecksumAlgorithm() + : AbstractByteArrayChecksumAlgorithm( + i18nc("name of the checksum algorithm, Cyclic Redundancy Check 64", "CRC-64")) +{} + +Crc64ByteArrayChecksumAlgorithm::~Crc64ByteArrayChecksumAlgorithm() = default; + +AbstractByteArrayChecksumParameterSet* +Crc64ByteArrayChecksumAlgorithm::parameterSet() { return &mParameterSet; } + +bool Crc64ByteArrayChecksumAlgorithm::calculateChecksum(QString* result, + const Okteta::AbstractByteArrayModel* model, const Okteta::AddressRange& range) const +{ + const Crc64AlgorithmSpec *spec = &algorithms[static_cast(mParameterSet.crc64Variant())]; + + quint64 lookupTable[256]; + fillTable(spec->polynomial, lookupTable); + + quint64 crcBits = spec->initialValue; + Okteta::Address nextBlockEnd = range.start() + CalculatedByteCountSignalLimit; + for (Okteta::Address i = range.start(); i <= range.end(); ++i) { + + uchar value = model->byte(i); + if (spec->inputReflected) { + value = reflect8(value); + } + + const uchar idx = (crcBits >> 56u) ^ value; + crcBits = (crcBits << 8u) ^ lookupTable[idx & 0xffu]; + + if (i >= nextBlockEnd) { + nextBlockEnd += CalculatedByteCountSignalLimit; + emit calculatedBytes(range.localIndex(i) + 1); + } + } + + if (spec->outputReflected) { + crcBits = reflect64(crcBits); + } + crcBits = crcBits ^ spec->finalXorValue; + + *result = QStringLiteral("%1").arg(crcBits, 16, 16, QChar::fromLatin1('0')); + return true; +} diff --git a/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumalgorithm.hpp b/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumalgorithm.hpp new file mode 100644 index 00000000..056a072a --- /dev/null +++ b/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumalgorithm.hpp @@ -0,0 +1,47 @@ +/* + This file is part of the Okteta Kasten module, made within the KDE community. + + Copyright 2019 Lars Maier + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef KASTEN_CRC64BYTEARRAYCHECKSUMALGORITHM_HPP +#define KASTEN_CRC64BYTEARRAYCHECKSUMALGORITHM_HPP + +// +#include "crc64bytearraychecksumparameterset.hpp" +// +#include + +class Crc64ByteArrayChecksumAlgorithm : public AbstractByteArrayChecksumAlgorithm +{ + Q_OBJECT + +public: + Crc64ByteArrayChecksumAlgorithm(); + ~Crc64ByteArrayChecksumAlgorithm() override; + +public: // AbstractByteArrayChecksumAlgorithm API + bool calculateChecksum(QString* result, const Okteta::AbstractByteArrayModel* model, const Okteta::AddressRange& range) const override; + AbstractByteArrayChecksumParameterSet* parameterSet() override; + +private: + Crc64ByteArrayChecksumParameterSet mParameterSet; +}; + +#endif diff --git a/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumparameterset.cpp b/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumparameterset.cpp new file mode 100644 index 00000000..715a9899 --- /dev/null +++ b/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumparameterset.cpp @@ -0,0 +1,33 @@ +/* + This file is part of the Okteta Kasten module, made within the KDE community. + + Copyright 2019 Lars Maier + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "crc64bytearraychecksumparameterset.hpp" + +Crc64ByteArrayChecksumParameterSet::Crc64ByteArrayChecksumParameterSet() = default; + +Crc64ByteArrayChecksumParameterSet::~Crc64ByteArrayChecksumParameterSet() = default; + +const char* Crc64ByteArrayChecksumParameterSet::id() const { return "Crc64"; } + +Crc64Variant Crc64ByteArrayChecksumParameterSet::crc64Variant() const { return mVariant; } + +void Crc64ByteArrayChecksumParameterSet::setCrc64Variant(Crc64Variant variant) { mVariant = variant; } diff --git a/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumparameterset.hpp b/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumparameterset.hpp new file mode 100644 index 00000000..38143aff --- /dev/null +++ b/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumparameterset.hpp @@ -0,0 +1,54 @@ +/* + This file is part of the Okteta Kasten module, made within the KDE community. + + Copyright 2019 Lars Maier + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef KASTEN_CRC64BYTEARRAYCHECKSUMPARAMETERSET_HPP +#define KASTEN_CRC64BYTEARRAYCHECKSUMPARAMETERSET_HPP + +// lib +#include "abstractbytearraychecksumparameterset.hpp" + +enum class Crc64Variant +{ + ECMA182 = 0, + ISO3309 = 1, +}; + +class Crc64ByteArrayChecksumParameterSet : public AbstractByteArrayChecksumParameterSet +{ +public: + Crc64ByteArrayChecksumParameterSet(); + ~Crc64ByteArrayChecksumParameterSet() override; + +public: // AbstractByteArrayChecksumParameterSet API + const char* id() const override; + +public: + void setCrc64Variant(Crc64Variant variant); + +public: + Crc64Variant crc64Variant() const; + +private: + Crc64Variant mVariant = Crc64Variant::ECMA182; +}; + +#endif diff --git a/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumparametersetedit.cpp b/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumparametersetedit.cpp new file mode 100644 index 00000000..3dd539ad --- /dev/null +++ b/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumparametersetedit.cpp @@ -0,0 +1,80 @@ +/* + This file is part of the Okteta Kasten module, made within the KDE community. + + Copyright 2019 Lars Maier + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "modsumbytearraychecksumparametersetedit.hpp" + +// parameterset +#include "crc64bytearraychecksumparameterset.hpp" +#include "crc64bytearraychecksumparametersetedit.hpp" +// Okteta Kasten gui +#include +// KF +#include +#include +// Qt +#include + +const char Crc64ByteArrayChecksumParameterSetEdit::Id[] = "Crc64"; + +Crc64ByteArrayChecksumParameterSetEdit::Crc64ByteArrayChecksumParameterSetEdit(QWidget* parent) + : AbstractByteArrayChecksumParameterSetEdit(parent) +{ + auto* baseLayout = new QFormLayout(this); + baseLayout->setContentsMargins(0, 0, 0, 0); + + mVariantComboBox = new KComboBox(this); + //mVariantComboBox->addItem(i18nc("@item:inlistbox", "Custom")); + mVariantComboBox->addItem(i18nc("@item:inlistbox", "ECMA-182")); + mVariantComboBox->addItem(i18nc("@item:inlistbox", "ISO 3309")); + connect(mVariantComboBox, QOverload::of(&KComboBox::activated), + this, &Crc64ByteArrayChecksumParameterSetEdit::valuesChanged); + + const QString byteOrderLabelText = + i18nc("@label:listbox variant used to select the CRC-64 variant", + "CRC-64 variant:"); + const QString groupSizeToolTip = + i18nc("@info:tooltip", + "CRC-64 variant used by calculation."); + mVariantComboBox->setToolTip(groupSizeToolTip); + + baseLayout->addRow(byteOrderLabelText, mVariantComboBox); +} + +Crc64ByteArrayChecksumParameterSetEdit::~Crc64ByteArrayChecksumParameterSetEdit() = default; + +bool Crc64ByteArrayChecksumParameterSetEdit::isValid() const { return true; } + +void Crc64ByteArrayChecksumParameterSetEdit::setParameterSet(const AbstractByteArrayChecksumParameterSet* parameterSet) +{ + const auto* crc64ParameterSet = + static_cast(parameterSet); + + mVariantComboBox->setCurrentIndex(static_cast(crc64ParameterSet->crc64Variant())); +} + +void Crc64ByteArrayChecksumParameterSetEdit::getParameterSet(AbstractByteArrayChecksumParameterSet* parameterSet) const +{ + auto* crc64ParameterSet = + static_cast(parameterSet); + + crc64ParameterSet->setCrc64Variant(static_cast(mVariantComboBox->currentIndex())); +} diff --git a/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumparametersetedit.hpp b/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumparametersetedit.hpp new file mode 100644 index 00000000..e28510d4 --- /dev/null +++ b/kasten/controllers/view/libbytearraychecksum/algorithm/crc64bytearraychecksumparametersetedit.hpp @@ -0,0 +1,51 @@ +/* + This file is part of the Okteta Kasten module, made within the KDE community. + + Copyright 2019 Lars Maier + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef KASTEN_CRC64BYTEARRAYCHECKSUMPARAMETERSETEDIT_HPP +#define KASTEN_CRC64BYTEARRAYCHECKSUMPARAMETERSETEDIT_HPP + +// lib +#include "abstractbytearraychecksumparametersetedit.hpp" + +class KComboBox; + +class Crc64ByteArrayChecksumParameterSetEdit : public AbstractByteArrayChecksumParameterSetEdit +{ + Q_OBJECT + +public: + static const char Id[]; + +public: + explicit Crc64ByteArrayChecksumParameterSetEdit(QWidget* parent = nullptr); + ~Crc64ByteArrayChecksumParameterSetEdit() override; + +public: // AbstractByteArrayFilterParameterSetEdit API + void setParameterSet(const AbstractByteArrayChecksumParameterSet* parameterSet) override; + void getParameterSet(AbstractByteArrayChecksumParameterSet* parameterSet) const override; + bool isValid() const override; + +private: + KComboBox* mVariantComboBox; +}; + +#endif diff --git a/kasten/controllers/view/libbytearraychecksum/bytearraychecksumalgorithmfactory.cpp b/kasten/controllers/view/libbytearraychecksum/bytearraychecksumalgorithmfactory.cpp index 8c38550a..3b3fcc3f 100644 --- a/kasten/controllers/view/libbytearraychecksum/bytearraychecksumalgorithmfactory.cpp +++ b/kasten/controllers/view/libbytearraychecksum/bytearraychecksumalgorithmfactory.cpp @@ -1,96 +1,98 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2009,2011 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ // QCA // need to have this first, as QCA needs QT_NO_CAST_FROM_ASCII disabled when included #include // krazy:excludeall=includes #ifdef HAVE_QCA2 // disable QT_NO_CAST_FROM_ASCII #ifdef QT_NO_CAST_FROM_ASCII #undef QT_NO_CAST_FROM_ASCII #endif #include #endif #include "bytearraychecksumalgorithmfactory.hpp" // lib -#include "algorithm/crc32bytearraychecksumalgorithm.hpp" #include "algorithm/adler32bytearraychecksumalgorithm.hpp" +#include "algorithm/crc32bytearraychecksumalgorithm.hpp" +#include "algorithm/crc64bytearraychecksumalgorithm.hpp" #include "algorithm/modsum8bytearraychecksumalgorithm.hpp" #include "algorithm/modsum16bytearraychecksumalgorithm.hpp" #include "algorithm/modsum32bytearraychecksumalgorithm.hpp" #include "algorithm/modsum64bytearraychecksumalgorithm.hpp" #ifdef HAVE_QCA2 #include "algorithm/qca2bytearraychecksumalgorithm.hpp" #endif // NEWCHECKSUM(start) // Here add the name of your header file of your checksum algorithm, // e.g. // #include "algorithm/mybytearraychecksumalgorithm.hpp" // NEWCHECKSUM(end) // KF #include // Qt #include #ifdef HAVE_QCA2 static inline void addQca2Algorithm(QVector& algorithmList, const QString& name, const char* type) { if (QCA::isSupported(type)) { algorithmList << new Qca2ByteArrayChecksumAlgorithm(name, QString::fromLatin1(type)); } } #endif QVector ByteArrayChecksumAlgorithmFactory::createAlgorithms() { QVector result { new ModSum8ByteArrayChecksumAlgorithm(), new ModSum16ByteArrayChecksumAlgorithm(), new ModSum32ByteArrayChecksumAlgorithm(), new ModSum64ByteArrayChecksumAlgorithm(), new Adler32ByteArrayChecksumAlgorithm(), new Crc32ByteArrayChecksumAlgorithm(), + new Crc64ByteArrayChecksumAlgorithm(), // NEWCHECKSUM(start) // Here add the creation of an object of your checksum algorithm class and add it to the list, // e.g. // new MyByteArrayChecksumAlgorithm(), // NEWCHECKSUM(end) }; #ifdef HAVE_QCA2 addQca2Algorithm(result, i18nc("name of the hash algorithm", "SHA-0"), "sha0"); addQca2Algorithm(result, i18nc("name of the hash algorithm", "SHA-1"), "sha1"); addQca2Algorithm(result, i18nc("name of the hash algorithm", "MD2"), "md2"); addQca2Algorithm(result, i18nc("name of the hash algorithm", "MD4"), "md4"); addQca2Algorithm(result, i18nc("name of the hash algorithm", "MD5"), "md5"); addQca2Algorithm(result, i18nc("name of the hash algorithm", "RIPEMD160"), "ripemd160"); addQca2Algorithm(result, i18nc("name of the hash algorithm", "SHA-224"), "sha224"); addQca2Algorithm(result, i18nc("name of the hash algorithm", "SHA-256"), "sha256"); addQca2Algorithm(result, i18nc("name of the hash algorithm", "SHA-384"), "sha384"); addQca2Algorithm(result, i18nc("name of the hash algorithm", "SHA-512"), "sha512"); addQca2Algorithm(result, i18nc("name of the hash algorithm", "Whirlpool"), "whirlpool"); #endif return result; } diff --git a/kasten/controllers/view/libbytearraychecksum/bytearraychecksumparameterseteditfactory.cpp b/kasten/controllers/view/libbytearraychecksum/bytearraychecksumparameterseteditfactory.cpp index d1078bdb..0a344fa6 100644 --- a/kasten/controllers/view/libbytearraychecksum/bytearraychecksumparameterseteditfactory.cpp +++ b/kasten/controllers/view/libbytearraychecksum/bytearraychecksumparameterseteditfactory.cpp @@ -1,53 +1,56 @@ /* This file is part of the Okteta Kasten module, made within the KDE community. Copyright 2009 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "bytearraychecksumparameterseteditfactory.hpp" // lib +#include "algorithm/crc64bytearraychecksumparametersetedit.hpp" #include "algorithm/modsumbytearraychecksumparametersetedit.hpp" #include "algorithm/nobytearraychecksumparametersetedit.hpp" //// NEWCHECKSUMPARAMETERSET(start) //// Here add the name of your header file of your edit widget for the parameterset, //// e.g. //// #include "algorithm/mybytearraychecksumparametersetedit.hpp" //// NEWCHECKSUMPARAMETERSET(end) AbstractByteArrayChecksumParameterSetEdit* ByteArrayChecksumParameterSetEditFactory::createEdit(const char* id) { AbstractByteArrayChecksumParameterSetEdit* result; if (qstrcmp(id, ModSumByteArrayChecksumParameterSetEdit::Id) == 0) { result = new ModSumByteArrayChecksumParameterSetEdit(); + } else if (qstrcmp(id, Crc64ByteArrayChecksumParameterSetEdit::Id) == 0) { + result = new Crc64ByteArrayChecksumParameterSetEdit(); } //// NEWCHECKSUMPARAMETERSET(start) //// Here add the check for the id of your parameter set //// and, if it matches, the creation of the widget //// e.g. //// else if (qstrcmp(id, MyByteArrayChecksumParameterSetEdit::Id) == 0) //// result = new MyByteArrayChecksumParameterSetEdit(); //// NEWCHECKSUMPARAMETERSET(end) else { // if (qstrcmp(id, NoByteArrayChecksumParameterSetEdit::Id) == 0) TODO: default should be a message "Not found" result = new NoByteArrayChecksumParameterSetEdit(); } return result; }