source: branches/version-2_5-dev/data/module/Compat/Compat/Function/hash.php @ 20116

Revision 20116, 1.3 KB checked in by nanasess, 13 years ago (diff)
  • svn properties を再設定
  • 再設定用のスクリプト追加
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2
3/**
4 * Replace hash()
5 *
6 * @category    PHP
7 * @package     PHP_Compat
8 * @license     LGPL - http://www.gnu.org/licenses/lgpl.html
9 * @copyright   2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net>
10 * @link        http://php.net/function.hash
11 * @author      revulo <revulon@gmail.com>
12 * @since       PHP 5.1.2
13 * @require     PHP 4.0.0 (user_error)
14 */
15function php_compat_hash($algo, $data, $raw_output = false)
16{
17    $algo = strtolower($algo);
18    switch ($algo) {
19        case 'md5':
20            $hash = md5($data);
21            break;
22
23        case 'sha1':
24            if (!function_exists('sha1')) {
25                require dirname(__FILE__) . '/sha1.php';
26            }
27            $hash = sha1($data);
28            break;
29
30        case 'sha256':
31            if (!function_exists('php_compat_sha256')) {
32                require dirname(__FILE__) . '/_sha256.php';
33            }
34            $hash = php_compat_sha256($data);
35            break;
36
37        default:
38            user_error('hash(): Unknown hashing algorithm: ' . $algo, E_USER_WARNING);
39            return false;
40    }
41
42    if ($raw_output) {
43        return pack('H*', $hash);
44    } else {
45        return $hash;
46    }
47}
48
49
50// Define
51if (!function_exists('hash')) {
52    function hash($algo, $data, $raw_output = false)
53    {
54        return php_compat_hash($algo, $data, $raw_output);
55    }
56}
Note: See TracBrowser for help on using the repository browser.