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

feat: add reason of signature #4592

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
7 changes: 6 additions & 1 deletion lib/Handler/JSignPdfHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ private function signWrapper(JSignPDF $jSignPDF): string {
$param
->setJSignParameters(
$this->jSignParam->getJSignParameters() .
' --hash-algorithm ' . $this->getHashAlgorithm()
' --hash-algorithm ' . $this->getHashAlgorithm() .
(
$this->getReason()
? ' --reason "' . $this->getReason() . '"'
: ''
)
);
$jSignPDF->setParam($param);
return $jSignPDF->sign();
Expand Down
1 change: 1 addition & 0 deletions lib/Handler/Pkcs12Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ public function sign(): File {
->setInputFile($this->getInputFile())
->setPassword($this->getPassword())
->setVisibleElements($this->getVisibleElements())
->setReason($this->getReason())
->sign();
$this->getInputFile()->putContent($signedContent);
return $this->getInputFile();
Expand Down
10 changes: 10 additions & 0 deletions lib/Handler/SignEngineHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ abstract class SignEngineHandler implements ISignEngineHandler {
private File $inputFile;
private string $certificate;
private string $password = '';
private string $reason = '';
/** @var VisibleElementAssoc[] */
private array $visibleElements = [];

Expand Down Expand Up @@ -54,6 +55,15 @@ public function getPassword(): string {
return $this->password;
}

public function setReason(string $reason): self {
$this->reason = $reason;
return $this;
}

public function getReason(): string {
return $this->reason;
}

/**
* @param VisibleElementAssoc[] $visibleElements
*
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/SignFileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
return $this;
}

public function sign(): File {

Check failure on line 259 in lib/Service/SignFileService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

InvalidReturnType

lib/Service/SignFileService.php:259:26: InvalidReturnType: The declared return type 'OCP\Files\File' for OCA\Libresign\Service\SignFileService::sign is incorrect, got 'OCP\Files\Node|string' (see https://psalm.dev/011)
$fileToSign = $this->getFileToSing($this->libreSignFile);
$pfxFileContent = $this->getPfxFile();
switch (strtolower($fileToSign->getExtension())) {
Expand All @@ -266,6 +266,9 @@
->setCertificate($pfxFileContent)
->setVisibleElements($this->elements)
->setPassword($this->password)
->setReason($this->l10n->t('Signed by %s with LibreSign.coop', [
$this->signRequest->getDisplayName() . ' <' . $this->userUniqueIdentifier . '>'
]))
->sign();
break;
default:
Expand All @@ -292,7 +295,7 @@

$this->eventDispatcher->dispatchTyped(new SignedEvent($this, $signedFile, $allSigned));

return $signedFile;

Check failure on line 298 in lib/Service/SignFileService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

InvalidReturnStatement

lib/Service/SignFileService.php:298:10: InvalidReturnStatement: The inferred type 'OCP\Files\Node|string' does not match the declared return type 'OCP\Files\File' for OCA\Libresign\Service\SignFileService::sign (see https://psalm.dev/128)
}

public function storeUserMetadata(array $metadata = []): self {
Expand Down
Loading