From 0da6cd7fe547ad78793e4e88c12b9707553254ef Mon Sep 17 00:00:00 2001 From: flashwave Date: Tue, 7 Nov 2023 21:47:35 +0000 Subject: [PATCH] Use XString random string generation. --- src/Upload.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/Upload.php b/src/Upload.php index 43e106c..341233d 100644 --- a/src/Upload.php +++ b/src/Upload.php @@ -6,13 +6,12 @@ use InvalidArgumentException; use RuntimeException; use Imagick; use JsonSerializable; +use Index\XString; use Index\Data\IDbConnection; use Index\Data\IDbResult; use Index\Data\DbType; final class Upload implements JsonSerializable { - private const ID_CHARS = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789-_'; - public function __construct( private string $id = '', private int $userId = 0, @@ -197,14 +196,6 @@ final class Upload implements JsonSerializable { ]; } - public static function generateId(int $length = 32): string { - $bytes = str_repeat("\0", $length); - $chars = strlen(self::ID_CHARS); - for($i = 0; $i < $length; ++$i) - $bytes[$i] = self::ID_CHARS[random_int(0, $chars - 1)]; - return $bytes; - } - public static function create( IDbConnection $conn, Application $app, User $user, @@ -224,7 +215,7 @@ final class Upload implements JsonSerializable { if($fileExpiry < 0) throw new InvalidArgumentException('$fileExpiry must be a positive integer.'); - $id = self::generateId(); + $id = XString::random(32); $create = $conn->prepare( 'INSERT INTO `prm_uploads` (' . ' `upload_id`, `app_id`, `user_id`, `upload_name`,'