Skip to content

Commit

Permalink
fix: return type
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos authored and backportbot-libresign[bot] committed Feb 4, 2025
1 parent 0223257 commit f0d0f9e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
8 changes: 2 additions & 6 deletions lib/Handler/ISignEngineHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ public function setCertificate(string $certificate): self;
public function getCertificate(): string;
public function setPassword(string $password): self;
public function getPassword(): string;
/**
* Sign a file
*
* @return string|\OCP\Files\Node string of signed file or Node of signed file
*/
public function sign();
public function sign(): File;
public function getSignedContent(): string;
}
12 changes: 8 additions & 4 deletions lib/Handler/JSignPdfHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\Exception\LibresignException;
use OCA\Libresign\Service\Install\InstallService;
use OCP\Files\File;
use OCP\IAppConfig;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -92,10 +93,13 @@ private function getHashAlgorithm(): string {
return 'SHA256';
}

/**
* @psalm-suppress MixedReturnStatement
*/
public function sign(): string {
public function sign(): File {
$signedContent = $this->getSignedContent();
$this->getInputFile()->putContent($signedContent);
return $this->getInputFile();
}

public function getSignedContent(): string {
$param = $this->getJSignParam()
->setCertificate($this->getCertificate())
->setPdf($this->getInputFile()->getContent())
Expand Down
2 changes: 1 addition & 1 deletion lib/Handler/Pkcs12Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public function sign(): File {
->setInputFile($this->getInputFile())
->setPassword($this->getPassword())
->setVisibleElements($this->getVisibleElements())
->sign();
->getSignedContent();
$this->getInputFile()->putContent($signedContent);
return $this->getInputFile();
}
Expand Down
12 changes: 4 additions & 8 deletions lib/Handler/Pkcs7Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,11 @@
namespace OCA\Libresign\Handler;

use OCP\Files\File;
use OCP\Files\Node;

/**
* @codeCoverageIgnore
*/
class Pkcs7Handler extends SignEngineHandler {
/**
* @psalm-suppress MixedReturnStatement
*
* @param Node $fileToSign
* @param Node $certificate
* @param string $passphrase
*/
public function sign(): File {
$p7sFile = $this->getP7sFile();
openssl_pkcs12_read($this->getCertificate(), $certificateData, $this->getPassword());
Expand All @@ -36,6 +28,10 @@ public function sign(): File {
return $p7sFile;
}

public function getSignedContent(): string {
return $this->sign()->getContent();
}

public function getP7sFile(): File {
$newName = $this->getInputFile()->getName() . '.p7s';
$p7sFile = $this->getInputFile()
Expand Down
4 changes: 4 additions & 0 deletions lib/Handler/SignEngineHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ public function setVisibleElements(array $visibleElements): self {
public function getVisibleElements(): array {
return $this->visibleElements;
}

public function getSignedContent(): string {
return $this->sign()->getContent();
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Handler/JSignPdfHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testSignExistingFileSuccess():void {
$this->class->setInputFile($inputFile);
$this->class->setCertificate('');
$this->class->setPassword('password');
$actual = $this->class->sign();
$actual = $this->class->getSignedContent();
$this->assertEquals('content', $actual);
}
}

0 comments on commit f0d0f9e

Please sign in to comment.