The recommended/official way for signing a PDF document is by registering a callback function.

This "mixes" the process of preparing the document and generating the signature to embed.

In my use case it is "necessary" to split the signing process in multiple parts:

1) preparing the document (hashing the content in this step is fine)
2) sign the document/the calculated hash
3) put the signature in the document

This is possible, but not so practical.

In the callback it is obviously possible not to generate any signature (and eventually just hash the content and save the hash somewhere), but as a user of PoDoFo I have no idea what is the ByteRange I just hashed/where I have to place the signature.

Of course it is possible to parse the document and search for the last signature... but the signing process is split in multiple parts also because of performance reasons...

Another "trick" is putting a dummy signature with some well-known value in the document and "grep" for it afterwards... but in some scenarios it can cause problem/get more complicated...

Fortunately the fix is easy, as AdjustByteRange is a void function.
As it's role is to "adjust the ByteRange" it seems like a sensible operation to return the calculated value for those interested.

Users can ignore the return value, and use only the callback approach as before (thus the API for those users is unchanged), and for those that needs to split the creation of the resulting document and signing as much as possible can reliably know where to put the signature.

Federico
Index: src/podofo/doc/PdfSignOutputDevice.cpp
===================================================================
--- src/podofo/doc/PdfSignOutputDevice.cpp	(revision 2029)
+++ src/podofo/doc/PdfSignOutputDevice.cpp	(working copy)
@@ -137,7 +137,7 @@
     }
 }
 
-void PdfSignOutputDevice::AdjustByteRange()
+PdfArray PdfSignOutputDevice::AdjustByteRange()
 {
     if(!m_bBeaconFound) {
         PODOFO_RAISE_ERROR( ePdfError_InternalLogic );
@@ -185,6 +185,7 @@
 
     m_pRealDevice->Seek(offset);
     m_pRealDevice->Write(sPosition.c_str(), sPosition.size());
+    return arr;
 }
 
 size_t PdfSignOutputDevice::ReadForSignature(char* pBuffer, size_t lLen)
Index: src/podofo/doc/PdfSignOutputDevice.h
===================================================================
--- src/podofo/doc/PdfSignOutputDevice.h	(revision 2029)
+++ src/podofo/doc/PdfSignOutputDevice.h	(working copy)
@@ -38,6 +38,7 @@
 #include "../base/PdfOutputDevice.h"
 #include "../base/PdfData.h"
 #include "../base/PdfString.h"
+#include "../base/PdfArray.h"
 
 namespace PoDoFo 
 {
@@ -83,7 +84,7 @@
     /** Modify ByteRange entry according to signature position
      *
      */
-    virtual void AdjustByteRange();
+    virtual PdfArray AdjustByteRange();
 
     /** Read data for signature
      */
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to