new cryptplug function importCertificateFromMem()

This commit is contained in:
Steffen Hansen 2002-07-31 12:37:34 +00:00
parent 4530913bc5
commit 6676c74b6a
3 changed files with 54 additions and 3 deletions

View File

@ -1,3 +1,7 @@
2002-07-31 Steffen Hansen <steffen@hrhansen.dk>
* Renamed importCertificate() to importCertificateWithFPR() and implemented importCertificateFromMem()
2002-07-03 Werner Koch <wk@gnupg.org> 2002-07-03 Werner Koch <wk@gnupg.org>
* gpgmeplug.c (nextCertificate): Actually free the entire array * gpgmeplug.c (nextCertificate): Actually free the entire array

View File

@ -1849,10 +1849,20 @@ endListCertificates( struct CertIterator* );
Import a certificate that was a result from a search-operation using the startListCertificates(), nextCertificate() funtions. Import a certificate that was a result from a search-operation using the startListCertificates(), nextCertificate() funtions.
The fingerprint must be passed to identify the key. The fingerprint must be passed to identify the key.
Additional info about the import operation is available in the additional_info parameter. The string must be free'd by the user with free().
*/ */
int int
importCertificate( const char* fingerprint ); importCertificateWithFPR( const char* fingerprint, char** additional_info );
/*!
Import a certificate from memory.
Additional info about the import operation is available in the additional_info parameter. The string must be free'd by the user with free().
*/
int
importCertificateFromMem( const char* data, size_t length, char** additional_info );
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -2234,7 +2234,7 @@ endListCertificates( struct CertIterator* it )
} }
int int
importCertificate( const char* fingerprint ) importCertificateWithFPR( const char* fingerprint, char** additional_info )
{ {
GpgmeError err; GpgmeError err;
GpgmeCtx ctx; GpgmeCtx ctx;
@ -2296,6 +2296,7 @@ importCertificate( const char* fingerprint )
if( err ) { if( err ) {
fprintf( stderr, "gpgme_op_export returned %d\n", err ); fprintf( stderr, "gpgme_op_export returned %d\n", err );
free (buf); free (buf);
*additional_info = gpgme_get_op_info( ctx, 0 );
gpgme_recipients_release( recips ); gpgme_recipients_release( recips );
gpgme_data_release( keydata ); gpgme_data_release( keydata );
gpgme_release( ctx ); gpgme_release( ctx );
@ -2305,6 +2306,7 @@ importCertificate( const char* fingerprint )
buf = NULL; buf = NULL;
err = gpgme_op_import( ctx, keydata ); err = gpgme_op_import( ctx, keydata );
*additional_info = gpgme_get_op_info( ctx, 0 );
if( err ) { if( err ) {
fprintf( stderr, "gpgme_op_import returned %d\n", err ); fprintf( stderr, "gpgme_op_import returned %d\n", err );
gpgme_recipients_release( recips ); gpgme_recipients_release( recips );
@ -2318,6 +2320,41 @@ importCertificate( const char* fingerprint )
gpgme_release( ctx ); gpgme_release( ctx );
return 0; return 0;
} }
int
importCertificateFromMem( const char* data, size_t length , char** additional_info )
{
GpgmeError err;
GpgmeCtx ctx;
GpgmeData keydata;
err = gpgme_new( &ctx );
/*fprintf( stderr, "2: gpgme returned %d\n", err );*/
if( err != GPGME_No_Error ) {
return err;
}
gpgme_set_protocol( ctx, GPGME_PROTOCOL_CMS );
gpgme_set_keylist_mode( ctx, GPGME_KEYLIST_MODE_LOCAL );
err = gpgme_data_new_from_mem( &keydata, data, length, 0 );
if( err ) {
fprintf( stderr, "gpgme_data_new returned %d\n", err );
gpgme_release( ctx );
return err;
}
err = gpgme_op_import( ctx, keydata );
*additional_info = gpgme_get_op_info( ctx, 0 );
if( err ) {
fprintf( stderr, "gpgme_op_import returned %d\n", err );
gpgme_data_release( keydata );
gpgme_release( ctx );
return err;
}
gpgme_data_release( keydata );
gpgme_release( ctx );
return 0;
}
/* == == == == == == == == == == == == == == == == == == == == == == == == == /* == == == == == == == == == == == == == == == == == == == == == == == == ==
== == == ==