security.h
00001 /*************************************************************************** 00002 security.h - description 00003 ------------------- 00004 begin : Thu Jun 24 11:22:12 2004 00005 copyright : (C) 2004, 2005 by Andras Mantia <amantia@kde.org> 00006 ***************************************************************************/ 00007 00008 /*************************************************************************** 00009 * * 00010 * This program is free software; you can redistribute it and/or modify * 00011 * it under the terms of the GNU Library General Public License as * 00012 * published by the Free Software Foundation; version 2 of the License. * 00013 * * 00014 ***************************************************************************/ 00015 00016 00017 #ifndef SECURITY_H 00018 #define SECURITY_H 00019 00020 //qt includes 00021 #include <qmap.h> 00022 #include <qobject.h> 00023 00024 class KProcIO; 00025 class KProcess; 00026 00027 struct KeyStruct { 00028 QString id; 00029 QString name; 00030 QString mail; 00031 bool trusted; 00032 bool secret; 00033 }; 00034 00042 namespace KNS { 00043 00044 class Security : public QObject 00045 { 00046 Q_OBJECT 00047 public: 00048 static Security* const ref() 00049 { 00050 static Security *m_ref; 00051 if (!m_ref) m_ref = new Security(); 00052 return m_ref; 00053 } 00054 ~Security(); 00055 00056 00062 void checkValidity(const QString &fileName); 00063 00070 void signFile(const QString &fileName); 00077 KeyStruct signatureKey() {return m_signatureKey;} 00078 00079 enum Results { 00080 MD5_OK = 1, 00081 SIGNED_OK = 2, 00082 SIGNED_BAD = 4, 00083 TRUSTED = 8, 00084 UNKNOWN = 16, 00085 SIGNED_BAD_CLEAR = 27, 00086 BAD_PASSPHRASE = 32 00087 }; 00088 00089 public slots: 00091 void readKeys(); 00093 void readSecretKeys(); 00096 void slotCheckValidity(); 00097 00101 void slotSignFile(); 00102 00103 private: 00104 Security(); 00105 00106 enum RunMode { 00107 List = 0, 00108 ListSecret, 00109 Verify, 00110 Sign 00111 }; 00112 00113 KeyStruct m_signatureKey; 00114 int m_result; 00115 int m_runMode; 00116 bool m_gpgRunning; 00117 bool m_keysRead; 00118 QMap<QString, KeyStruct> m_keys; 00119 QString m_fileName; 00120 QString m_secretKey; 00121 00122 private slots: 00123 void slotProcessExited(KProcess *process); 00124 void slotDataArrived(KProcIO *process); 00125 00126 signals: 00131 void validityResult(int result); 00136 void fileSigned(int result); 00137 }; 00138 00139 } 00140 00141 #endif