22 #include <openssl/evp.h> 23 #include <openssl/pem.h> 28 PrcKeyRegistry *PrcKeyRegistry::_global_ptr =
nullptr;
44 <<
"Internal error--PrcKeyRegistry destructor called!\n";
56 record_keys(
const KeyDef *key_def,
size_t num_keys) {
57 for (
size_t i = 0; i < num_keys; i++) {
58 const KeyDef *def = &key_def[i];
59 if (def->_data !=
nullptr) {
61 while (_keys.size() <= i) {
65 key._generated_time = 0;
68 if (_keys[i]._def != def) {
69 if (_keys[i]._pkey !=
nullptr) {
70 EVP_PKEY_free(_keys[i]._pkey);
71 _keys[i]._pkey =
nullptr;
74 _keys[i]._generated_time = def->_generated_time;
87 set_key(
size_t n, EVP_PKEY *pkey, time_t generated_time) {
89 while (_keys.size() <= n) {
93 key._generated_time = 0;
96 _keys[n]._def =
nullptr;
97 if (_keys[n]._pkey !=
nullptr) {
98 EVP_PKEY_free(_keys[n]._pkey);
99 _keys[n]._pkey =
nullptr;
101 _keys[n]._pkey = pkey;
102 _keys[n]._generated_time = generated_time;
110 size_t PrcKeyRegistry::
111 get_num_keys()
const {
118 EVP_PKEY *PrcKeyRegistry::
119 get_key(
size_t n)
const {
120 nassertr(n < _keys.size(),
nullptr);
122 if (_keys[n]._def !=
nullptr) {
123 if (_keys[n]._pkey ==
nullptr) {
125 const KeyDef *def = _keys[n]._def;
126 BIO *mbio = BIO_new_mem_buf((
void *)def->_data, def->_length);
127 EVP_PKEY *pkey = PEM_read_bio_PUBKEY(mbio,
nullptr,
nullptr,
nullptr);
128 ((PrcKeyRegistry *)
this)->_keys[n]._pkey = pkey;
131 if (pkey ==
nullptr) {
133 ((PrcKeyRegistry *)
this)->_keys[n]._def =
nullptr;
138 return _keys[n]._pkey;
145 time_t PrcKeyRegistry::
146 get_generated_time(
size_t n)
const {
147 nassertr(n < _keys.size(), 0);
149 return _keys[n]._generated_time;
155 PrcKeyRegistry *PrcKeyRegistry::
157 if (_global_ptr ==
nullptr) {
158 _global_ptr =
new PrcKeyRegistry;
163 #endif // HAVE_OPENSSL PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.