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/hg/lib/cartDb.c src/hg/lib/cartDb.c index 5c29528..1626ea4 100644 --- src/hg/lib/cartDb.c +++ src/hg/lib/cartDb.c @@ -105,48 +105,30 @@ } cartDefaultDisconnector(&conn); } else if (sameString(sessionKey, "off")) { useSessionKey = FALSE; } else if (sameString(sessionKey, "autodetect")) { errAbort("brower.sessionKey=autodetect has not implemented yet."); // TODO } } return useSessionKey; } -char *cartDbMakeRandomKey(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; -} - - void cartDbSecureId(char *buf, int bufSize, struct cartDb *cartDb) /* Return combined string of session id plus sessionKey in buf if turned on.*/ { if (cartDbUseSessionKey() && !sameString(cartDb->sessionKey,"")) safef(buf, bufSize, "%d_%s", cartDb->id, cartDb->sessionKey); else safef(buf, bufSize, "%d", cartDb->id); } unsigned int cartDbParseId(char *id, char **pSessionKey) /* Parse out the numeric id and id_sessionKey string if present. */ { unsigned int result = 0; if (sameString(id,"")) // some users reported blank cookie values. {