[Pkg-gnupg-commit] [gpgme] 230/412: core: New GPGME_DATA_ENCODING_MIME.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Thu Sep 22 21:26:53 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gpgme.

commit d8d5f5a16712244fe6eff860b6ac5f007b1bf870
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Jul 13 14:45:02 2016 +0200

    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 at gnupg.org>
---
 NEWS                  |  1 +
 doc/gpgme.texi        |  3 +++
 lang/cpp/src/data.cpp |  2 ++
 lang/cpp/src/data.h   |  3 ++-
 src/data.c            |  2 +-
 src/engine-gpg.c      | 27 +++++++++++++++++++++++++--
 src/gpgme-tool.c      |  2 ++
 src/gpgme.h.in        |  3 ++-
 8 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/NEWS b/NEWS
index 32f3c84..bb31a50 100644
--- a/NEWS
+++ b/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]
diff --git a/doc/gpgme.texi b/doc/gpgme.texi
index 87322b0..c514ff8 100644
--- a/doc/gpgme.texi
+++ b/doc/gpgme.texi
@@ -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.
 
+ at 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}.
diff --git a/lang/cpp/src/data.cpp b/lang/cpp/src/data.cpp
index af1c479..64acb47 100644
--- a/lang/cpp/src/data.cpp
+++ b/lang/cpp/src/data.cpp
@@ -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));
 }
diff --git a/lang/cpp/src/data.h b/lang/cpp/src/data.h
index d5e54aa..b2f2173 100644
--- a/lang/cpp/src/data.h
+++ b/lang/cpp/src/data.h
@@ -77,7 +77,8 @@ public:
         AutoEncoding,
         BinaryEncoding,
         Base64Encoding,
-        ArmorEncoding
+        ArmorEncoding,
+        MimeEncoding
     };
     Encoding encoding() const;
     Error setEncoding(Encoding encoding);
diff --git a/src/data.c b/src/data.c
index 7123a82..87b619e 100644
--- a/src/data.c
+++ b/src/data.c
@@ -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);
diff --git a/src/engine-gpg.c b/src/engine-gpg.c
index e279f04..16571a5 100644
--- a/src/engine-gpg.c
+++ b/src/engine-gpg.c
@@ -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,8 +2398,14 @@ 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)
-	err = add_arg (gpg, "--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)
diff --git a/src/gpgme-tool.c b/src/gpgme-tool.c
index ccda973..080b306 100644
--- a/src/gpgme-tool.c
+++ b/src/gpgme-tool.c
@@ -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;
 }
 
diff --git a/src/gpgme.h.in b/src/gpgme.h.in
index cdb7037..49d56c3 100644
--- a/src/gpgme.h.in
+++ b/src/gpgme.h.in
@@ -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;
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git



More information about the Pkg-gnupg-commit mailing list