Auth_OpenID_CryptUtil Klassenreferenz


Öffentliche Methoden

 getBytes ($num_bytes)
 randomString ($length, $population=null)

Ausführliche Beschreibung

Definiert in Zeile 26 der Datei CryptUtil.php.


Dokumentation der Elementfunktionen

getBytes ( num_bytes  ) 

Get the specified number of random bytes.

Attempts to use a cryptographically secure (not predictable) source of randomness if available. If there is no high-entropy randomness source available, it will fail. As a last resort, for non-critical systems, define Auth_OpenID_RAND_SOURCE as null, and the code will fall back on a pseudo-random number generator.

Parameter:
int $num_bytes The length of the return value
Rückgabe:
string $bytes random bytes

Definiert in Zeile 40 der Datei CryptUtil.php.

00041     {
00042         static $f = null;
00043         $bytes = '';
00044         if ($f === null) {
00045             if (Auth_OpenID_RAND_SOURCE === null) {
00046                 $f = false;
00047             } else {
00048                 $f = @fopen(Auth_OpenID_RAND_SOURCE, "r");
00049                 if ($f === false) {
00050                     $msg = 'Define Auth_OpenID_RAND_SOURCE as null to ' .
00051                         ' continue with an insecure random number generator.';
00052                     trigger_error($msg, E_USER_ERROR);
00053                 }
00054             }
00055         }
00056         if ($f === false) {
00057             // pseudorandom used
00058             $bytes = '';
00059             for ($i = 0; $i < $num_bytes; $i += 4) {
00060                 $bytes .= pack('L', mt_rand());
00061             }
00062             $bytes = substr($bytes, 0, $num_bytes);
00063         } else {
00064             $bytes = fread($f, $num_bytes);
00065         }
00066         return $bytes;
00067     }

randomString ( length,
population = null 
)

Produce a string of length random bytes, chosen from chrs. If $chrs is null, the resulting string may contain any characters.

Parameter:
integer $length The length of the resulting randomly-generated string
string $chrs A string of characters from which to choose to build the new string
Rückgabe:
string $result A string of randomly-chosen characters from $chrs

Definiert in Zeile 80 der Datei CryptUtil.php.

00081     {
00082         if ($population === null) {
00083             return Auth_OpenID_CryptUtil::getBytes($length);
00084         }
00085 
00086         $popsize = strlen($population);
00087 
00088         if ($popsize > 256) {
00089             $msg = 'More than 256 characters supplied to ' . __FUNCTION__;
00090             trigger_error($msg, E_USER_ERROR);
00091         }
00092 
00093         $duplicate = 256 % $popsize;
00094 
00095         $str = "";
00096         for ($i = 0; $i < $length; $i++) {
00097             do {
00098                 $n = ord(Auth_OpenID_CryptUtil::getBytes(1));
00099             } while ($n < $duplicate);
00100 
00101             $n %= $popsize;
00102             $str .= $population[$n];
00103         }
00104 
00105         return $str;
00106     }


Die Dokumentation für diese Klasse wurde erzeugt aufgrund der Datei:
Copyright © 2003 - 2009 MyOOS [Shopsystem]. All rights reserved.
MyOOS [Shopsystem] is Free Software released under the GNU/GPL License.

Webmaster: info@r23.de (Impressum)
doxygen