Next: , Up: Certificate Handling


3.1 How to create a certificate object

This section explains how to create a certificate object, initialize it, copy it and eventually destroy it.

— Function: ksba_cert_t ksba_cert_new (void)

The function ksba_cert_new creates 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 NULL is returned. You might then get the actual error code using ‘gpg_error_from_errno (errno)’.

— Function: void ksba_cert_ref (ksba_cert_t cert)

The function ksba_cert_ref bumps the reference counter of the certificate object up by one. Thus an extra ksba_cert_release is required to actually release the memory used for the object.

— Function: void ksba_cert_release (ksba_cert_t cert)

The function ksba_cert_release reduces 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 pass NULL to the function in which case nothing happens.

— Function: gpg_error_t ksba_cert_read_der (ksba_cert_t cert, ksba_reader_t reader)

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 0 if the operation was successfully performed. An error code is returned on failure.

— Function: gpg_error_t ksba_cert_init_from_mem (ksba_cert_t cert, const void *buffer, size_t length)

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 0 if the operation was successfully performed. An error code is returned on failure.