Allow the signature_index to be None #3

Merged
julienfastre merged 1 commits from test-ts-sign into main 2024-10-16 07:13:38 +00:00
2 changed files with 5 additions and 4 deletions
Showing only changes of commit 34857ae4b0 - Show all commits

View File

@ -1,4 +1,5 @@
import io import io
from random import randint
from typing import Optional from typing import Optional
from pyhanko import stamp from pyhanko import stamp
@ -49,8 +50,8 @@ class SignOrchestrator:
reason=reason, 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: 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) 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) signature_meta = self._make_signature_metadata(reason, field_name)
pdf_signer = signers.PdfSigner( pdf_signer = signers.PdfSigner(

View File

@ -13,7 +13,7 @@ orchestrator = SignOrchestrator('./assets/dummy.p12',
pkcs12_password=None) pkcs12_password=None)
with open('./assets/test.pdf', 'rb') as input: 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, input_content=input.read(), box_place=(300, 600, 500, 660), on_page=0,
signer_text="Mme Caroline Diallo") signer_text="Mme Caroline Diallo")
@ -21,7 +21,7 @@ with open('./assets/test.pdf', 'rb') as input:
output.write(signed_content.read()) output.write(signed_content.read())
with open('./assets/test_signed_0.pdf', 'rb') as input: 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, input_content=input.read(), box_place=(100, 600, 300, 660), on_page=0,
signer_text="M. Bah Mamadou") signer_text="M. Bah Mamadou")