2 * Copyright (c) 2014 <copyright holder> <email>
4 * For license details, see the LICENSE file in the root of this project.
9 #include "util_random.h"
10 #include "util_base64.h"
12 #include "GSSContextCache.h"
16 GSSContextCache* GSSContextCache::_instance = 0;
18 GSSContextCache::GSSContextCache()
23 GSSContextCache::~GSSContextCache()
28 GSSContextCache* GSSContextCache::instance()
31 _instance = new GSSContextCache;
37 std::string GSSContextCache::store ( GSSContext& data, std::string inKey )
46 if ( inKey.length() > 0 )
50 else if ( !generateKey(key) )
52 // Key generation failed. Eeek!
53 throw std::runtime_error("Could not generate random data for an ID");
56 // Store the key/value pair in the map
57 // Store the key in the context for convenience
62 // Return the key for future reference
66 /*************************************
67 * Generate random bytes, and base64 *
68 * encode them to be JSONable keys *
69 *************************************/
70 bool GSSContextCache::generateKey(std::string &key)
73 unsigned char theKey[KEYLEN];
75 if (!randGenPseudoRandom(theKey, KEYLEN))
78 // Encode the binary string
79 base64EncodeStr(theKey, KEYLEN, key);
86 GSSContext& GSSContextCache::retrieve ( std::string key )
94 // Maybe do something about data entries that are expired?