Cpp: Add support for gpgme_data_identify
authorAndre Heinecke <aheinecke@intevation.de>
Tue, 12 Apr 2016 14:05:31 +0000 (16:05 +0200)
committerAndre Heinecke <aheinecke@intevation.de>
Tue, 12 Apr 2016 14:05:31 +0000 (16:05 +0200)
* lang/cpp/src/data.cpp (Data::type): New.
* lang/cpp/src/data.h (Data::Type): New enum mapping.

lang/cpp/src/data.cpp
lang/cpp/src/data.h

index b07406c..bf9a629 100644 (file)
@@ -162,6 +162,26 @@ GpgME::Error GpgME::Data::setEncoding(Encoding enc)
     return Error(gpgme_data_set_encoding(d->data, ge));
 }
 
+GpgME::Data::Type GpgME::Data::type() const
+{
+    if (isNull()) {
+        return Invalid;
+    }
+    switch (gpgme_data_identify(d->data, 0)) {
+    case GPGME_DATA_TYPE_INVALID:       return Invalid;
+    case GPGME_DATA_TYPE_UNKNOWN:       return Unknown;
+    case GPGME_DATA_TYPE_PGP_SIGNED:    return PGPSigned;
+    case GPGME_DATA_TYPE_PGP_OTHER:     return PGPOther;
+    case GPGME_DATA_TYPE_PGP_KEY:       return PGPKey;
+    case GPGME_DATA_TYPE_CMS_SIGNED:    return CMSSigned;
+    case GPGME_DATA_TYPE_CMS_ENCRYPTED: return CMSEncrypted;
+    case GPGME_DATA_TYPE_CMS_OTHER:     return CMSOther;
+    case GPGME_DATA_TYPE_X509_CERT:     return X509Cert;
+    case GPGME_DATA_TYPE_PKCS12:        return PKCS12;
+    }
+    return Invalid;
+}
+
 char *GpgME::Data::fileName() const
 {
     return gpgme_data_get_file_name(d->data);
index 97e4202..efb1e79 100644 (file)
@@ -82,6 +82,20 @@ public:
     Encoding encoding() const;
     Error setEncoding(Encoding encoding);
 
+    enum Type {
+        Invalid,
+        Unknown,
+        PGPSigned,
+        PGPOther,
+        PGPKey,
+        CMSSigned,
+        CMSEncrypted,
+        CMSOther,
+        X509Cert,
+        PKCS12
+    };
+    Type type() const;
+
     char *fileName() const;
     Error setFileName(const char *name);