Rev

Rev 3349 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | Bug Tracker

Rev 3349 Rev 3350
Line 20... Line 20...
20
using namespace std; // Required for isnan()
20
using namespace std; // Required for isnan()
21
#include "etsi_ts103097_certificate_codec.hh"
21
#include "etsi_ts103097_certificate_codec.hh"
22
22
23
#include "loggers.hh"
23
#include "loggers.hh"
24
24
25
/*bool security_cache_comp::operator()(const OCTETSTRING& p_lhs, const OCTETSTRING& p_rhs) const {
25
bool security_cache_comp::operator()(const OCTETSTRING& p_lhs, const OCTETSTRING& p_rhs) const {
26
  loggers::get_instance().log_msg(">>> security_cache_comp::operator(): ", p_lhs);
26
  loggers::get_instance().log_msg(">>> security_cache_comp::operator(): ", p_lhs);
27
  loggers::get_instance().log_msg(">>> security_cache_comp::operator(): ", p_rhs);
27
  loggers::get_instance().log_msg(">>> security_cache_comp::operator(): ", p_rhs);
28
  if (p_lhs.lengthof() != p_rhs.lengthof()) {
28
  unsigned char* first1 = (unsigned char*)static_cast<const unsigned char*>(p_lhs);
29
    return !false;
29
  unsigned char* first2 = (unsigned char*)static_cast<const unsigned char*>(p_rhs);
30
  } else {
-
 
31
    for (int i = 0; i < p_lhs.lengthof(); i++) {
30
  unsigned char* last1 = p_lhs.lengthof() + (unsigned char*)static_cast<const unsigned char*>(p_lhs);
32
      loggers::get_instance().log("security_cache_comp::operator(): compare %02x with %02x", p_lhs[i].get_octet(), p_rhs[i].get_octet());
31
  unsigned char* last2 = p_rhs.lengthof() + (unsigned char*)static_cast<const unsigned char*>(p_rhs);
-
 
32
33
      if (p_lhs[i].get_octet() != p_rhs[i].get_octet()) {
33
  while (first1 != last1) {
34
        loggers::get_instance().log("<<< security_cache_comp::operator(): false");
34
    if ((first2 == last2) || (*first2 < *first1)) {
35
        return !false;
35
      return false;
-
 
36
    } else if (*first1 < *first2) {
36
      }
37
      return true;
37
    }
38
    }
-
 
39
    ++first1;
-
 
40
    ++first2;
-
 
41
  } // End of 'while' statement
-
 
42
  return (first2 != last2);
38
  }
43
}
39
  loggers::get_instance().log("<<< security_cache_comp::operator(): true");
-
 
40
  return !true;
-
 
41
}*/
-
 
42
44
43
security_cache::security_cache(): _certificates(), _hashed_id8s() {
45
security_cache::security_cache(): _certificates(), _hashed_id8s() {
44
  loggers::get_instance().log(">>> security_cache::security_cache");
46
  loggers::get_instance().log(">>> security_cache::security_cache");
45
} // End of ctor
47
} // End of ctor
46
48
Line 58... Line 60...
58
} // End of clear method
60
} // End of clear method
59
61
60
int security_cache::get_certificate_id(const OCTETSTRING& p_hashed_id8, std::string& p_certifcate_id) const {
62
int security_cache::get_certificate_id(const OCTETSTRING& p_hashed_id8, std::string& p_certifcate_id) const {
61
  loggers::get_instance().log_msg(">>> security_cache::get_certificate_id: ", p_hashed_id8);
63
  loggers::get_instance().log_msg(">>> security_cache::get_certificate_id: ", p_hashed_id8);
62
64
63
  //std::map<OCTETSTRING, std::string>::const_iterator it = _hashed_id8s.find(p_hashed_id8);
65
  std::map<OCTETSTRING, std::string>::const_iterator it = _hashed_id8s.find(p_hashed_id8);
64
  std::vector<unsigned char> v(static_cast<const unsigned char*>(p_hashed_id8), p_hashed_id8.lengthof() + static_cast<const unsigned char*>(p_hashed_id8));
66
  //std::vector<unsigned char> v(static_cast<const unsigned char*>(p_hashed_id8), p_hashed_id8.lengthof() + static_cast<const unsigned char*>(p_hashed_id8));
65
  std::map<std::vector<unsigned char>, std::string>::const_iterator it = _hashed_id8s.find(v);
67
  //std::map<std::vector<unsigned char>, std::string>::const_iterator it = _hashed_id8s.find(v);
66
  if (it == _hashed_id8s.cend()) {
68
  if (it == _hashed_id8s.cend()) {
67
    dump();
69
    dump();
68
    p_certifcate_id = "";
70
    p_certifcate_id = "";
69
    return -1;
71
    return -1;
70
  }
72
  }
Line 289... Line 291...
289
    _certificates.erase(i);
291
    _certificates.erase(i);
290
  }
292
  }
291
293
292
  _certificates.insert(std::pair<std::string, std::unique_ptr<security_db_record> >(key, std::unique_ptr<security_db_record>(p)));
294
  _certificates.insert(std::pair<std::string, std::unique_ptr<security_db_record> >(key, std::unique_ptr<security_db_record>(p)));
293
295
294
  //std::map<OCTETSTRING, std::string>::const_iterator h = _hashed_id8s.find(hashed_id8);
296
  std::map<OCTETSTRING, std::string>::const_iterator h = _hashed_id8s.find(hashed_id8);
295
  std::vector<unsigned char> v(static_cast<const unsigned char*>(hashed_id8), hashed_id8.lengthof() + static_cast<const unsigned char*>(hashed_id8));
297
  //std::vector<unsigned char> v(static_cast<const unsigned char*>(hashed_id8), hashed_id8.lengthof() + static_cast<const unsigned char*>(hashed_id8));
296
  loggers::get_instance().log_to_hexa("security_cache::store_certificate: Converted hashed_id8: ", v.data(), v.size());
-
 
297
  std::map<std::vector<unsigned char>, std::string>::const_iterator h = _hashed_id8s.find(v);
298
  //std::map<std::vector<unsigned char>, std::string>::const_iterator h = _hashed_id8s.find(v);
298
  if (h != _hashed_id8s.cend()) {
299
  if (h != _hashed_id8s.cend()) {
299
    _hashed_id8s.erase(h);
300
    _hashed_id8s.erase(h);
300
  }
301
  }
301
  //_hashed_id8s.insert(std::pair<OCTETSTRING, std::string&>(hashed_id8, key));
302
  _hashed_id8s.insert(std::pair<OCTETSTRING, std::string&>(hashed_id8, key));
302
  loggers::get_instance().log("security_cache::store_certificate: Insert %s to _hashed_id8", key.c_str());
-
 
303
  _hashed_id8s.insert(std::pair<std::vector<unsigned char>, std::string&>(v, key));
303
  //_hashed_id8s.insert(std::pair<std::vector<unsigned char>, std::string&>(v, key));
304
 
304
 
305
  //dump();
305
  //dump();
306
306
307
  return 0;
307
  return 0;
308
}
308
}
Line 325... Line 325...
325
    loggers::get_instance().log_msg("security_cache::dump: public_enc_key_x = ", p->public_enc_key_x());
325
    loggers::get_instance().log_msg("security_cache::dump: public_enc_key_x = ", p->public_enc_key_x());
326
    loggers::get_instance().log_msg("security_cache::dump: public_enc_key_y = ", p->public_enc_key_y());
326
    loggers::get_instance().log_msg("security_cache::dump: public_enc_key_y = ", p->public_enc_key_y());
327
    loggers::get_instance().log_msg("security_cache::dump: public_enc_comp_key = ", p->public_enc_comp_key());
327
    loggers::get_instance().log_msg("security_cache::dump: public_enc_comp_key = ", p->public_enc_comp_key());
328
  } // End of 'for' statement
328
  } // End of 'for' statement
329
  //for (std::map<OCTETSTRING, std::string>::const_iterator it = _hashed_id8s.cbegin(); it != _hashed_id8s.cend(); ++it) {
329
  //for (std::map<OCTETSTRING, std::string>::const_iterator it = _hashed_id8s.cbegin(); it != _hashed_id8s.cend(); ++it) {
330
  for (std::map<std::vector<unsigned char>, std::string>::const_iterator it = _hashed_id8s.cbegin(); it != _hashed_id8s.cend(); ++it) {
330
  for (std::map<OCTETSTRING/*std::vector<unsigned char>*/, std::string>::const_iterator it = _hashed_id8s.cbegin(); it != _hashed_id8s.cend(); ++it) {
331
    //    loggers::get_instance().log_to_hexa("security_cache::dump: Hashedid8 key = ", it->first.data(), it->first.size());
331
    loggers::get_instance().log_msg("security_cache::dump: Hashedid8 key = ", it->first);
332
    loggers::get_instance().log("security_cache::dump: Hashedid8 idx ==> %s", it->second.c_str());
332
    loggers::get_instance().log("security_cache::dump: Hashedid8 idx ==> %s", it->second.c_str());
333
  } // End of 'for' statement
333
  } // End of 'for' statement
334
} // End of method dump
334
} // End of method dump