Function : Note

NSFNoteSignExt - Sign all or specific items in a note and append a signature item to the note.
----------------------------------------------------------------------------------------------------------

#include <nsfnote.h>

STATUS LNPUBLIC NSFNoteSignExt(
NOTEHANDLE hNote,
const char far *SignatureItemName,
WORD ItemCount,
DHANDLE hItemIDs
);

Description :

Use this function to sign one section of a document. This function works just like NSFNoteSign, but provides the added flexibility needed to sign just the fields that reside in a section of a document, and to give the signature item the appropriate name. Use NSFNoteSign() to sign the entire document.

NSFNoteSignExt generates a signature item with the specified name and appends this signature item to the note. A signature item has data type TYPE_SIGNATURE and item flags ITEM_SEAL. The data value of the signature item is a digest of the data stored in items in the note, signed with the user's private key.

To sign all the fields that reside in one section of a note, you need the name of the section and the BLOCKIDs of all the items in the section. Format a signature item name as a zero-terminated ASCI string of the form $Sig_<sectionname>. Allocate a block of memory in which to store an array of item BLOCKIDs. Initialize this array with the BLOCKIDs of all the items in the section. Then call NSFNoteSignExt specifying the handle to the note, the signature item name, the count of items in the section, and the handle to the block of memory containing the array of item BLOCKIDs. NSFNoteSignExt will create a digital signature from the specified items and append this digital signature item to the note.


Parameters :

Sample Usage :

STATUS error;
NOTEHANDLE  hNote;
char *szSectionName;
char szSigItemName[ITEM_NAME_MAX+1];
char *aszItemNames[NUM_ITEMS_IN_SECTION];
DHANDLE hItemBLOCKIDs;
BLOCKID *pItemBLOCKID;
int i;
WORD    wType;
BLOCKID bhValue;
DWORD   dwLength;


/* hNote is the handle to an open document that includes a section. The
  name of this section is specified in szSectionName. There are
  NUM_ITEMS_IN_SECTION items in this section. The array aszItemNames[]
  contains the field names of all the items in this section.
  First, format a name for the signature item.
*/

strcpy(szSigItemName, ITEM_NAME_NOTE_SIG_PREFIX);
strncat(szSigItemName, szSectionName, ITEM_NAME_MAX);

/* Allocate and initialize an array of BLOCKIDs of items in the section */

if (error = OSMemAlloc(0, NUM_ITEMS_IN_SECTION * sizeof(BLOCKID),
                      &hItemBLOCKIDs))
{
   return(error);
}

pItemBLOCKIDs = (BLOCKID*)OSLockObject(hItemBLOCKIDs);

for (i = 0; i < NUM_ITEMS_IN_SECTION; i++)
{
   if (error = NSFItemInfo(hNote, szSigItemName[i],
               strlen(szSigItemName[i]), &pItemBLOCKIDs[i],
               &wType, &bhValue, &dwLength))
   {
       OSUnlockObject(hItemBLOCKIDs);
       OSMemFree(hItemBLOCKIDs);
       return(error);
   }
}


OSUnlockObject(hItemBLOCKIDs);

/* sign the items in the section */

if (error = NSFNoteSignExt( hNote,
                           szSigItemName,
                           NUM_ITEMS_IN_SECTION,
                           hItemBLOCKIDs ))
{
   OSMemFree(hItemBLOCKIDs);
   return(error);
}

OSMemFree(hItemBLOCKIDs);


See Also :

NSFNoteSign
----------------------------------------------------------------------------------------------------------