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

LibreSign / libresign / 22603185457

03 Mar 2026 12:58AM UTC coverage: 53.56%. First build
22603185457

Pull #2595

github

web-flow
Merge df6ade764 into 94e35a169
Pull Request #2595: [WIP] Sign usign only PHP

0 of 56 new or added lines in 3 files covered. (0.0%)

9583 of 17892 relevant lines covered (53.56%)

6.39 hits per line

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

0.0
/lib/Handler/PhpNativeHandler.php
1
<?php
2

3
declare(strict_types=1);
4
/**
5
 * @copyright Copyright (c) 2023 Vitor Mattos <vitor@php.rio>
6
 *
7
 * @author Vitor Mattos <vitor@php.rio>
8
 *
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24

25
namespace OCA\Libresign\Handler;
26

27
use OCP\AppFramework\Services\IAppConfig;
28
use Psr\Log\LoggerInterface;
29

30
class PhpNativeHandler extends SignEngineHandler {
31
        public function __construct(
32
                private IAppConfig $appConfig,
33
                private LoggerInterface $logger,
34
        ) {
NEW
35
        }
×
36

37
        /**
38
         * @psalm-suppress MixedReturnStatement
39
         */
40
        public function sign(): string {
NEW
41
                $param = $this->getJSignParam()
×
NEW
42
                        ->setCertificate($this->getCertificate())
×
NEW
43
                        ->setPdf($this->getInputFile()->getContent())
×
NEW
44
                        ->setPassword($this->getPassword());
×
45

NEW
46
                $signed = $this->signUsingVisibleElements();
×
NEW
47
                if ($signed) {
×
NEW
48
                        return $signed;
×
49
                }
NEW
50
                $jSignPdf = $this->getJSignPdf();
×
NEW
51
                $jSignPdf->setParam($param);
×
NEW
52
                return $this->signWrapper($jSignPdf);
×
53
        }
54

55
        private function signUsingVisibleElements(): string {
NEW
56
                $visibleElements = $this->getvisibleElements();
×
NEW
57
                if ($visibleElements) {
×
NEW
58
                        $jSignPdf = $this->getJSignPdf();
×
NEW
59
                        $param = $this->getJSignParam();
×
NEW
60
                        foreach ($visibleElements as $element) {
×
NEW
61
                                $param
×
NEW
62
                                        ->setJSignParameters(
×
NEW
63
                                                $param->getJSignParameters() .
×
NEW
64
                                                ' -pg ' . $element->getFileElement()->getPage() .
×
NEW
65
                                                ' -llx ' . $element->getFileElement()->getLlx() .
×
NEW
66
                                                ' -lly ' . $element->getFileElement()->getLly() .
×
NEW
67
                                                ' -urx ' . $element->getFileElement()->getUrx() .
×
NEW
68
                                                ' -ury ' . $element->getFileElement()->getUry() .
×
NEW
69
                                                ' --l2-text ""' .
×
NEW
70
                                                ' -V' .
×
NEW
71
                                                ' --bg-path ' . $element->getTempFile()
×
NEW
72
                                        );
×
NEW
73
                                $jSignPdf->setParam($param);
×
NEW
74
                                $signed = $this->signWrapper($jSignPdf);
×
75
                        }
NEW
76
                        return $signed;
×
77
                }
NEW
78
                return '';
×
79
        }
80

81
        private function signWrapper(JSignPDF $jSignPDF): string {
82
                try {
NEW
83
                        return $jSignPDF->sign();
×
NEW
84
                } catch (\Throwable $th) {
×
NEW
85
                        $rows = str_getcsv($th->getMessage());
×
NEW
86
                        $hashAlgorithm = array_filter($rows, fn ($r) => str_contains($r, 'The chosen hash algorithm'));
×
NEW
87
                        if (!empty($hashAlgorithm)) {
×
NEW
88
                                $hashAlgorithm = current($hashAlgorithm);
×
NEW
89
                                $hashAlgorithm = trim($hashAlgorithm, 'INFO ');
×
NEW
90
                                $hashAlgorithm = str_replace('\"', '"', $hashAlgorithm);
×
NEW
91
                                $hashAlgorithm = preg_replace('/\.( )/', ".\n", $hashAlgorithm);
×
NEW
92
                                throw new LibresignException($hashAlgorithm);
×
93
                        }
NEW
94
                        $this->logger->error('Error at JSignPdf side. LibreSign can not do nothing. Follow the error message: ' . $th->getMessage());
×
NEW
95
                        throw new \Exception($th->getMessage());
×
96
                }
97
        }
98
}
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