core: New GPGME_DATA_ENCODING_MIME.
* src/gpgme.h.in (GPGME_DATA_ENCODING_MIME): New. * src/data.c (gpgme_data_set_encoding): Adjust check. * src/engine-gpg.c (have_gpg_version): New. (gpg_encrypt, gpg_encrypt_sign): Pass flag '--mimemode'. (gpg_sign): Ditto. * lang/cpp/src/data.h (GpgME): Add MimeEncoding. * lang/cpp/src/data.cpp (encoding, setEncoding): Support MimeEncoding. * src/gpgme-tool.c (server_data_encoding): Add flag --mime. -- This feature allows an application to declare that the encrypted or signed data is a valid MIME part. What is missing is a way to return that information to the application after decryption/verification. This can be done by setting the encoding of the output data object; however this requires some internal additions to our processing model. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
2095b1573a
commit
d8d5f5a167
1
NEWS
1
NEWS
@ -20,6 +20,7 @@ Noteworthy changes in version 1.7.0 (unreleased) [C25/A14/R_]
|
||||
GPGME_STATUS_NOTATION_FLAGS NEW.
|
||||
GPGME_DATA_TYPE_PGP_ENCRYPTED NEW.
|
||||
GPGME_DATA_TYPE_PGP_SIGNATURE NEW.
|
||||
GPGME_DATA_ENCODING_MIME NEW.
|
||||
|
||||
|
||||
Noteworthy changes in version 1.6.0 (2015-08-26) [C25/A14/R0]
|
||||
|
@ -2130,6 +2130,9 @@ scheme as used by @acronym{MIME} and other protocols.
|
||||
This specifies that the data is encoded in an armored form as used by
|
||||
OpenPGP and PEM.
|
||||
|
||||
@item GPGME_DATA_ENCODING_MIME
|
||||
This specifies that the data is encoded as a MIME part.
|
||||
|
||||
@item GPGME_DATA_ENCODING_URL
|
||||
The data is a list of linefeed delimited URLs. This is only useful with
|
||||
@code{gpgme_op_import}.
|
||||
|
@ -146,6 +146,7 @@ GpgME::Data::Encoding GpgME::Data::encoding() const
|
||||
case GPGME_DATA_ENCODING_BINARY: return BinaryEncoding;
|
||||
case GPGME_DATA_ENCODING_BASE64: return Base64Encoding;
|
||||
case GPGME_DATA_ENCODING_ARMOR: return ArmorEncoding;
|
||||
case GPGME_DATA_ENCODING_MIME: return MimeEncoding;
|
||||
}
|
||||
return AutoEncoding;
|
||||
}
|
||||
@ -158,6 +159,7 @@ GpgME::Error GpgME::Data::setEncoding(Encoding enc)
|
||||
case BinaryEncoding: ge = GPGME_DATA_ENCODING_BINARY; break;
|
||||
case Base64Encoding: ge = GPGME_DATA_ENCODING_BASE64; break;
|
||||
case ArmorEncoding: ge = GPGME_DATA_ENCODING_ARMOR; break;
|
||||
case MimeEncoding: ge = GPGME_DATA_ENCODING_MIME; break;
|
||||
}
|
||||
return Error(gpgme_data_set_encoding(d->data, ge));
|
||||
}
|
||||
|
@ -77,7 +77,8 @@ public:
|
||||
AutoEncoding,
|
||||
BinaryEncoding,
|
||||
Base64Encoding,
|
||||
ArmorEncoding
|
||||
ArmorEncoding,
|
||||
MimeEncoding
|
||||
};
|
||||
Encoding encoding() const;
|
||||
Error setEncoding(Encoding encoding);
|
||||
|
@ -193,7 +193,7 @@ gpgme_data_set_encoding (gpgme_data_t dh, gpgme_data_encoding_t enc)
|
||||
"encoding=%i", enc);
|
||||
if (!dh)
|
||||
return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
|
||||
if (enc < 0 || enc > GPGME_DATA_ENCODING_URL0)
|
||||
if (enc < 0 || enc > GPGME_DATA_ENCODING_MIME)
|
||||
return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
|
||||
dh->encoding = enc;
|
||||
return TRACE_ERR (0);
|
||||
|
@ -294,6 +294,15 @@ add_data (engine_gpg_t gpg, gpgme_data_t data, int dup_to, int inbound)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Return true if the engine's version is at least VERSION. */
|
||||
static int
|
||||
have_gpg_version (engine_gpg_t gpg, const char *version)
|
||||
{
|
||||
return _gpgme_compare_versions (gpg->version, version);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static char *
|
||||
gpg_get_version (const char *file_name)
|
||||
@ -1719,6 +1728,10 @@ gpg_encrypt (void *engine, gpgme_key_t recp[], gpgme_encrypt_flags_t flags,
|
||||
if (!err && (flags & GPGME_ENCRYPT_NO_COMPRESS))
|
||||
err = add_arg (gpg, "--compress-algo=none");
|
||||
|
||||
if (gpgme_data_get_encoding (plain) == GPGME_DATA_ENCODING_MIME
|
||||
&& have_gpg_version (gpg, "2.1.14"))
|
||||
err = add_arg (gpg, "--mimemode");
|
||||
|
||||
if (!symmetric)
|
||||
{
|
||||
/* If we know that all recipients are valid (full or ultimate trust)
|
||||
@ -1779,6 +1792,10 @@ gpg_encrypt_sign (void *engine, gpgme_key_t recp[],
|
||||
if (!err && (flags & GPGME_ENCRYPT_NO_COMPRESS))
|
||||
err = add_arg (gpg, "--compress-algo=none");
|
||||
|
||||
if (gpgme_data_get_encoding (plain) == GPGME_DATA_ENCODING_MIME
|
||||
&& have_gpg_version (gpg, "2.1.14"))
|
||||
err = add_arg (gpg, "--mimemode");
|
||||
|
||||
if (!symmetric)
|
||||
{
|
||||
/* If we know that all recipients are valid (full or ultimate trust)
|
||||
@ -2381,9 +2398,15 @@ gpg_sign (void *engine, gpgme_data_t in, gpgme_data_t out,
|
||||
err = add_arg (gpg, "--detach");
|
||||
if (!err && use_armor)
|
||||
err = add_arg (gpg, "--armor");
|
||||
if (!err && use_textmode)
|
||||
if (!err)
|
||||
{
|
||||
if (gpgme_data_get_encoding (in) == GPGME_DATA_ENCODING_MIME
|
||||
&& have_gpg_version (gpg, "2.1.14"))
|
||||
err = add_arg (gpg, "--mimemode");
|
||||
else if (use_textmode)
|
||||
err = add_arg (gpg, "--textmode");
|
||||
}
|
||||
}
|
||||
|
||||
if (!err)
|
||||
err = append_args_from_signers (gpg, ctx);
|
||||
|
@ -1876,6 +1876,8 @@ server_data_encoding (const char *line)
|
||||
return GPGME_DATA_ENCODING_URLESC;
|
||||
if (strstr (line, "--url0"))
|
||||
return GPGME_DATA_ENCODING_URL0;
|
||||
if (strstr (line, "--mime"))
|
||||
return GPGME_DATA_ENCODING_MIME;
|
||||
return GPGME_DATA_ENCODING_NONE;
|
||||
}
|
||||
|
||||
|
@ -228,7 +228,8 @@ typedef enum
|
||||
GPGME_DATA_ENCODING_ARMOR = 3, /* Either PEM or OpenPGP Armor. */
|
||||
GPGME_DATA_ENCODING_URL = 4, /* LF delimited URL list. */
|
||||
GPGME_DATA_ENCODING_URLESC = 5, /* Ditto, but percent escaped. */
|
||||
GPGME_DATA_ENCODING_URL0 = 6 /* Nul delimited URL list. */
|
||||
GPGME_DATA_ENCODING_URL0 = 6, /* Nul delimited URL list. */
|
||||
GPGME_DATA_ENCODING_MIME = 7 /* Data is a MIME part. */
|
||||
}
|
||||
gpgme_data_encoding_t;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user