CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CondCore/DBCommon/interface/DecodingKey.h

Go to the documentation of this file.
00001 #ifndef CondCoreDBCommon_DecodingKey_H
00002 #define CondCoreDBCommon_DecodingKey_H
00003 
00004 #include <iostream>
00005 #include <string>
00006 #include <set>
00007 #include <map>
00008 
00009 namespace cond {
00010 
00011   struct ServiceCredentials {
00012     ServiceCredentials();
00013     std::string connectionString;
00014     std::string userName;
00015     std::string password;
00016   };
00017 
00018   class KeyGenerator {
00019     public:
00020 
00021     KeyGenerator();
00022 
00023     std::string make( size_t keySize );
00024     std::string makeWithRandomSize( size_t maxSize );
00025     
00026     private:
00027 
00028     int m_iteration;
00029 
00030   };
00031 
00032   class DecodingKey {
00033 
00034     public:
00035 
00036     static const std::string FILE_NAME;
00037     static const std::string FILE_PATH;
00038     static const size_t DEFAULT_KEY_SIZE = 100;
00039     static std::string templateFile();
00040 
00041     public:
00042 
00043     DecodingKey();
00044 
00045     virtual ~DecodingKey(){}
00046 
00047     size_t init( const std::string& keyFileName,  const std::string& password, bool readMode = true );
00048 
00049     size_t createFromInputFile( const std::string& inputFileName, size_t generatedKeySize = 0 );
00050 
00051     void list( std::ostream& out );
00052 
00053     void flush();
00054 
00055     const std::string& principalName() const;
00056 
00057     const std::string& principalKey() const;
00058 
00059     bool isNominal() const;
00060 
00061     const std::string& ownerName() const;
00062 
00063     const std::map< std::string, ServiceCredentials >& services() const;
00064 
00065     void addDefaultService( const std::string& connectionString );
00066 
00067     void addService( const std::string& serviceName, const std::string& connectionString, const std::string& userName, const std::string& password );
00068 
00069 
00070     private:
00071 
00072     std::string m_fileName;
00073 
00074     bool m_mode;
00075 
00076     std::string m_pwd;
00077 
00078     std::string m_principalName;
00079 
00080     std::string m_principalKey;
00081 
00082     std::string m_owner;
00083 
00084     std::map< std::string, ServiceCredentials > m_services;
00085     
00086   };
00087 }
00088 
00089 inline
00090 cond::KeyGenerator::KeyGenerator():m_iteration(0){
00091 }
00092 
00093 inline
00094 cond::ServiceCredentials::ServiceCredentials():connectionString(""),userName(""),password(""){
00095 }
00096 
00097 inline
00098 cond::DecodingKey::DecodingKey():m_fileName(""),m_mode( true ),m_pwd(""),m_principalName(""),m_principalKey(""),m_owner(""),m_services(){
00099 }
00100 
00101 inline
00102 const std::string& 
00103 cond::DecodingKey::principalName() const {
00104   return m_principalName;
00105 }
00106 
00107 inline
00108 const std::string& 
00109 cond::DecodingKey::principalKey() const {
00110   return  m_principalKey;
00111 }
00112  
00113 inline
00114 bool 
00115 cond::DecodingKey::isNominal() const {
00116   return  !m_owner.empty();
00117 }
00118 
00119 inline
00120 const std::string& 
00121 cond::DecodingKey::ownerName() const {
00122   return  m_owner;
00123 }
00124 
00125 inline
00126 const std::map< std::string, cond::ServiceCredentials >&
00127 cond::DecodingKey::services() const { return m_services; }
00128 
00129 #endif //  CondCoreDBCommon_DecodingKey_H
00130 
00131