Bug #21491 » 12502.diff
t3lib/class.t3lib_div.php (working copy) | ||
---|---|---|
}
|
||
/**
|
||
* Returns a variable length of a proper HMAC on a given
|
||
* input string and secret TYPO3 encryption key.
|
||
*
|
||
* @param string Input string to create HMAC from
|
||
* @param integer The maximum string-length of the output
|
||
* @return string Substring of the resulting HMAC, being at maximum $len chars long (from beginning)
|
||
*/
|
||
public static function hmac($input, $len=32) {
|
||
return substr(hash_hmac('md5', $input, $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']), 0, $len);
|
||
}
|
||
/**
|
||
* Takes comma-separated lists and arrays and removes all duplicates
|
||
* If a value in the list is trim(empty), the value is ignored.
|
||
* Usage: 16
|
tests/t3lib/t3lib_div_testcase.php (working copy) | ||
---|---|---|
t3lib_div::quoteJSvalue('\\')
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function hmacReturnsHashOfProperLength() {
|
||
$hmac = t3lib_div::hmac('message', 32);
|
||
$this->assertTrue(is_string($hmac) && !empty($hmac));
|
||
$this->assertTrue(strlen($hmac) <= 32);
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function hmacReturnsEqualHashesForEqualInput() {
|
||
$msg0 = 'message';
|
||
$msg1 = 'message';
|
||
$this->assertEquals(t3lib_div::hmac($msg0, 32), t3lib_div::hmac($msg1, 32));
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function hmacReturnsNotEqualHashesForNotEqualInput() {
|
||
$msg0 = 'message0';
|
||
$msg1 = 'message1';
|
||
$this->assertNotEquals(t3lib_div::hmac($msg0, 32), t3lib_div::hmac($msg1, 32));
|
||
}
|
||
}
|
||
?>
|