kleopatra
classify.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <gpgme++/global.h>
00034
00035 #ifndef __KLEOPATRA_UISERVER_CLASSIFY_H__
00036 #define __KLEOPATRA_UISERVER_CLASSIFY_H__
00037
00038 class QString;
00039 class QStringList;
00040
00041 namespace Kleo {
00042
00043 namespace Class {
00044 enum {
00045 NoClass = 0,
00046
00047
00048 CMS = 0x01,
00049 OpenPGP = 0x02,
00050
00051 AnyProtocol = OpenPGP|CMS,
00052 ProtocolMask = AnyProtocol,
00053
00054
00055 Binary = 0x04,
00056 Ascii = 0x08,
00057
00058 AnyFormat = Binary|Ascii,
00059 FormatMask = AnyFormat,
00060
00061
00062 DetachedSignature = 0x010,
00063 OpaqueSignature = 0x020,
00064 ClearsignedMessage = 0x040,
00065
00066 AnySignature = DetachedSignature|OpaqueSignature|ClearsignedMessage,
00067
00068 CipherText = 0x080,
00069
00070 AnyMessageType = AnySignature|CipherText,
00071
00072 Certificate = 0x100,
00073 ExportedPSM = 0x200,
00074
00075 AnyCertStoreType = Certificate|ExportedPSM,
00076
00077 CertificateRequest = 0x400,
00078
00079 AnyType = AnyMessageType|AnyCertStoreType|CertificateRequest,
00080 TypeMask = AnyType
00081 };
00082 }
00083
00084 unsigned int classify( const QString & filename );
00085 unsigned int classifyContent( const QByteArray & data );
00086
00087 QString findSignedData( const QString & signatureFileName );
00088 QStringList findSignatures( const QString & signedDataFileName );
00089 QString outputFileName( const QString & input );
00090
00091 const char * outputFileExtension( unsigned int classification );
00092
00093 QString printableClassification( unsigned int classification );
00094
00095 #define make_convenience( What, Mask ) \
00096 inline bool is##What( const QString & filename ) { \
00097 return ( classify( filename ) & Class::Mask ) == Class::What ; \
00098 } \
00099 inline bool is##What( const unsigned int classifcation ) { \
00100 return ( classifcation & Class::Mask ) == Class::What ; \
00101 } \
00102 inline bool mayBe##What( const QString & filename ) { \
00103 return classify( filename ) & Class::What ; \
00104 } \
00105 inline bool mayBe##What( const unsigned int classifcation ) { \
00106 return classifcation & Class::What ; \
00107 }
00108
00109 make_convenience( CMS, ProtocolMask )
00110 make_convenience( OpenPGP, ProtocolMask )
00111
00112 make_convenience( Binary, FormatMask )
00113 make_convenience( Ascii, FormatMask )
00114
00115 make_convenience( DetachedSignature, TypeMask )
00116 make_convenience( OpaqueSignature, TypeMask )
00117 make_convenience( CipherText, TypeMask )
00118 make_convenience( AnyMessageType, TypeMask )
00119 #undef make_convenience
00120
00121 inline GpgME::Protocol findProtocol( const unsigned int classifcation ) {
00122 if ( isOpenPGP( classifcation ) )
00123 return GpgME::OpenPGP;
00124 else if ( isCMS( classifcation ) )
00125 return GpgME::CMS;
00126 else
00127 return GpgME::UnknownProtocol;
00128 }
00129 inline GpgME::Protocol findProtocol( const QString & filename ) {
00130 return findProtocol( classify( filename ) );
00131 }
00132
00133 }
00134
00135 #endif