5c060e59f4dfaaef7d80080266ed0784c7b1aa82
galt
  Mon Feb 13 15:55:34 2017 -0800
using makeRandomKey in cart.c, removed redundant copy in cartDb.c. code review feedback. refs #18737

diff --git src/lib/htmshell.c src/lib/htmshell.c
index c19528b..f6a8528 100644
--- src/lib/htmshell.c
+++ src/lib/htmshell.c
@@ -4,30 +4,31 @@
  * the html final stuff is written even if the program has
  * to abort.
  *
  * This also includes a few routines to write commonly used
  * html constructs such as images, horizontal lines. etc.
  *
  * This file is copyright 2002 Jim Kent, but license is hereby
  * granted for all use - public, private or commercial. */
 
 #include "common.h"
 #include "obscure.h"
 #include "cheapcgi.h"
 #include "htmshell.h"
 #include "errAbort.h"
 #include "dnautil.h"
+#include "base64.h"
 
 
 jmp_buf htmlRecover;
 
 boolean htmlWarnBoxSetUpAlready=FALSE;
 
 static bool NoEscape = FALSE;
 
 static bool errorsNoHeader = FALSE;
 
 void htmlSuppressErrors()
 /* Do not output a http header for error messages. Makes sure that very early
  * errors are not shown back to the user but trigger a 500 error, */
 {
 errorsNoHeader = TRUE;
@@ -838,32 +839,30 @@
     slNameAddHead(&classes, cloneString(buf));
 }
 if (htmlFormClass != NULL )
     slNameAddHead(&classes, htmlFormClass);
 fprintf(f, " CLASS=\"%s\"", slNameListToString(classes, ' '));
 
 if (htmlBackground != NULL )
     fprintf(f, " BACKGROUND=\"%s\"", htmlBackground);
 if (gotBgColor)
     fprintf(f, " BGCOLOR=\"#%X\"", htmlBgColor);
 fputs(">\n",f);
 }
 
 //--- NONCE and CSP routines -------------
 
-#include "base64.h"
-// copied from cartDb::cartDbMakeRandomKey()
 char *makeRandomKey(int numBits)
 /* Generate base64 encoding of a random key of at least size numBits returning string to be freed when done */
 {
 int numBytes = (numBits + 7) / 8;  // round up to nearest whole byte.
 numBytes = ((numBytes+2)/3)*3;  // round up to the nearest multiple of 3 to avoid equals-char padding in base64 output
 FILE *f = mustOpen("/dev/urandom", "r");   // open random system device for read-only access.
 char *binaryString = needMem(numBytes);
 mustRead(f, binaryString, numBytes);
 carefulClose(&f);
 char * result = base64Encode(binaryString, numBytes); // converts 3 binary bytes into 4 printable characters
 int len = strlen(result);
 memSwapChar(result, len, '+', 'A'); // replace + and / with characters that are URL-friendly.
 memSwapChar(result, len, '/', 'a');
 freeMem(binaryString);
 return result;