Add wrapper around openssl_random_pseudo_bytes()

This commit is contained in:
Joshua Ramon Enslin 2020-08-20 14:56:36 +02:00 committed by Stefan Rohde-Enslin
parent 7b1dc582ed
commit bdee1e9aee

View File

@ -301,4 +301,19 @@ class MD_STD {
} }
/**
* Type-safe wrapper around openssl_random_pseudo_bytes.
*
* @param integer $length Length.
*
* @return string
*/
public static function openssl_random_pseudo_bytes(int $length):string {
$output = \openssl_random_pseudo_bytes($length);
if ($output === false) throw new Exception("Failed generating random pseudo bytes using openssl_random_pseudo_bytes");
return $output;
}
} }