Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable31] chore: remove wrong annotation #4604

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 4 additions & 6 deletions lib/Handler/SignEngineHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public function getInputFile(): File {
return $this->inputFile;
}

/**
* @return static
*/
public function setCertificate(string $certificate): self {
$this->certificate = $certificate;
return $this;
Expand All @@ -42,9 +39,6 @@ public function getCertificate(): string {
return $this->certificate;
}

/**
* @return static
*/
public function setPassword(string $password): self {
$this->password = $password;
return $this;
Expand Down Expand Up @@ -72,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);
}
}
Loading