[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * The Horde_Crypt:: class provides an API for various cryptographic 4 * systems used by Horde applications. 5 * 6 * $Horde: framework/Crypt/Crypt.php,v 1.27.10.9 2006/01/01 21:28:12 jan Exp $ 7 * 8 * Copyright 2002-2006 Michael Slusarz <slusarz@bigworm.colorado.edu> 9 * 10 * See the enclosed file COPYING for license information (LGPL). If you 11 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 12 * 13 * @author Michael Slusarz <slusarz@bigworm.colorado.edu> 14 * @since Horde 3.0 15 * @package Horde_Crypt 16 */ 17 class Horde_Crypt { 18 19 /** 20 * The temporary directory to use. 21 * 22 * @var string 23 */ 24 var $_tempdir; 25 26 /** 27 * Attempts to return a concrete Horde_Crypt instance based on $driver. 28 * 29 * @param mixed $driver The type of concrete Horde_Crypt subclass to 30 * return. If $driver is an array, then we will look 31 * in $driver[0]/lib/Crypt/ for the subclass 32 * implementation named $driver[1].php. 33 * @param array $params A hash containing any additional configuration or 34 * parameters a subclass might need. 35 * 36 * @return Horde_Crypt The newly created concrete Horde_Crypt instance, or 37 * false on an error. 38 */ 39 function &factory($driver, $params = array()) 40 { 41 if (is_array($driver)) { 42 list($app, $driver) = $driver; 43 } 44 45 /* Return a base Horde_Crypt object if no driver is specified. */ 46 $driver = basename($driver); 47 if (empty($driver) || (strcmp($driver, 'none') == 0)) { 48 $crypt = &new Horde_Crypt(); 49 return $crypt; 50 } 51 52 if (!empty($app)) { 53 require_once $GLOBALS['registry']->get('fileroot', $app) . '/lib/Crypt/' . $driver . '.php'; 54 } elseif (@file_exists(dirname(__FILE__) . '/Crypt/' . $driver . '.php')) { 55 require_once dirname(__FILE__) . '/Crypt/' . $driver . '.php'; 56 } else { 57 @include_once 'Horde/Crypt/' . $driver . '.php'; 58 } 59 $class = 'Horde_Crypt_' . $driver; 60 if (class_exists($class)) { 61 $crypt = &new $class($params); 62 } else { 63 $crypt = PEAR::raiseError('Class definition of ' . $class . ' not found.'); 64 } 65 66 return $crypt; 67 } 68 69 /** 70 * Attempts to return a reference to a concrete Horde_Crypt instance 71 * based on $driver. It will only create a new instance if no 72 * Horde_Crypt instance with the same parameters currently exists. 73 * 74 * This should be used if multiple crypto backends (and, thus, 75 * multiple Horde_Crypt instances) are required. 76 * 77 * This method must be invoked as: $var = &Horde_Crypt::singleton() 78 * 79 * @param mixed $driver The type of concrete Horde_Crypt subclass to 80 * return. If $driver is an array, then we will look 81 * in $driver[0]/lib/Crypt/ for the subclass 82 * implementation named $driver[1].php. 83 * @param array $params A hash containing any additional configuration or 84 * connection parameters a subclass might need. 85 * 86 * @return Horde_Crypt The concrete Horde_Crypt reference, or false on an 87 * error. 88 */ 89 function &singleton($driver, $params = array()) 90 { 91 static $instances; 92 93 if (!isset($instances)) { 94 $instances = array(); 95 } 96 97 $signature = serialize(array($driver, $params)); 98 if (!isset($instances[$signature])) { 99 $instances[$signature] = &Horde_Crypt::factory($driver, $params); 100 } 101 102 return $instances[$signature]; 103 } 104 105 /** 106 * Outputs error message if we are not using a secure connection. 107 * 108 * @return PEAR_Error Returns a PEAR_Error object if there is no secure 109 * connection. 110 */ 111 function requireSecureConnection() 112 { 113 global $browser; 114 115 if (!$browser->usingSSLConnection()) { 116 return PEAR::raiseError(_("The encryption features require a secure web connection.")); 117 } 118 } 119 120 /** 121 * Encrypt the requested data. 122 * This method should be provided by all classes that extend Horde_Crypt. 123 * 124 * @param string $data The data to encrypt. 125 * @param array $params An array of arguments needed to encrypt the data. 126 * 127 * @return array The encrypted data. 128 */ 129 function encrypt($data, $params = array()) 130 { 131 return $data; 132 } 133 134 /** 135 * Decrypt the requested data. 136 * This method should be provided by all classes that extend Horde_Crypt. 137 * 138 * @param string $data The data to decrypt. 139 * @param array $params An array of arguments needed to decrypt the data. 140 * 141 * @return array The decrypted data. 142 */ 143 function decrypt($data, $params = array()) 144 { 145 return $data; 146 } 147 148 /** 149 * Create a temporary file that will be deleted at the end of this 150 * process. 151 * 152 * @access private 153 * 154 * @param string $descrip Description string to use in filename. 155 * @param boolean $delete Delete the file automatically? 156 * 157 * @return string Filename of a temporary file. 158 */ 159 function _createTempFile($descrip = 'horde-crypt', $delete = true) 160 { 161 return Util::getTempFile($descrip, $delete, $this->_tempdir, true); 162 } 163 164 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |