Compare commits

..

2 Commits

Author SHA1 Message Date
8c5950b37f 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
2024-10-16 07:13:38 +00:00
34857ae4b0
Allow the signature_index to be None
When the signature_index is not set, the name's sinature zone is generated from a random int.
2024-10-15 07:47:58 +02:00
2 changed files with 5 additions and 4 deletions

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")