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: Support Signing sha256 digest of a pdf file #3612

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
26 changes: 13 additions & 13 deletions lib/Service/SignFileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use OCA\Libresign\Db\FileMapper;
use OCA\Libresign\Db\IdentifyMethod;
use OCA\Libresign\Db\IdentifyMethodMapper;
use OCA\Libresign\Db\SignRequest as SignRequestEntity;
use OCA\Libresign\Db\SignRequest;
use OCA\Libresign\Db\SignRequestMapper;
use OCA\Libresign\Db\UserElementMapper;
use OCA\Libresign\Events\SignedEvent;
Expand Down Expand Up @@ -54,7 +54,7 @@
use TypeError;

class SignFileService {
/** @var SignRequestEntity */
/** @var SignRequest */
private $signRequest;
/** @var string */
private $password;
Expand Down Expand Up @@ -115,7 +115,7 @@ public function canDeleteRequestSignature(array $data): void {
throw new \Exception($this->l10n->t('Document already signed'));
}
array_walk($data['users'], function ($user) use ($signatures) {
$exists = array_filter($signatures, function (SignRequestEntity $signRequest) use ($user) {
$exists = array_filter($signatures, function (SignRequest $signRequest) use ($user) {
$identifyMethod = $this->identifyMethodService->getIdentifiedMethod($signRequest->getId());
if ($identifyMethod->getName() === 'email') {
return $identifyMethod->getEntity()->getIdentifierValue() === $user['email'];
Expand Down Expand Up @@ -188,7 +188,7 @@ public function setFriendlyName(string $friendlyName): self {
/**
* @return static
*/
public function setSignRequest(SignRequestEntity $signRequest): self {
public function setSignRequest(SignRequest $signRequest): self {
$this->signRequest = $signRequest;
return $this;
}
Expand Down Expand Up @@ -312,7 +312,7 @@ public function storeUserMetadata(array $metadata = []): self {
}

/**
* @return SignRequestEntity[]
* @return SignRequest[]
*/
private function getSigners(): array {
if (empty($this->signers)) {
Expand Down Expand Up @@ -425,7 +425,7 @@ public function getLibresignFile(?int $nodeId, ?string $signRequestUuid = null):
return $libresignFile;
}

public function renew(SignRequestEntity $signRequest, string $method): void {
public function renew(SignRequest $signRequest, string $method): void {
$identifyMethods = $this->identifyMethodService->getIdentifyMethodsFromSignRequestId($signRequest->getId());
if (empty($identifyMethods[$method])) {
throw new LibresignException($this->l10n->t('Invalid identification method'));
Expand All @@ -443,7 +443,7 @@ public function renew(SignRequestEntity $signRequest, string $method): void {
}

public function requestCode(
SignRequestEntity $signRequest,
SignRequest $signRequest,
string $identifyMethodName,
string $signMethodName,
string $identify = ''
Expand All @@ -466,15 +466,15 @@ public function requestCode(
throw new LibresignException($this->l10n->t('Sending authorization code not enabled.'));
}

public function getSignRequestToSign(FileEntity $libresignFile, ?string $signRequestUuid, ?IUser $user): SignRequestEntity {
public function getSignRequestToSign(FileEntity $libresignFile, ?string $signRequestUuid, ?IUser $user): SignRequest {
$this->validateHelper->fileCanBeSigned($libresignFile);
try {
$signRequests = $this->signRequestMapper->getByFileId($libresignFile->getId());

if (!empty($signRequestUuid)) {
$signRequest = $this->getSignRequest($signRequestUuid);
} else {
$signRequest = array_reduce($signRequests, function (?SignRequestEntity $carry, SignRequestEntity $signRequest) use ($user): ?SignRequestEntity {
$signRequest = array_reduce($signRequests, function (?SignRequest $carry, SignRequest $signRequest) use ($user): ?SignRequest {
$identifyMethods = $this->identifyMethodMapper->getIdentifyMethodsFromSignRequestId($signRequest->getId());
$found = array_filter($identifyMethods, function (IdentifyMethod $identifyMethod) use ($user) {
if ($identifyMethod->getIdentifierKey() === IdentifyMethodService::IDENTIFY_EMAIL
Expand Down Expand Up @@ -512,7 +512,7 @@ public function getSignRequestToSign(FileEntity $libresignFile, ?string $signReq
throw new LibresignException($this->l10n->t('Invalid data to sign file'), 1);
}
$this->validateHelper->userCanApproveValidationDocuments($user);
$signRequest = new SignRequestEntity();
$signRequest = new SignRequest();
$signRequest->setFileId($libresignFile->getId());
$signRequest->setDisplayName($user->getDisplayName());
$signRequest->setUuid(UUIDUtil::getUUID());
Expand Down Expand Up @@ -545,7 +545,7 @@ private function getPdfToSign(FileEntity $fileData, File $originalFile): File {
);

$footer = $this->footerHandler
->setTemplateVar('signers', array_map(function (SignRequestEntity $signer) {
->setTemplateVar('signers', array_map(function (SignRequest $signer) {
return [
'displayName' => $signer->getDisplayName(),
'signed' => $signer->getSigned(),
Expand Down Expand Up @@ -614,7 +614,7 @@ private function forceSaveFileOfDifferentUser(string $path, string $content): \O
/**
* @throws DoesNotExistException
*/
public function getSignRequest(string $uuid): SignRequestEntity {
public function getSignRequest(string $uuid): SignRequest {
$this->validateHelper->validateUuidFormat($uuid);
return $this->signRequestMapper->getByUuid($uuid);
}
Expand Down Expand Up @@ -662,7 +662,7 @@ public function validateRenewSigner(string $uuid, ?IUser $user = null): void {
$this->validateHelper->validateRenewSigner($uuid, $user);
}

public function getSignerData(?IUser $user, ?SignRequestEntity $signRequest = null): array {
public function getSignerData(?IUser $user, ?SignRequest $signRequest = null): array {
$return = ['user' => ['name' => null]];
if ($signRequest) {
$return['user']['name'] = $signRequest->getDisplayName();
Expand Down
Loading