• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eliashaeussler / typo3-form-consent / 26600856469

28 May 2026 08:38PM UTC coverage: 91.598% (-3.1%) from 94.724%
26600856469

Pull #495

github

eliashaeussler
[TASK] Restructure CI and build tools
Pull Request #495: [TASK] Restructure CI and build tools

1 of 1 new or added line in 1 file covered. (100.0%)

36 existing lines in 3 files now uncovered.

774 of 845 relevant lines covered (91.6%)

16.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/Classes/Compatibility/Migration/HmacHashMigration.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "form_consent".
7
 *
8
 * Copyright (C) 2021-2026 Elias Häußler <elias@haeussler.dev>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace EliasHaeussler\Typo3FormConsent\Compatibility\Migration;
25

26
use TYPO3\CMS\Core;
27
use TYPO3\CMS\Extbase;
28
use TYPO3\CMS\Form;
29

30
/**
31
 * HmacHashMigration
32
 *
33
 * @author Elias Häußler <elias@haeussler.dev>
34
 * @license GPL-2.0-or-later
35
 * @internal
36
 */
37
final readonly class HmacHashMigration
38
{
39
    private const LEGACY_HASH_LENGTH = 40;
40

41
    private Core\Information\Typo3Version $typo3Version;
42

43
    public function __construct(
26✔
44
        private Core\Crypto\HashService $hashService,
45
    ) {
46
        $this->typo3Version = new Core\Information\Typo3Version();
26✔
47
    }
48

49
    public function migrate(string $string, Extbase\Security\HashScope|Form\Security\HashScope $hashScope): string
19✔
50
    {
51
        // Early return if string does not have HMAC appended
52
        if (strlen($string) < self::LEGACY_HASH_LENGTH) {
19✔
53
            return $string;
1✔
54
        }
55

56
        // Validate hash
57
        try {
58
            $this->validateHashedString($string, $hashScope);
18✔
59

60
            // Hash is valid
61
            return $string;
11✔
62
        } catch (Core\Exception\Crypto\InvalidHashStringException) {
7✔
63
            // Hash is invalid and needs migration
64
        }
65

66
        /** @var non-empty-string $string */
67
        $string = substr($string, 0, -self::LEGACY_HASH_LENGTH);
7✔
68

69
        return $this->migrateString($string, $hashScope);
7✔
70
    }
71

72
    /**
73
     * @param non-empty-string $string
74
     */
75
    private function validateHashedString(string $string, Extbase\Security\HashScope|Form\Security\HashScope $hashScope): void
18✔
76
    {
77
        if ($this->typo3Version->getMajorVersion() === 13) {
18✔
78
            // @todo Remove once support for TYPO3 v13 is dropped
UNCOV
79
            $this->hashService->validateAndStripHmac($string, $hashScope->prefix());
×
80
        } else {
81
            $this->hashService->validateAndStripHmac($string, $hashScope->prefix(), $this->getRequiredHashAlgo($hashScope));
18✔
82
        }
83
    }
84

85
    /**
86
     * @param non-empty-string $string
87
     */
88
    private function migrateString(string $string, Extbase\Security\HashScope|Form\Security\HashScope $hashScope): string
7✔
89
    {
90
        // @todo Remove once support for TYPO3 v13 is dropped
91
        if ($this->typo3Version->getMajorVersion() === 13) {
7✔
UNCOV
92
            return $this->hashService->appendHmac($string, $hashScope->prefix());
×
93
        }
94

95
        return $this->hashService->appendHmac($string, $hashScope->prefix(), $this->getRequiredHashAlgo($hashScope));
7✔
96
    }
97

98
    private function getRequiredHashAlgo(Extbase\Security\HashScope|Form\Security\HashScope $hashScope): Core\Crypto\HashAlgo
18✔
99
    {
100
        if ($hashScope === Form\Security\HashScope::ResourcePointer) {
18✔
101
            return Core\Crypto\HashAlgo::SHA1;
4✔
102
        }
103

104
        return Core\Crypto\HashAlgo::SHA3_256;
16✔
105
    }
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc