From: Michael M Slusarz Date: Fri, 5 Mar 2010 06:39:59 +0000 (-0700) Subject: Move uriB64[En|De]code() to Horde_Url X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=837be59133c0b29f14d5b97f5a187685dbc1be85;p=horde.git Move uriB64[En|De]code() to Horde_Url --- diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index 2140d940b..ea7ef120d 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -512,7 +512,7 @@ HTML; $queryString .= '&_t=' . $now . '&_h='; - return $queryString . Horde_Util::uriB64Encode(hash_hmac('sha1', $queryString, $GLOBALS['conf']['secret_key'], true)); + return $queryString . Horde_Url::uriB64Encode(hash_hmac('sha1', $queryString, $GLOBALS['conf']['secret_key'], true)); } /** @@ -538,7 +538,7 @@ HTML; $queryString = substr($data, 0, $pos); $hmac = substr($data, $pos); - if ($hmac != Horde_Util::uriB64Encode(hash_hmac('sha1', $queryString, $GLOBALS['conf']['secret_key'], true))) { + if ($hmac != Horde_Url::uriB64Encode(hash_hmac('sha1', $queryString, $GLOBALS['conf']['secret_key'], true))) { return false; } diff --git a/framework/Token/lib/Horde/Token.php b/framework/Token/lib/Horde/Token.php index 4315cde6f..88353c87a 100644 --- a/framework/Token/lib/Horde/Token.php +++ b/framework/Token/lib/Horde/Token.php @@ -124,7 +124,7 @@ class Horde_Token */ public function generateId($seed = '') { - return Horde_Util::uriB64Encode(pack('H*', sha1(uniqid(mt_rand(), true) . $seed . (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '')))); + return Horde_Url::uriB64Encode(pack('H*', sha1(uniqid(mt_rand(), true) . $seed . (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '')))); } /** diff --git a/framework/Token/package.xml b/framework/Token/package.xml index 2fbc66ca3..eeb2143ce 100644 --- a/framework/Token/package.xml +++ b/framework/Token/package.xml @@ -55,6 +55,10 @@ http://pear.php.net/dtd/package-2.0.xsd"> pear.horde.org + Url + pear.horde.org + + Util pear.horde.org diff --git a/framework/Url/lib/Horde/Url.php b/framework/Url/lib/Horde/Url.php index 9652dff4e..6f874f270 100644 --- a/framework/Url/lib/Horde/Url.php +++ b/framework/Url/lib/Horde/Url.php @@ -253,4 +253,33 @@ class Horde_Url return $link . '>'; } + /** + * URL-safe base64 encoding, with trimmed '='. + * + * @param string $string String to encode. + * + * @return string URL-safe, base64 encoded data. + */ + static public function uriB64Encode($string) + { + return str_replace(array('+', '/', '='), array('-', '_', ''), base64_encode($string)); + } + + /** + * Decode URL-safe base64 data, dealing with missing '='. + * + * @param string $string Encoded data. + * + * @return string Decoded data. + */ + static public function uriB64Decode($string) + { + $data = str_replace(array('-', '_'), array('+', '/'), $string); + $mod4 = strlen($data) % 4; + if ($mod4) { + $data .= substr('====', $mod4); + } + return base64_decode($data); + } + } diff --git a/framework/Url/package.xml b/framework/Url/package.xml index 37705e6df..a7c0bee1a 100644 --- a/framework/Url/package.xml +++ b/framework/Url/package.xml @@ -29,7 +29,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - * Initial package. + * Added Horde_Url::uriB64Encode() and Horde_Url::uriB64Decode(). + * Initial package. diff --git a/framework/Util/lib/Horde/Util.php b/framework/Util/lib/Horde/Util.php index 527bfde73..a36ae1176 100644 --- a/framework/Util/lib/Horde/Util.php +++ b/framework/Util/lib/Horde/Util.php @@ -778,35 +778,6 @@ class Horde_Util } /** - * URL-safe base64 encoding, with trimmed '='. - * - * @param string $string String to encode. - * - * @return string URL-safe, base64 encoded data. - */ - static public function uriB64Encode($string) - { - return str_replace(array('+', '/', '='), array('-', '_', ''), base64_encode($string)); - } - - /** - * Decode URL-safe base64 data, dealing with missing '='. - * - * @param string $string Encoded data - * - * @return string Decoded data. - */ - static public function uriB64Decode($string) - { - $data = str_replace(array('-', '_'), array('+', '/'), $string); - $mod4 = strlen($data) % 4; - if ($mod4) { - $data .= substr('====', $mod4); - } - return base64_decode($data); - } - - /** * Convert a variable to UTF-8. Recursively handles inner variables. * * @param mixed $in The variable to convert. diff --git a/framework/Util/package.xml b/framework/Util/package.xml index 4246f2efb..843ec8ee5 100644 --- a/framework/Util/package.xml +++ b/framework/Util/package.xml @@ -29,7 +29,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - * Removed Horde_Util::strftime2date() and Horde_Util::date2strftime(). + * Removed Horde_Util::uriB64Encode() and Horde_Util::uriB64Decode(). + * Removed Horde_Util::strftime2date() and Horde_Util::date2strftime(). * Removed Horde_Util::closeWindowJs() and Horde_Util::nocacheUrl(). * Added Horde_Util::convertToUtf8(). * Added Horde_Util::abbreviate().