2 * Copyright (c) 2014 <copyright holder> <email>
4 * For license details, see the LICENSE file in the root of this project.
8 #include "GSSNameCache.h"
9 #include "util_base64.h"
10 #include "util_random.h"
14 GSSNameCache* GSSNameCache::_instance = 0;
16 GSSNameCache::GSSNameCache()
21 GSSNameCache::GSSNameCache ( const GSSNameCache& other )
26 GSSNameCache::~GSSNameCache()
31 GSSNameCache& GSSNameCache::operator= ( const GSSNameCache& other )
39 std::string GSSNameCache::store ( GSSName& data, std::string inKey )
48 if ( inKey.length() > 0 )
52 else if ( !generateKey(key) )
54 // Key generation failed. Eeek!
55 throw std::runtime_error("Could not generate random data for an ID");
58 // Store the key/value pair in the map
59 // Store the key in the context for convenience
60 // std::cout << "\n==> In GSSNameCache::store, about to store data in the names hash.\n";
65 // Return the key for future reference
69 /*************************************
70 * Generate random bytes, and base64 *
71 * encode them to be JSONable keys *
72 *************************************/
73 bool GSSNameCache::generateKey(std::string &key)
76 unsigned char theKey[KEYLEN];
80 // Generate random byte string
81 if (!randGenPseudoRandom(theKey, KEYLEN))
84 // Encode the binary string
85 base64EncodeStr(theKey, KEYLEN, key);
91 GSSName& GSSNameCache::retrieve ( std::string key )
99 // Maybe do something about data entries that are expired?
103 return *(names[key]);
106 GSSNameCache* GSSNameCache::instance()
109 _instance = new GSSNameCache;