/*! \ingroup groupSignAct
\brief Signs a message \c cleartext and returns
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.
If \c certificate is \c NULL, the default certificate is used.
*/
bool signMessage( const char* cleartext,
const char** ciphertext,
+ const size_t* cipherLen,
const char* certificate,
struct StructuringInfo* structuring );
\c cleartext according to the \c addressee and
the current settings (algorithm, etc.) and
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
\c true, otherwise
*/
bool encryptMessage( const char* cleartext,
const char** ciphertext,
+ const size_t* cipherLen,
const char* addressee,
struct StructuringInfo* structuring );
#define GPGMEPLUG_SIGN_FLAT_PREFIX ""
#define GPGMEPLUG_SIGN_FLAT_SEPARATOR ""
#define GPGMEPLUG_SIGN_FLAT_POSTFIX ""
+#define __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY false
#endif
// definitions for encoding
#ifndef GPGMEPLUG_ENC_MAKE_MIME_OBJECT
#define GPGMEPLUG_ENC_FLAT_PREFIX ""
#define GPGMEPLUG_ENC_FLAT_SEPARATOR ""
#define GPGMEPLUG_ENC_FLAT_POSTFIX ""
+#define __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY false
#endif
// Note: The following specification will result in
// function encryptAndSignMessage() producing
bool signMessage( const char* cleartext,
const char** ciphertext,
+ const size_t* cipherLen,
const char* certificate,
struct StructuringInfo* structuring )
{
GpgmeCtx ctx;
GpgmeError err;
GpgmeData data, sig;
- size_t rSLen = 0;
- char* rSig = 0;
- bool bOk = false;
+ char* rSig = 0;
+ bool bOk = false;
int sendCerts = 1;
init_StructuringInfo( structuring );
err = gpgme_new (&ctx);
gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL);
- gpgme_set_armor (ctx, 1);
- gpgme_set_textmode (ctx, 1);
+ gpgme_set_armor (ctx, __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY ? 0 : 1);
+// gpgme_set_textmode (ctx, 1);
switch ( config.sendCertificates ) {
case SendCert_undef:
err = gpgme_op_sign (ctx, data, sig, GPGME_SIG_MODE_DETACH );
if (!err) {
- rSig = gpgme_data_release_and_get_mem( sig, &rSLen );
- *ciphertext = malloc( rSLen + 1 );
- if( *ciphertext ) {
- if( rSLen ) {
- bOk = true;
- strncpy((char*)*ciphertext, rSig, rSLen );
+ if( __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY )
+ *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( *cipherLen ) {
+ bOk = true;
+ strncpy((char*)*ciphertext, rSig, *cipherLen );
+ }
+ ((char*)(*ciphertext))[*cipherLen] = '\0';
}
- ((char*)(*ciphertext))[rSLen] = '\0';
+ free( rSig );
}
- free( rSig );
}
else {
gpgme_data_release( sig );
bool encryptMessage( const char* cleartext,
const char** ciphertext,
+ const size_t* cipherLen,
const char* certificate,
struct StructuringInfo* structuring )
{
GpgmeError err;
GpgmeData gCiphertext, gPlaintext;
GpgmeRecipients rset;
- size_t rCLen = 0;
char* rCiph = 0;
bool bOk = false;
gpgme_new (&ctx);
gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL);
- gpgme_set_armor (ctx, 1);
- gpgme_set_textmode (ctx, 1);
+ gpgme_set_armor (ctx, __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY ? 0 : 1);
+// gpgme_set_textmode (ctx, 1);
gpgme_data_new_from_mem (&gPlaintext, cleartext,
1+strlen( cleartext ), 1 );
gpgme_data_release (gPlaintext);
if( !err ) {
- rCiph = gpgme_data_release_and_get_mem( gCiphertext, &rCLen );
- *ciphertext = malloc( rCLen + 1 );
- if( *ciphertext ) {
- if( rCLen ) {
- bOk = true;
- strncpy((char*)*ciphertext, rCiph, rCLen );
+ if( __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY )
+ *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( *cipherLen ) {
+ bOk = true;
+ strncpy((char*)*ciphertext, rCiph, *cipherLen );
+ }
+ ((char*)(*ciphertext))[*cipherLen] = 0;
}
- ((char*)(*ciphertext))[rCLen] = 0;
+ free( rCiph );
}
- free( rCiph );
}
else {
gpgme_data_release ( gCiphertext );