diff options
Diffstat (limited to 'plugins/openid/lib/Auth/OpenID/BigMath.php')
-rw-r--r-- | plugins/openid/lib/Auth/OpenID/BigMath.php | 77 |
1 files changed, 62 insertions, 15 deletions
diff --git a/plugins/openid/lib/Auth/OpenID/BigMath.php b/plugins/openid/lib/Auth/OpenID/BigMath.php index 58b46bf2..6a33322a 100644 --- a/plugins/openid/lib/Auth/OpenID/BigMath.php +++ b/plugins/openid/lib/Auth/OpenID/BigMath.php @@ -30,7 +30,7 @@ require_once 'Auth/OpenID.php'; * @access private * @package OpenID */ -class Auth_OpenID_MathLibrary { +abstract class Auth_OpenID_MathLibrary { /** * Given a long integer, returns the number converted to a binary * string. This function accepts long integer values of arbitrary @@ -78,7 +78,7 @@ class Auth_OpenID_MathLibrary { * Given a binary string, returns the binary string converted to a * long number. * - * @param string $binary The binary version of a long number, + * @param string $str The binary version of a long number, * probably as a result of calling longToBinary * @return integer $long The long number equivalent of the binary * string $str @@ -131,12 +131,8 @@ class Auth_OpenID_MathLibrary { * and will utilize the local large-number math library when * available. * - * @param integer $start The start of the range, or the minimum - * random number to return * @param integer $stop The end of the range, or the maximum * random number to return - * @param integer $step The step size, such that $result - ($step - * * N) = $start for some N * @return integer $result The resulting randomly-generated number */ function rand($stop) @@ -176,6 +172,55 @@ class Auth_OpenID_MathLibrary { return $this->mod($n, $stop); } + + /** + * @param int $number + * @param int $base + * @return int + */ + abstract protected function init($number, $base = 10); + + /** + * @param int $x + * @param int $y + * @return int + */ + abstract public function cmp($x, $y); + + /** + * @param int $x + * @param int $y + * @return int + */ + abstract protected function add($x, $y); + + /** + * @param int $x + * @param int $y + * @return int + */ + abstract protected function mul($x, $y); + + /** + * @param int $x + * @param int $y + * @return int + */ + abstract protected function div($x, $y); + + /** + * @param int $base + * @param int $modulus + * @return int + */ + abstract protected function mod($base, $modulus); + + /** + * @param int $base + * @param int $exponent + * @return int + */ + abstract protected function pow($base, $exponent); } /** @@ -188,7 +233,7 @@ class Auth_OpenID_MathLibrary { * @package OpenID */ class Auth_OpenID_BcMathWrapper extends Auth_OpenID_MathLibrary{ - var $type = 'bcmath'; + public $type = 'bcmath'; function add($x, $y) { @@ -234,6 +279,10 @@ class Auth_OpenID_BcMathWrapper extends Auth_OpenID_MathLibrary{ * Same as bcpowmod when bcpowmod is missing * * @access private + * @param int $base + * @param int $exponent + * @param int $modulus + * @return int */ function _powmod($base, $exponent, $modulus) { @@ -274,7 +323,7 @@ class Auth_OpenID_BcMathWrapper extends Auth_OpenID_MathLibrary{ * @package OpenID */ class Auth_OpenID_GmpMathWrapper extends Auth_OpenID_MathLibrary{ - var $type = 'gmp'; + public $type = 'gmp'; function add($x, $y) { @@ -360,11 +409,12 @@ function Auth_OpenID_math_extensions() /** * Detect which (if any) math library is available + * + * @param array $exts + * @return bool */ function Auth_OpenID_detectMathLibrary($exts) { - $loaded = false; - foreach ($exts as $extension) { if (extension_loaded($extension['extension'])) { return $extension; @@ -391,8 +441,7 @@ function Auth_OpenID_detectMathLibrary($exts) * This function checks for the existence of specific long number * implementations in the following order: GMP followed by BCmath. * - * @return Auth_OpenID_MathWrapper $instance An instance of - * {@link Auth_OpenID_MathWrapper} or one of its subclasses + * @return Auth_OpenID_MathLibrary|null * * @package OpenID */ @@ -421,12 +470,10 @@ function Auth_OpenID_getMathLib() foreach (Auth_OpenID_math_extensions() as $extinfo) { $tried[] = $extinfo['extension']; } - $triedstr = implode(", ", $tried); Auth_OpenID_setNoMathSupport(); - $result = null; - return $result; + return null; } // Instantiate a new wrapper |