/*! \ingroup groupCertAct
\brief Generates a prototype certificate with the data provided
- in the four parameter.
+ in the four parameter. The memory returned in \a generatedKey
+ must be freed with free() by the caller.
*/
-bool requestDecentralCertificate( const char* certparms, char** generatedKey );
+bool requestDecentralCertificate( const char* certparms,
+ char** generatedKey, int* keyLength );
/*! \ingroup groupCertAct
\brief Requests a certificate in a PSE from the CA
const char* requestCertificateDialog(){ return 0; }
-bool requestDecentralCertificate( const char* certparms, char** generatedKey )
+bool requestDecentralCertificate( const char* certparms,
+ char** generatedKey, int* length )
{
+ GpgmeError err;
GpgmeCtx ctx;
- GpgmeError err = gpgme_new (&ctx);
+ GpgmeData pub, result;
+ int len;
+
+ err = gpgme_data_new (&pub);
if( err != GPGME_No_Error )
return false;
- gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL);
-
- gpgme_set_armor (ctx, __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY ? 0 : 1);
+ err = gpgme_new (&ctx);
+ if( err != GPGME_No_Error ) {
+ gpgme_data_release( pub );
+ return false;
+ }
- if( gpgme_op_genkey( ctx, certparms, NULL, NULL ) == GPGME_No_Error )
- return true;
- else
+ gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
+ /* We want binary, so comment this: gpgme_set_armor (ctx, 1); */
+ err = gpgme_op_genkey (ctx, certparms, pub, NULL );
+ if( err != GPGME_No_Error ) {
+ gpgme_data_release( pub );
+ gpgme_release( ctx );
return false;
+ }
+
+ gpgme_release (ctx);
+ *generatedKey = gpgme_data_release_and_get_mem (pub, &len);
+ *length = len;
- gpgme_release( ctx );
+ /* The buffer generatedKey contains the LEN bytes you want */
+ // Caller is responsible for freeing
}
bool requestCentralCertificateAndPSE( const char* name,