Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:36:47

0001 #include "CondCore/Utilities/interface/Utilities.h"
0002 #include "CondCore/CondDB/interface/DecodingKey.h"
0003 #include "CondCore/CondDB/interface/Cipher.h"
0004 #include "CondCore/CondDB/interface/Auth.h"
0005 #include "CondCore/CondDB/interface/Exception.h"
0006 
0007 #include <boost/program_options.hpp>
0008 #include <fstream>
0009 #include <iostream>
0010 #include <stdexcept>
0011 
0012 namespace cond {
0013   class KeyMgrUtilities : public Utilities {
0014   public:
0015     KeyMgrUtilities();
0016     ~KeyMgrUtilities() override;
0017     int execute() override;
0018   };
0019 }  // namespace cond
0020 
0021 cond::KeyMgrUtilities::KeyMgrUtilities() : Utilities("cmscond_key_mgr") {
0022   addOption<std::string>("create", "c", "creating from input file data");
0023   addOption<std::string>("read", "r", "read data from input file");
0024   addOption<bool>("generate", "g", "generate a new key when not specified");
0025   addOption<bool>("dump_template", "d", "dump an input file template");
0026 }
0027 
0028 cond::KeyMgrUtilities::~KeyMgrUtilities() {}
0029 
0030 int cond::KeyMgrUtilities::execute() {
0031   std::string inFile("");
0032   if (hasOptionValue("create")) {
0033     inFile = getOptionValue<std::string>("create");
0034     size_t keySize = 0;
0035     if (hasOptionValue("generate"))
0036       keySize = auth::COND_AUTHENTICATION_KEY_SIZE;
0037     if (!inFile.empty()) {
0038       auth::DecodingKey key;
0039       key.init(auth::DecodingKey::FILE_NAME, auth::COND_KEY, false);
0040       key.createFromInputFile(inFile, keySize);
0041       if (hasDebug())
0042         key.list(std::cout);
0043       key.flush();
0044       return 0;
0045     }
0046     return 1;
0047   }
0048 
0049   if (hasOptionValue("read")) {
0050     inFile = getOptionValue<std::string>("read");
0051     if (!inFile.empty()) {
0052       auth::DecodingKey key;
0053       key.init(inFile, auth::COND_KEY);
0054       key.list(std::cout);
0055       return 0;
0056     }
0057     return 1;
0058   }
0059 
0060   if (hasOptionValue("dump_template")) {
0061     std::cout << auth::DecodingKey::templateFile() << std::endl;
0062     return 0;
0063   }
0064 
0065   return 1;
0066 }
0067 
0068 int main(int argc, char** argv) {
0069   cond::KeyMgrUtilities utilities;
0070   return utilities.run(argc, argv);
0071 }