Next: Retrieving attributes, Up: Certificate Handling
This section explains how to create a certificate object, initialize it, copy it and eventually destroy it.
The function
ksba_cert_newcreates a new certificate object and returns a handle for it. The certificate object has initially one reference.The only reason why this function may fail is an out-of-memory condition in which case
NULLis returned. You might then get the actual error code using ‘gpg_error_from_errno (errno)’.
The function
ksba_cert_refbumps the reference counter of the certificate object up by one. Thus an extraksba_cert_releaseis required to actually release the memory used for the object.
The function
ksba_cert_releasereduces the number of references to the certificate object with the handle cert. If this was the last reference, it will also destroy the object and releases all associated resources. It is okay to passNULLto the function in which case nothing happens.
Read the next certificate from the reader object and store it in the certificate object cert for future access. The certificate is parsed and rejected if it has any syntactical or semantical error (i.e. does not match the ASN.1 description).
The function returns
0if the operation was successfully performed. An error code is returned on failure.
Parse the buffer which should contain a DER encoded certificate of length and initialize the certificate object cert with it. This function is intended as a convenience function to be used when a certificate is already available in a internal memory buffer. This avoids the extra code needed to setup the reader object. Note that cert must be a valid certificate object.
The function returns
0if the operation was successfully performed. An error code is returned on failure.