File indexing completed on 2024-06-16 04:55:55

0001 /* -*- mode: c++; c-basic-offset:4 -*-
0002     crypto/checksumsutils_p.h
0003 
0004     This file is part of Kleopatra, the KDE keymanager
0005     SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include "kleopatra_debug.h"
0013 
0014 #include <QRegularExpression>
0015 
0016 namespace Kleo
0017 {
0018 class ChecksumDefinition;
0019 }
0020 
0021 namespace ChecksumsUtils
0022 {
0023 #ifdef Q_OS_UNIX
0024 // Can we use QAbstractFileEngine::caseSensitive()?
0025 static const Qt::CaseSensitivity fs_cs = Qt::CaseSensitive;
0026 
0027 static const QRegularExpression::PatternOption s_regex_cs = QRegularExpression::NoPatternOption;
0028 #else
0029 static const Qt::CaseSensitivity fs_cs = Qt::CaseInsensitive;
0030 static const QRegularExpression::PatternOption s_regex_cs = QRegularExpression::CaseInsensitiveOption;
0031 #endif
0032 
0033 std::vector<QRegularExpression> get_patterns(const std::vector<std::shared_ptr<Kleo::ChecksumDefinition>> &checksumDefinitions);
0034 
0035 struct matches_any {
0036     const std::vector<QRegularExpression> m_regexps;
0037     explicit matches_any(const std::vector<QRegularExpression> &regexps)
0038         : m_regexps(regexps)
0039     {
0040     }
0041     bool operator()(const QString &s) const
0042     {
0043         return std::any_of(m_regexps.cbegin(), m_regexps.cend(), [&s](const QRegularExpression &rx) {
0044             return rx.match(s).hasMatch();
0045         });
0046     }
0047 };
0048 
0049 struct File {
0050     QString name;
0051     QByteArray checksum;
0052     bool binary;
0053 };
0054 
0055 std::vector<File> parse_sum_file(const QString &fileName);
0056 
0057 std::shared_ptr<Kleo::ChecksumDefinition> filename2definition(const QString &fileName,
0058                                                               const std::vector<std::shared_ptr<Kleo::ChecksumDefinition>> &checksumDefinitions);
0059 
0060 } // namespace ChecksumsUtils