next up previous contents
Next: Platform specific header Up: PKCS #11 Previous: Function definitions   Contents


Templates

A common way of conversing with PKCS #11 is through templates. You create a template containing the type of information or result you need, and when you call a specific function with that template, the engine will fill it in for you.

Most functions that provide information, or generate data, are called like this:

  1. Create template
  2. Set template parameters
  3. Call function with template
  4. Read template results

One possible result, if specified by the caller, is to only set information about the amount of memory needed for the result data, and not set the result data itself. The usual way this is used is this:

  1. Create template
  2. Set NULL pointers for result data
  3. Call function with template
  4. Read the result sizes, and allocate memory
  5. Set the allocation result pointers in the template
  6. Call function with template again

This way, an application does not need to guess how much memory it needs. For simplicity, we do not use this method in our examples later in this chapter, but it is usually a good idea if you do not know exactly how much data to expect.

These are a few of the very basics. It might be a good idea to dive into some actual code. But first, we need to get one thing out of the way.


next up previous contents
Next: Platform specific header Up: PKCS #11 Previous: Function definitions   Contents
Written by Jelte Jansen
© NLnet Labs, May 13, 2008
jelte@nlnetlabs.nl