PHP Class Dcrypt\Str

The functions in this class were inspired by the symfony's StringUtils class.
Datei anzeigen Open project: dopecode/dcrypt Class Usage Examples

Public Methods

Method Description
equal ( string $known, string $given ) : boolean Compares two strings in constant time. Strings are hashed before comparison so information is not leaked when strings are not of equal length.
hashSize ( string $algo ) : integer Determine the length of the output of a given hash algorithm in bytes.
strlen ( string $string ) : integer Returns the number of bytes in a string.
substr ( string $string, integer $start, integer $length = null ) : string Returns part of a string.

Private Methods

Method Description
strcmp ( string $knownHash, string $givenHash ) : boolean Private constant-time strcmp method to use when hash_equals is unavailable.

Method Details

equal() public static method

Compares two strings in constant time. Strings are hashed before comparison so information is not leaked when strings are not of equal length.
public static equal ( string $known, string $given ) : boolean
$known string The string of known length to compare against
$given string The string that the user can control
return boolean

hashSize() public static method

Determine the length of the output of a given hash algorithm in bytes.
public static hashSize ( string $algo ) : integer
$algo string Name of algorithm to look up
return integer

strlen() public static method

Returns the number of bytes in a string.
public static strlen ( string $string ) : integer
$string string The string whose length we wish to obtain
return integer

substr() public static method

Returns part of a string.
public static substr ( string $string, integer $start, integer $length = null ) : string
$string string The string whose length we wish to obtain
$start integer
$length integer
return string the extracted part of string; or FALSE on failure, or an empty string.