Example #1
0
/**
 * Searches certificate by subject and returns a copy of it if found.
 * If not found returns <code>NULL</code>.
 * NB! The returned certificate must be freed with OpenSSL function X509_free(X509* cert).
 *
 * @param subject certificate subject.
 * @return returns copy of found certificate or <code>NULL</code> if certificate was not found.
 * @throws IOException exception is thrown if copying certificate failed.
 */
X509Cert X509CertStore::findIssuer(const X509Cert &cert, const set<string> &type) const
{
    activate(cert.issuerName("C"));
    SCOPE(AUTHORITY_KEYID, akid, X509_get_ext_d2i(cert.handle(), NID_authority_key_identifier, nullptr, nullptr));
    for(const TSL::Service &s: *d)
    {
        if(type.find(s.type) == type.cend())
            continue;
        for(const X509Cert &i: s.certs)
        {
            if(!akid || !akid->keyid)
            {
                if(X509_NAME_cmp(X509_get_subject_name(i.handle()), X509_get_issuer_name(cert.handle())))
                    return i;
            }
            else
            {
                SCOPE(ASN1_OCTET_STRING, skid, X509_get_ext_d2i(i.handle(), NID_subject_key_identifier, nullptr, nullptr));
                if(skid.get() && ASN1_OCTET_STRING_cmp(akid->keyid, skid.get()) == 0)
                    return i;
            }
        }
    }
    return X509Cert();
}
/** Extract masked detectors from a MaskWorkspace
  * @return vector of detector IDs of the detectors that are
  * masked
  */
std::vector<detid_t> ExtractMaskToTable::extractMaskFromMaskWorkspace() {
  // output vector
  std::vector<detid_t> maskeddetids;

  // Go through all spectra to find masked workspace
  MaskWorkspace_const_sptr maskws =
      boost::dynamic_pointer_cast<const MaskWorkspace>(m_dataWS);
  size_t numhist = maskws->getNumberHistograms();
  for (size_t i = 0; i < numhist; ++i) {
    // Rule out the spectrum without mask
    if (maskws->readY(i)[0] < 1.0E-9)
      continue;

    // Get spectrum
    const API::ISpectrum *spec = maskws->getSpectrum(i);
    if (!spec)
      throw runtime_error(
          "Unable to get spectrum reference from mask workspace.");

    const set<detid_t> detidset = spec->getDetectorIDs();
    std::copy(detidset.cbegin(), detidset.cend(),
              std::inserter(maskeddetids, maskeddetids.end()));
  }
  return maskeddetids;
}
Example #3
0
void EulerUtils::Display::printSet ( string itemName, const set<unsigned long long>& data ) {
	cout << endl << "Printing " << itemName << "..." << endl;
	for ( auto i = data.cbegin(); i != data.cend(); i++ ) {
        cout << ( i == data.cbegin() ? "" : ", " ) << *i ;
    }
    cout << endl;
}
Example #4
0
void BogglePlayer::buildLexicon(const set<string>& word_list){
  string newWord; 
  const int minimum_word_length = 3;
  set<string>::iterator wordlistBegin = word_list.cbegin();
  set<string>::iterator wordlistEnd = word_list.cend();
  std::srand(unsigned(time(0)));
  std::vector<string> vector;

    for(; wordlistBegin != wordlistEnd; ++wordlistBegin)
    {
        vector.push_back(*wordlistBegin);
    }

    std::random_shuffle(vector.begin(), vector.end());
   
    for(auto it = vector.begin(); it != vector.end(); ++it)
    {
        newWord.assign(*it);
       
        if(newWord.length() >= minimum_word_length)
        {
            t->add(newWord);
        }
    }
   
    BogglePlayer::buildLexiconFlag = true;
};
Example #5
0
/**
 * Return STACK_OF(X509) containing all certs loaded from directory
 * @return STACK_OF(X509) all certs in store.
 * throws IOException
 */
vector<X509Cert> X509CertStore::certs(const set<string> &type) const
{
    vector<X509Cert> certs;
    for(const TSL::Service &s: *d)
    {
        if(type.find(s.type) != type.cend())
            certs.insert(certs.end(), s.certs.cbegin(), s.certs.cend());
    }
    return certs;
}
Example #6
0
int X509CertStore::validate(int ok, X509_STORE_CTX *ctx, const set<string> &type)
{
    switch(X509_STORE_CTX_get_error(ctx))
    {
    case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
    case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
    case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
    case X509_V_ERR_CERT_UNTRUSTED:
    {
        X509 *x509 = X509_STORE_CTX_get0_cert(ctx);
        SCOPE(AUTHORITY_KEYID, akid, X509_get_ext_d2i(x509, NID_authority_key_identifier, nullptr, nullptr));
        for(const TSL::Service &s: *instance()->d)
        {
            if(type.find(s.type) == type.cend())
                continue;
            auto certFound = find_if(s.certs.cbegin(), s.certs.cend(), [&](const X509Cert &issuer){
                if(X509_cmp(x509, issuer.handle()) == 0)
                    return true;
                if(!akid || !akid->keyid)
                {
                    if(X509_NAME_cmp(X509_get_subject_name(issuer.handle()), X509_get_issuer_name(x509)) != 0)
                        return false;
                }
                else
                {
                    SCOPE(ASN1_OCTET_STRING, skid, X509_get_ext_d2i(issuer.handle(), NID_subject_key_identifier, nullptr, nullptr));
                    if(!skid.get() || ASN1_OCTET_STRING_cmp(akid->keyid, skid.get()) != 0)
                        return false;
                }
                SCOPE(EVP_PKEY, pub, X509_get_pubkey(issuer.handle()));
                if(X509_verify(x509, pub.get()) == 1)
                    return true;
                OpenSSLException(); //Clear errors
                return false;
            });
            if(certFound == s.certs.cend())
                continue;
            X509_STORE_CTX_set_ex_data(ctx, 0, const_cast<TSL::Validity*>(&s.validity[0]));
            X509_VERIFY_PARAM *param = X509_STORE_CTX_get0_param(ctx);
            if(!(X509_VERIFY_PARAM_get_flags(param) & X509_V_FLAG_USE_CHECK_TIME) || s.validity.empty())
                return 1;
            for(const TSL::Validity &v: s.validity)
            {
                if(X509_VERIFY_PARAM_get_time(param) >= v.start && (v.end == 0 || X509_VERIFY_PARAM_get_time(param) <= v.end))
                {
                    X509_STORE_CTX_set_ex_data(ctx, 0, const_cast<TSL::Validity*>(&v));
                    return 1;
                }
            }
        }
        return ok;
    }
    default: return ok;
    }
}
Example #7
0
unsigned RelationManager::cleanSet(set<const Class *> &s)
{
	unsigned deletedRecords = 0;
	for (auto it = s.cbegin(); it != s.cend();) {
		if ((*it) == nullptr) {
			s.erase(it++); ++deletedRecords;
		} else ++it;
	}

	return deletedRecords;
}
Example #8
0
void Remove( TiXmlElement* element, const set<string>& tagsToRemove )
{
	TiXmlElement* curr = element->FirstChildElement( );
	while( curr != nullptr )
	{
		TiXmlElement* next = curr->NextSiblingElement( );
		if( tagsToRemove.find(curr->ValueStr()) != tagsToRemove.cend() )
		{
			element->RemoveChild( curr );
		}

		curr = next;
	}
}
Example #9
0
void Server::precomputeTransferPatterns() {
  // ProfilerStart("log/tp.perf");
  if (loadTransferPatternsDB(&_tpdb)) {
    _log.info("Loaded transfer patterns.");
  } else {
    if (_tpdb.numGraphs() == 0) {
      _tpdb.init(_network.numStops(), _router.hubs());
    }

    const int progId = _log.beginProg();
    const size_t numStops = _network.numStops();
    const int nThreads = _maxWorkers > omp_get_max_threads() ?
                         omp_get_max_threads() : _maxWorkers;
    omp_set_num_threads(nThreads);
    int progress = 0;
    #pragma omp parallel
    {  // NOLINT
    const TransitNetwork network = _network;
    const HubSet hubs = _router.hubs();
    TPDB tpdb(network.numStops(), hubs);
    #pragma omp for schedule(dynamic, 3)
    for (size_t stop = 0; stop < numStops; ++stop) {
      const set<vector<int> > patterns =
          TransferPatternRouter::computeTransferPatterns(network, stop, hubs);
      for (auto it = patterns.cbegin(), end = patterns.cend(); it != end; ++it)
        tpdb.addPattern(*it);
      tpdb.finalise(stop);  // clears construction cache

      #pragma omp critical(progress_message)
      if (progress < 100 || progress % (numStops / 100) == 0)
        _log.prog(progId, progress + 1, numStops,
                  "computing transfer patterns (mt)", omp_get_num_threads());
      #pragma omp atomic
      ++progress;
    }
    #pragma omp critical(reduction)
    {  // NOLINT
      // combine and clear the local TPDB
      _tpdb += tpdb;
      tpdb = TransferPatternsDB();
    }
    }  // pragma omp parallel

    saveTransferPatternsDB(_tpdb);
  }
  _router.transferPatternsDB(_tpdb);
  // ProfilerStop();
}
Example #10
0
    static set<range> merge(const vector<range>& vr){
        const set<range> sr(vr.cbegin(), vr.cend());
        set<range> result;
//        doAlgo(vr.cbegin(), vr.cend(), res);
        if(sr.size() == 0){
            return result;
        }
        auto iter = sr.cbegin();
        range prev = *iter;
        while(++iter != sr.cend()){
            range curr = *iter;
            if(prev.second < curr.first){
                result.insert(prev);
                prev = curr;
            } else {
                prev = range(prev.first, max(prev.second, curr.second));
            }
        }
        result.insert(prev);
        return result;
    }
Example #11
0
set<M> operator+ (const set<M>& lhs, const set<M>& rhs){
  set<M> U{lhs};
  U.insert(rhs.cbegin(), rhs.cend());
  return U;
}
Example #12
0
int main()
{
  
 
  //the next few lines are to set unbuffered cin 
  //it means you don't have to press [enter] in the keyboard
  //
  tcgetattr(STDIN_FILENO,&old_t);//gets the current terminal setings.

  new_t=old_t;

  new_t.c_lflag &=(~ICANON & ~ECHO);//disable ...

  tcsetattr(STDIN_FILENO,TCSANOW,&new_t);//set new settings unbuffered

  // *****************************************************


  size_t number_partidas;
  size_t number_projects=0;

  while(1)
    {
      main1=&main2;
      char option=main1->menu();
      bool ok;
      switch(option)
	{

	case 'w':
	  //write a new partida
	  /* restore the former settings */
	  tcsetattr(STDIN_FILENO,TCSANOW,&old_t);//buffered keyboard
	  ok = true;
	  try
	    {
	      main1 -> enter_data ();//we've filled a new object
	    }
	  catch(const char* e)
	    {
	      cout<<"errooooor !!!!!!"<<endl;
	      cout << endl << e << endl;
	      ok = false;
	    } 

	  if(ok)
	    {
	      cont_main2.insert(main2);
	      // int a=3;
	      if(!project.size()) project.push_back(cont_main2);

	      else
		{
		  project.pop_back();

		  project.push_back(cont_main2);

		}
	    }


	  else cout << "I have inserted no partida";
	  tcsetattr(STDIN_FILENO,TCSANOW,&new_t);//set new settings unbuffered
 	  break;



	case 'p':
	  //see a specific partida
	  cout << "\n\n";
	  //	  string part=main2.partida;
	  
	  /* restore the former settings */
	  tcsetattr(STDIN_FILENO,TCSANOW,&old_t);//keyboard buffered

	  cin>>main2.parti;
	      

	  tcsetattr(STDIN_FILENO,TCSANOW,&new_t);//set new settings unbuffered

	 

	  //converses string to float
	  main2.find_partida(main2.parti);//find out the actual number
	  
	  cout << fixed << setprecision(2);//only 2 decimals
	  //	  main2.find_partida(main2.partida);

	  p=cont_main2.find(main2);//it is in cont_main2
	  if(p != cont_main2.cend())
	    {
	      main2 = *p;	 
	      main1 = &main2;
	      
	      //main1->print_partida(main2);//p contains a object (partida
	      main1 -> print_partida(main2);//p contains a object (partida
	      cout << "\nEdit ? (y/n)";
	      char ed;
	      cin >> ed;
	      if(ed == 'y' || ed == 'Y')main1->edit();
	      
	    }
	  else cout << "\n\nNot found !!!!" << endl;
	  break;


	  
	case 'e':
	  //edit a specific partida
	  break;


	case 's':
	  //we want to save th whole set, not only one object

	  file.open("prevision.bin",ios_base::out | ios_base::binary);
	  if(file.is_open())
	    {
	      number_partidas = cont_main2.size();

	      //    static size_t  number_projects=0;

	      //     number_projects=project.size();

	      //the first byte in disk will be the number of objects/partidas.. next the objects
	      file.write(reinterpret_cast<const char*>(&(number_partidas)),sizeof(number_partidas));


	      //the second byte will contain the number of projectd
	      // file.write(reinterpret_cast<const char*>(&(number_projects)),sizeof(number_projects));

	      p=cont_main2.cbegin();//point to the begining of the vector (dinamic array)
	      main2=*p;
	      main1=&main2;
	      //   main1 -> saveMonths();

	     
		  for(size_t x = 0 ; x < number_partidas ; ++x)
		    {
		      main2 = *p;
		      main1 -> save_file();//p contains an object a partida...saves ONE object/partida
		      ++p;//next object ... next partida
		    }
		
	    }
	  file.close();
	  cout << "\n*** FILE SAVED ***\n";
	  break;
	 
	case 'l':
	  file.open("prevision.bin",ios_base::in | ios_base::binary);
	  if(file.is_open())
	    {
	      
	       cont_main2.erase(cont_main2.begin(),cont_main2.end());
	       int numberPartidas;//we read the number of objects/partidas
	       file.read((char*)&numberPartidas,sizeof(numberPartidas) );
	       
		   
		     
		       for(int x = 0;x < numberPartidas; ++x)
			 main1 -> load_partida();
		     
		   project.push_back(cont_main2);
		   
		 } 
	    

	    file.close();






	    cout << "\n*** FILE LOADED ***\n";
	  break;

	case 'i':

	   number_partidas = cont_main2.size();
	   p_project = project.begin();
	   //	  	  p=cont_main2.begin();

		  cout << endl << "List:" << endl;
		  number_projects = project.size();

		  	  static size_t indexProjects;

		  indexProjects=0;

		  for(size_t proj = 0 ; proj < number_projects ; ++proj)
		    {
	
		      p = (*p_project).begin();//???????????????

		      cont_main2=*(project.begin());

		      p=cont_main2.begin();//ok !!!!!!

		      //	      main1 -> headProjectMonth(indexProjects);
		 
		      for(size_t x = 0 ; x<number_partidas ; ++x)
			{
			  main1 -> list();//writes one line/partida
			  ++p;
			}
		      cout << endl << endl;
		      ++p_project;
		      ++indexProjects;
		    }

	  cout << "\n\033[0;0mWould you like to create a monthly prevision from this list?" << "\033[?25h";

	  char a;
	  cin.clear();
	  cout << "\033[?25l";
	  cin >> a;

	  if(a =='y' || a =='Y')
	    {

	      project.push_back(cont_main2);
	      //now we should save this container of containers on HDD

	      //so.....
	      ++number_projects;



	      p_project=--project.end();//points past end so --
	      //no it point to the last set (the last budget)

	      cont_main2 = *p_project;//a contains a set a month
	      

	      //we go to the begin(). The firs partida of this new monthly
	      //budget.. Because the variable "month" is static.
	      //only storing in the first line we are storing the month of
	      //every partida.

	      main2 = *cont_main2.begin();//main 2 contains a line a single partida
	      main1 = &main2;
	   
	      cout << "\033[?25h";

	      
	      char monthLastPrevision[] = "MArch";
	      buffered();
	      cout << "\nWhat month? ";
	      cin >> monthLastPrevision;
	      

	      //we enter this month in the vector months
	      main1 -> enterMonth (monthLastPrevision);
	      

	      unbuffered();//cin unbuffered  (keyboard)
	     
	      cout << "\033[?25l";//hide cursor
	      
	    }