add util_base64 and util_random
[gssweb.git] / json_gssapi / src / cache / GSSContextCache.cpp
index d6f6ca3..b8b4dc6 100644 (file)
@@ -5,12 +5,10 @@
  *
  */
 
-// #include <glib.h>
 #include <stdexcept>
-#include <openssl/err.h>
-#include <openssl/rand.h>
+#include "util_random.h"
+#include "util_base64.h"
 
-#include "utils/base64.h"
 #include "GSSContextCache.h"
 
 #define KEYLEN 128
@@ -72,30 +70,14 @@ std::string GSSContextCache::store ( GSSContext& data, std::string inKey )
 bool GSSContextCache::generateKey(std::string &key)
 {
   /* Variables      */
-  int  osslReturn = 0;
   unsigned char theKey[KEYLEN];
-  bool existingErrors = false;
-  
-  /* Error checking */
-  // See if there are any queued OpenSSL errors already.
-  existingErrors = ( 0 == ERR_peek_error() ); 
-  
-  /* Setup          */
-  /* Main           */
-  // Generate random byte string
-  osslReturn = RAND_pseudo_bytes(theKey, KEYLEN);
-  
-  // Discard the error message if there weren't any OpenSSL errors to begin with.
-  if (osslReturn == 1 && !existingErrors)
-  {
-    while (0 != ERR_get_error() );
-    return(false);
-  }
+
+  if (!randGenPseudoRandom(theKey, KEYLEN))
+      return false;
 
   // Encode the binary string
-  key = (char *)theKey;
-  key = base64_encode(key);
-  
+  base64EncodeStr(theKey, KEYLEN, key);
+
   /* Cleanup        */
   /* Return         */
   return(true);