Skip to content

Give each signature field a unique name - #384

Open
AlexanderV wants to merge 1 commit into
empira:masterfrom
AlexanderV:upstream/signature-field-names
Open

Give each signature field a unique name#384
AlexanderV wants to merge 1 commit into
empira:masterfrom
AlexanderV:upstream/signature-field-names

Conversation

@AlexanderV

Copy link
Copy Markdown

The partial name of a signature field is hard-coded, with a TODO next to it (DigitalSignatureHandler.cs):

signatureField.Elements.Add(PdfFormField.Keys.T, new PdfString("Signature1")); // TODO If already exists, will it cause error? implement a name chooser if yes.

The answer to the TODO is yes: signing a document that already contains a signature produces a second field named Signature1. The fully qualified names of interactive form fields must be unique; validators either merge the two fields or reject the file.

The first unused SignatureN is now chosen by scanning the names of the fields at the root of the interactive form. Only the root is relevant, because the new field is added there — the name of a field below the root is relative to the name of its parent and cannot collide with a root name.

Tests (Pdf.Signatures/SignatureFieldNameTests.cs, 3 cases): a new document gets Signature1; signing an already signed document gets Signature2; an unrelated field that already occupies Signature1 is respected.

The tests use a dummy IDigitalSigner and an empty appearance handler (Pdf.Signatures/TestSigner.cs), so they need no certificate, no assets and no network, and they run in milliseconds.

Verified on top of current master: full PdfSharp.Tests suite green (255 passed, 0 failed).

This PR is independent of my other PRs; each of them applies to master on its own.

The partial name of the signature field was hard-coded to "Signature1"
(with a TODO). Signing a document a second time therefore produced two
fields named "Signature1". The fully qualified names of interactive form
fields must be unique; validators like Acrobat either merge or reject the
duplicate. The first unused "SignatureN" is now chosen by scanning the
names of the fields at the root of the interactive form.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants