interface change: signMessage() and encryptMessage() now return an additional 'cipherLen' parameter to enable us to handle binary cipher data

This commit is contained in:
Karl-Heinz Zimmer 2002-03-22 10:40:24 +00:00
parent 70251d0f5f
commit cf04fed2de
4 changed files with 52 additions and 25 deletions

View File

@ -1386,7 +1386,12 @@ struct StructuringInfo {
/*! \ingroup groupSignAct /*! \ingroup groupSignAct
\brief Signs a message \c cleartext and returns \brief Signs a message \c cleartext and returns
in \c *ciphertext the signature data bloc that in \c *ciphertext the signature data bloc that
is to be added to the message. is to be added to the message. The length returned
in \c *cipherLen tells you the size (==amount of bytes)
of the ciphertext, if the structuring information
would return with contentTEncCode set to "base64"
the ciphertext might contain a char 0x00
and has to be converted into base64 before sending.
The signature role is specified by \c certificate. The signature role is specified by \c certificate.
If \c certificate is \c NULL, the default certificate is used. If \c certificate is \c NULL, the default certificate is used.
@ -1416,6 +1421,7 @@ struct StructuringInfo {
*/ */
bool signMessage( const char* cleartext, bool signMessage( const char* cleartext,
const char** ciphertext, const char** ciphertext,
const size_t* cipherLen,
const char* certificate, const char* certificate,
struct StructuringInfo* structuring ); struct StructuringInfo* structuring );
@ -1477,6 +1483,12 @@ bool findCertificates( const char* addressee, char** certificates );
\c cleartext according to the \c addressee and \c cleartext according to the \c addressee and
the current settings (algorithm, etc.) and the current settings (algorithm, etc.) and
returns the encoded data bloc in \c *ciphertext. returns the encoded data bloc in \c *ciphertext.
The length returned in \c *cipherLen tells you the
size (==amount of bytes) of the ciphertext, if the
structuring information would return with
contentTEncCode set to "base64" the ciphertext
might contain a char 0x00 and has to be converted
into base64 before sending.
If the message could be encrypted, the function returns If the message could be encrypted, the function returns
\c true, otherwise \c true, otherwise
@ -1501,6 +1513,7 @@ bool findCertificates( const char* addressee, char** certificates );
*/ */
bool encryptMessage( const char* cleartext, bool encryptMessage( const char* cleartext,
const char** ciphertext, const char** ciphertext,
const size_t* cipherLen,
const char* addressee, const char* addressee,
struct StructuringInfo* structuring ); struct StructuringInfo* structuring );

View File

@ -16,6 +16,7 @@
#define GPGMEPLUG_SIGN_FLAT_PREFIX "" #define GPGMEPLUG_SIGN_FLAT_PREFIX ""
#define GPGMEPLUG_SIGN_FLAT_SEPARATOR "" #define GPGMEPLUG_SIGN_FLAT_SEPARATOR ""
#define GPGMEPLUG_SIGN_FLAT_POSTFIX "" #define GPGMEPLUG_SIGN_FLAT_POSTFIX ""
#define __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY true
#define GPGMEPLUG_ENC_INCLUDE_CLEARTEXT false #define GPGMEPLUG_ENC_INCLUDE_CLEARTEXT false
#define GPGMEPLUG_ENC_MAKE_MIME_OBJECT true #define GPGMEPLUG_ENC_MAKE_MIME_OBJECT true
@ -33,5 +34,6 @@
#define GPGMEPLUG_ENC_FLAT_PREFIX "" #define GPGMEPLUG_ENC_FLAT_PREFIX ""
#define GPGMEPLUG_ENC_FLAT_SEPARATOR "" #define GPGMEPLUG_ENC_FLAT_SEPARATOR ""
#define GPGMEPLUG_ENC_FLAT_POSTFIX "" #define GPGMEPLUG_ENC_FLAT_POSTFIX ""
#define __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY false
#include "gpgmeplug.c" #include "gpgmeplug.c"

View File

@ -16,6 +16,7 @@
#define GPGMEPLUG_SIGN_FLAT_PREFIX "" #define GPGMEPLUG_SIGN_FLAT_PREFIX ""
#define GPGMEPLUG_SIGN_FLAT_SEPARATOR "" #define GPGMEPLUG_SIGN_FLAT_SEPARATOR ""
#define GPGMEPLUG_SIGN_FLAT_POSTFIX "" #define GPGMEPLUG_SIGN_FLAT_POSTFIX ""
#define __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY true
#define GPGMEPLUG_ENC_INCLUDE_CLEARTEXT false #define GPGMEPLUG_ENC_INCLUDE_CLEARTEXT false
#define GPGMEPLUG_ENC_MAKE_MIME_OBJECT true #define GPGMEPLUG_ENC_MAKE_MIME_OBJECT true
@ -33,5 +34,6 @@
#define GPGMEPLUG_ENC_FLAT_PREFIX "" #define GPGMEPLUG_ENC_FLAT_PREFIX ""
#define GPGMEPLUG_ENC_FLAT_SEPARATOR "" #define GPGMEPLUG_ENC_FLAT_SEPARATOR ""
#define GPGMEPLUG_ENC_FLAT_POSTFIX "" #define GPGMEPLUG_ENC_FLAT_POSTFIX ""
#define __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY true
#include "gpgmeplug.c" #include "gpgmeplug.c"

View File

@ -79,6 +79,7 @@
#define GPGMEPLUG_SIGN_FLAT_PREFIX "" #define GPGMEPLUG_SIGN_FLAT_PREFIX ""
#define GPGMEPLUG_SIGN_FLAT_SEPARATOR "" #define GPGMEPLUG_SIGN_FLAT_SEPARATOR ""
#define GPGMEPLUG_SIGN_FLAT_POSTFIX "" #define GPGMEPLUG_SIGN_FLAT_POSTFIX ""
#define __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY false
#endif #endif
// definitions for encoding // definitions for encoding
#ifndef GPGMEPLUG_ENC_MAKE_MIME_OBJECT #ifndef GPGMEPLUG_ENC_MAKE_MIME_OBJECT
@ -98,6 +99,7 @@
#define GPGMEPLUG_ENC_FLAT_PREFIX "" #define GPGMEPLUG_ENC_FLAT_PREFIX ""
#define GPGMEPLUG_ENC_FLAT_SEPARATOR "" #define GPGMEPLUG_ENC_FLAT_SEPARATOR ""
#define GPGMEPLUG_ENC_FLAT_POSTFIX "" #define GPGMEPLUG_ENC_FLAT_POSTFIX ""
#define __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY false
#endif #endif
// Note: The following specification will result in // Note: The following specification will result in
// function encryptAndSignMessage() producing // function encryptAndSignMessage() producing
@ -860,13 +862,13 @@ void storeNewCharPtr( char** dest, const char* src )
bool signMessage( const char* cleartext, bool signMessage( const char* cleartext,
const char** ciphertext, const char** ciphertext,
const size_t* cipherLen,
const char* certificate, const char* certificate,
struct StructuringInfo* structuring ) struct StructuringInfo* structuring )
{ {
GpgmeCtx ctx; GpgmeCtx ctx;
GpgmeError err; GpgmeError err;
GpgmeData data, sig; GpgmeData data, sig;
size_t rSLen = 0;
char* rSig = 0; char* rSig = 0;
bool bOk = false; bool bOk = false;
int sendCerts = 1; int sendCerts = 1;
@ -879,8 +881,8 @@ bool signMessage( const char* cleartext,
err = gpgme_new (&ctx); err = gpgme_new (&ctx);
gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL); gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL);
gpgme_set_armor (ctx, 1); gpgme_set_armor (ctx, __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY ? 0 : 1);
gpgme_set_textmode (ctx, 1); // gpgme_set_textmode (ctx, 1);
switch ( config.sendCertificates ) { switch ( config.sendCertificates ) {
case SendCert_undef: case SendCert_undef:
@ -912,17 +914,21 @@ bool signMessage( const char* cleartext,
err = gpgme_op_sign (ctx, data, sig, GPGME_SIG_MODE_DETACH ); err = gpgme_op_sign (ctx, data, sig, GPGME_SIG_MODE_DETACH );
if (!err) { if (!err) {
rSig = gpgme_data_release_and_get_mem( sig, &rSLen ); if( __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY )
*ciphertext = malloc( rSLen + 1 ); *ciphertext = gpgme_data_release_and_get_mem( sig, (size_t*)cipherLen );
else {
rSig = gpgme_data_release_and_get_mem( sig, (size_t*)cipherLen );
*ciphertext = malloc( *cipherLen + 1 );
if( *ciphertext ) { if( *ciphertext ) {
if( rSLen ) { if( *cipherLen ) {
bOk = true; bOk = true;
strncpy((char*)*ciphertext, rSig, rSLen ); strncpy((char*)*ciphertext, rSig, *cipherLen );
} }
((char*)(*ciphertext))[rSLen] = '\0'; ((char*)(*ciphertext))[*cipherLen] = '\0';
} }
free( rSig ); free( rSig );
} }
}
else { else {
gpgme_data_release( sig ); gpgme_data_release( sig );
*ciphertext = 0; *ciphertext = 0;
@ -1238,6 +1244,7 @@ bool findCertificates( const char* addressee, char** certificates )
bool encryptMessage( const char* cleartext, bool encryptMessage( const char* cleartext,
const char** ciphertext, const char** ciphertext,
const size_t* cipherLen,
const char* certificate, const char* certificate,
struct StructuringInfo* structuring ) struct StructuringInfo* structuring )
{ {
@ -1245,7 +1252,6 @@ bool encryptMessage( const char* cleartext,
GpgmeError err; GpgmeError err;
GpgmeData gCiphertext, gPlaintext; GpgmeData gCiphertext, gPlaintext;
GpgmeRecipients rset; GpgmeRecipients rset;
size_t rCLen = 0;
char* rCiph = 0; char* rCiph = 0;
bool bOk = false; bool bOk = false;
@ -1254,8 +1260,8 @@ bool encryptMessage( const char* cleartext,
gpgme_new (&ctx); gpgme_new (&ctx);
gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL); gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL);
gpgme_set_armor (ctx, 1); gpgme_set_armor (ctx, __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY ? 0 : 1);
gpgme_set_textmode (ctx, 1); // gpgme_set_textmode (ctx, 1);
gpgme_data_new_from_mem (&gPlaintext, cleartext, gpgme_data_new_from_mem (&gPlaintext, cleartext,
1+strlen( cleartext ), 1 ); 1+strlen( cleartext ), 1 );
@ -1308,17 +1314,21 @@ bool encryptMessage( const char* cleartext,
gpgme_data_release (gPlaintext); gpgme_data_release (gPlaintext);
if( !err ) { if( !err ) {
rCiph = gpgme_data_release_and_get_mem( gCiphertext, &rCLen ); if( __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY )
*ciphertext = malloc( rCLen + 1 ); *ciphertext = gpgme_data_release_and_get_mem( gCiphertext, (size_t*)cipherLen );
else {
rCiph = gpgme_data_release_and_get_mem( gCiphertext, (size_t*)cipherLen );
*ciphertext = malloc( *cipherLen + 1 );
if( *ciphertext ) { if( *ciphertext ) {
if( rCLen ) { if( *cipherLen ) {
bOk = true; bOk = true;
strncpy((char*)*ciphertext, rCiph, rCLen ); strncpy((char*)*ciphertext, rCiph, *cipherLen );
} }
((char*)(*ciphertext))[rCLen] = 0; ((char*)(*ciphertext))[*cipherLen] = 0;
} }
free( rCiph ); free( rCiph );
} }
}
else { else {
gpgme_data_release ( gCiphertext ); gpgme_data_release ( gCiphertext );
*ciphertext = 0; *ciphertext = 0;