From bdee1e9aee4ebf24dcc7e69df358e22d12275f13 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Thu, 20 Aug 2020 14:56:36 +0200 Subject: [PATCH] Add wrapper around openssl_random_pseudo_bytes() --- MD_STD.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/MD_STD.php b/MD_STD.php index ec49462..9ed4f00 100644 --- a/MD_STD.php +++ b/MD_STD.php @@ -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; + + } + }