+ $challenge=base64_decode($challenge);
+ $parsed = array();
+ while (!empty($challenge)) {
+ if ($challenge{0} == ',') { // First char is a comma, must not be 1st time through loop
+ $challenge=substr($challenge,1);
+ }
+ $key=explode('=',$challenge,2);
+ $challenge=$key[1];
+ $key=$key[0];
+ if ($challenge{0} == '"') {
+ // We're in a quoted value
+ // Drop the first quote, since we don't care about it
+ $challenge=substr($challenge,1);
+ // Now explode() to the next quote, which is the end of our value
+ $val=explode('"',$challenge,2);
+ $challenge=$val[1]; // The rest of the challenge, work on it in next iteration of loop
+ $value=explode(',',$val[0]);
+ // Now, for those quoted values that are only 1 piece..
+ if (sizeof($value) == 1) {
+ $value=$value[0]; // Convert to non-array
+ }
+ } else {
+ // We're in a "simple" value - explode to next comma
+ $val=explode(',',$challenge,2);
+ if (isset($val[1])) {
+ $challenge=$val[1];
+ } else {
+ unset($challenge);
+ }
+ $value=$val[0];
+ }
+ $parsed["$key"]=$value;
+ } // End of while loop
+ return $parsed;
+}
+
+/**
+ * Creates a HMAC digest that can be used for authentication purposes
+ * See RFCs 2104, 2617, 2831
+ *
+ * Uses PHP's Hash extension if available (enabled by default in PHP
+ * 5.1.2+ - see http://www.php.net/manual/en/hash.requirements.php
+ * or, if installed on earlier PHP versions, the PECL hash module -
+ * see http://pecl.php.net/package/hash
+ *
+ * Otherwise, will attempt to use the Mhash extension - see
+ * http://www.php.net/manual/en/mhash.requirements.php
+ *
+ * Finally, a fall-back custom implementation is used if none of
+ * the above are available.
+ *
+ * @param string $data The data to be encoded/hashed
+ * @param string $key The (shared) secret key that will be used
+ * to build the keyed hash. This argument is
+ * technically optional, but only for internal
+ * use (when the custom hash implementation is
+ * being used) - external callers should always
+ * specify a value for this argument.
+ *
+ * @return string The HMAC-MD5 digest string
+ * @since 1.4.0
+ *
+ */
+function hmac_md5($data, $key='') {
+
+ // use PHP's native Hash extension if possible
+ //
+ if (function_exists('hash_hmac'))
+ return pack('H*', hash_hmac('md5', $data, $key));
+
+
+ // otherwise, use (obsolete) mhash extension if available
+ //
+ if (extension_loaded('mhash')) {
+
+ if ($key == '')
+ $mhash = mhash(MHASH_MD5, $data);
+ else
+ $mhash = mhash(MHASH_MD5, $data, $key);
+
+ return $mhash;