From d949d711dc1d944a9d627d39a89af74943a5a8c1 Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Tue, 12 Apr 2016 16:05:31 +0200 Subject: [PATCH] Cpp: Add support for gpgme_data_identify * lang/cpp/src/data.cpp (Data::type): New. * lang/cpp/src/data.h (Data::Type): New enum mapping. --- lang/cpp/src/data.cpp | 20 ++++++++++++++++++++ lang/cpp/src/data.h | 14 ++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lang/cpp/src/data.cpp b/lang/cpp/src/data.cpp index b07406cf..bf9a629f 100644 --- a/lang/cpp/src/data.cpp +++ b/lang/cpp/src/data.cpp @@ -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); diff --git a/lang/cpp/src/data.h b/lang/cpp/src/data.h index 97e42029..efb1e790 100644 --- a/lang/cpp/src/data.h +++ b/lang/cpp/src/data.h @@ -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);