PHP Class Dcrypt\Str

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

Méthodes publiques

Méthode 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

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

Method Details

equal() public static méthode

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
Résultat boolean

hashSize() public static méthode

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
Résultat integer

strlen() public static méthode

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

substr() public static méthode

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
Résultat string the extracted part of string; or FALSE on failure, or an empty string.