improce memory handling
This commit is contained in:
parent
9f84291722
commit
cfcac3496a
@ -951,7 +951,7 @@ bool encryptMessage( const char* cleartext,
|
|||||||
// untrusted key (oder gar keiner) gefunden wurde, verweigert gpg
|
// untrusted key (oder gar keiner) gefunden wurde, verweigert gpg
|
||||||
// das signieren.
|
// das signieren.
|
||||||
}
|
}
|
||||||
|
|
||||||
gpgme_release (ctx);
|
gpgme_release (ctx);
|
||||||
|
|
||||||
return bOk;
|
return bOk;
|
||||||
@ -966,11 +966,12 @@ bool decryptMessage( const char* ciphertext,
|
|||||||
const char** cleartext,
|
const char** cleartext,
|
||||||
const char* certificate )
|
const char* certificate )
|
||||||
{
|
{
|
||||||
GpgmeCtx ctx;
|
GpgmeCtx ctx;
|
||||||
GpgmeData gCiphertext, gPlaintext;
|
GpgmeError err;
|
||||||
size_t rCLen;
|
GpgmeData gCiphertext, gPlaintext;
|
||||||
char* rCiph = 0;
|
size_t rCLen = 0;
|
||||||
bool bOk = false;
|
char* rCiph = 0;
|
||||||
|
bool bOk = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -984,6 +985,19 @@ bool decryptMessage( const char* ciphertext,
|
|||||||
struct passphrase_cb_info_s info;
|
struct passphrase_cb_info_s info;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if( !ciphertext )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
err = gpgme_new (&ctx);
|
||||||
|
gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
temporary code!!
|
temporary code!!
|
||||||
|
|
||||||
@ -999,28 +1013,28 @@ bool decryptMessage( const char* ciphertext,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
gpgme_new( &ctx );
|
|
||||||
gpgme_data_new_from_mem( &gCiphertext, ciphertext,
|
|
||||||
1+strlen( ciphertext ), 1 );
|
|
||||||
gpgme_data_new( &gPlaintext );
|
|
||||||
|
|
||||||
gpgme_op_decrypt( ctx, gCiphertext, gPlaintext );
|
gpgme_data_new_from_mem( &gCiphertext, ciphertext,
|
||||||
gpgme_data_release( gCiphertext );
|
1+strlen( ciphertext ), 1 );
|
||||||
|
gpgme_data_new( &gPlaintext );
|
||||||
|
|
||||||
rCiph = gpgme_data_release_and_get_mem( gPlaintext, &rCLen );
|
gpgme_op_decrypt( ctx, gCiphertext, gPlaintext );
|
||||||
|
gpgme_data_release( gCiphertext );
|
||||||
|
|
||||||
*cleartext = malloc( rCLen + 1 );
|
rCiph = gpgme_data_release_and_get_mem( gPlaintext, &rCLen );
|
||||||
if( *cleartext ) {
|
|
||||||
if( rCLen ) {
|
|
||||||
bOk = true;
|
|
||||||
strncpy((char*)*cleartext, rCiph, rCLen );
|
|
||||||
}
|
|
||||||
((char*)(*cleartext))[rCLen] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
free( rCiph );
|
*cleartext = malloc( rCLen + 1 );
|
||||||
gpgme_release( ctx );
|
if( *cleartext ) {
|
||||||
return bOk;
|
if( rCLen ) {
|
||||||
|
bOk = true;
|
||||||
|
strncpy((char*)*cleartext, rCiph, rCLen );
|
||||||
|
}
|
||||||
|
((char*)(*cleartext))[rCLen] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
free( rCiph );
|
||||||
|
gpgme_release( ctx );
|
||||||
|
return bOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool decryptAndCheckMessage( const char* ciphertext,
|
bool decryptAndCheckMessage( const char* ciphertext,
|
||||||
|
Loading…
Reference in New Issue
Block a user