فهرست منبع

! Some minor updates for 5.1 support, sha1 support and only file_put_contents for smf cache

Spuds 13 سال پیش
والد
کامیت
bd7e615ca2
2فایلهای تغییر یافته به همراه6 افزوده شده و 49 حذف شده
  1. 2 25
      Sources/Load.php
  2. 4 24
      Sources/Subs-OpenID.php

+ 2 - 25
Sources/Load.php

@@ -2682,31 +2682,8 @@ function cache_put_data($key, $value, $ttl = 120)
 			
 			// Write out the cache file, check that the cache write was successful; all the data must be written
 			// If it fails due to low diskspace, or other, remove the cache file
-			if (version_compare(PHP_VERSION, '5.1', '<'))
-			{
-				$fh = @fopen($cachedir . '/data_' . $key . '.php', 'w');
-				if ($fh)
-				{
-					// Write the file.
-					set_file_buffer($fh, 0);
-
-					if (flock($fh, LOCK_EX))
-						$cache_bytes = fwrite($fh, $cache_data);
-					else
-						$cache_bytes = 0;
-
-					flock($fh, LOCK_UN);
-					fclose($fh);
-
-					if ($cache_bytes !== strlen($cache_data))
-						@unlink($cachedir . '/data_' . $key . '.php');
-				}
-			}
-			else
-			{
-				if (file_put_contents($cachedir . '/data_' . $key . '.php', $cache_data, LOCK_EX) !== strlen($cache_data))
-					@unlink($cachedir . '/data_' . $key . '.php');
-			}
+			if (file_put_contents($cachedir . '/data_' . $key . '.php', $cache_data, LOCK_EX) !== strlen($cache_data))
+				@unlink($cachedir . '/data_' . $key . '.php');
 		}
 	}
 	

+ 4 - 24
Sources/Subs-OpenID.php

@@ -199,7 +199,7 @@ function smf_openID_makeAssociation($server)
 	if (!empty($assoc_data['enc_mac_key']))
 	{
 		$dh_secret = bcpowmod(binary_to_long(base64_decode($assoc_data['dh_server_public'])), $dh_keys['private'], $p);
-		$secret = base64_encode(binary_xor(sha1_raw(long_to_binary($dh_secret)), base64_decode($assoc_data['enc_mac_key'])));
+		$secret = base64_encode(binary_xor(sha1(long_to_binary($dh_secret), true), base64_decode($assoc_data['enc_mac_key'])));
 	}
 	else
 		$secret = $assoc_data['mac_key'];
@@ -569,37 +569,17 @@ function sha1_hmac($data, $key)
 {
 
 	if (strlen($key) > 64)
-		$key = sha1_raw($key);
+		$key = sha1($key, true);
 
 	// Pad the key if need be.
 	$key = str_pad($key, 64, chr(0x00));
 	$ipad = str_repeat(chr(0x36), 64);
 	$opad = str_repeat(chr(0x5c), 64);
-	$hash1 = sha1_raw(($key ^ $ipad) . $data);
-	$hmac = sha1_raw(($key ^ $opad) . $hash1);
+	$hash1 = sha1(($key ^ $ipad) . $data, true);
+	$hmac = sha1(($key ^ $opad) . $hash1, true);
 	return $hmac;
 }
 
-/**
- * @todo move to Subs-Compat.php
- */
-function sha1_raw($text)
-{
-	if (version_compare(PHP_VERSION, '5.0.0', '>='))
-		return sha1($text, true);
-
-	$hex = sha1($text);
-	$raw = '';
-	for ($i = 0; $i < 40; $i += 2)
-	{
-		$hexcode = substr($hex, $i, 2);
-		$charcode = (int) base_convert($hexcode, 16, 10);
-		$raw .= chr($charcode);
-	}
-
-	return $raw;
-}
-
 function binary_to_long($str)
 {
 	$bytes = array_merge(unpack('C*', $str));