Individual Module

Table of Contents

  1. Introduction
    1. Example

      Introduction

      By abstracting the existing modules it is possible to create own modules that may use other signature backends to create the signature. This way it may be possible to e.g. extend the OpenSSL CMS module, and implement the handling of an OpenSSL engine.

      Additional interfaces are available which allow modifications of the signature dictionary or the document instance: SetaPDF_Signer_Signature_DictionaryInterface and SetaPDF_Signer_Signature_DocumentInterface

      Example

      PHP
      <?php
      class MySignatureModule implements 
          SetaPDF_Signer_Signature_Module_ModuleInterface,
          SetaPDF_Signer_Signature_DictionaryInterface.
          SetaPDF_Signer_Signature_DocumentInterface
      {
          /**
           * Create a signature for the file in the given $tmpPath.
           *
           * @param SetaPDF_Core_Reader_FilePath $tmpPath
           * @return string
           */
          public function createSignature(SetaPDF_Core_Reader_FilePath $tmpPath)
          {
              // get hash
              $hashAlgorithm = 'sha256';
              $hashValue = hash_file($hashAlgorithm, $tmpPath);
      
              // e.g. call an external webservice to create the signature
              $signature = callWebserviceToCreateSignature($hashValue, $hashAlgorithm);
      
              // return the signature value
              return $signature;
          }
      
          /**
           * Method to update the signature dictionary.
           *
           * @param SetaPDF_Core_Type_Dictionary $dictionary
           */
          public function updateSignatureDictionary(SetaPDF_Core_Type_Dictionary $dictionary)
          {
              // update the signature dictionary if needed
          }
      
          /**
           * Method to allow updates onto the document instance.
           *
           * @param SetaPDF_Core_Document $document
           */
          public function updateDocument(SetaPDF_Core_Document $document)
          {
              // make changes or check to the document instance
          }
      }