Merge pull request 'Allow the signature_index to be None' (#3) from test-ts-sign into main
All checks were successful
Build image and push it to registry / build (push) Successful in 1m40s

Reviewed-on: #3
This commit is contained in:
Julien Fastré 2024-10-16 07:13:38 +00:00
commit 8c5950b37f
2 changed files with 5 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import io
from random import randint
from typing import Optional
from pyhanko import stamp
@ -49,8 +50,8 @@ class SignOrchestrator:
reason=reason,
)
def sign(self, reason: str, signature_index: int, input_content: Buffer, on_page: int, box_place: (int, int, int, int), signer_text: str) -> io.BytesIO:
field_name = 'Signature' + str(signature_index)
def sign(self, reason: str, signature_index: int|None, input_content: Buffer, on_page: int, box_place: (int, int, int, int), signer_text: str) -> io.BytesIO:
field_name = 'Signature' + str(signature_index) if signature_index is not None else 'Signature'+ str(randint(1000, 99999999999))
signature_meta = self._make_signature_metadata(reason, field_name)
pdf_signer = signers.PdfSigner(

View File

@ -13,7 +13,7 @@ orchestrator = SignOrchestrator('./assets/dummy.p12',
pkcs12_password=None)
with open('./assets/test.pdf', 'rb') as input:
signed_content = orchestrator.sign(reason="first signer", signature_index=0,
signed_content = orchestrator.sign(reason="first signer", signature_index=None,
input_content=input.read(), box_place=(300, 600, 500, 660), on_page=0,
signer_text="Mme Caroline Diallo")
@ -21,7 +21,7 @@ with open('./assets/test.pdf', 'rb') as input:
output.write(signed_content.read())
with open('./assets/test_signed_0.pdf', 'rb') as input:
signed_content = orchestrator.sign(reason="second signer", signature_index=1,
signed_content = orchestrator.sign(reason="second signer", signature_index=None,
input_content=input.read(), box_place=(100, 600, 300, 660), on_page=0,
signer_text="M. Bah Mamadou")