Update random_bytes length in filename and prefix generation

The size of the random byte string used in the generateFilename method of StoredObjectVersion has been reduced from 16 to 8. Conversely, the size of the random byte string used in the generatePrefix method of StoredObject has been increased from 8 to 32.

The naming generation fit better with the usage, as 16bytes are generated for each file (more version), and less for the version.
This commit is contained in:
Julien Fastré 2024-07-12 00:00:44 +02:00
parent 2feea24c41
commit cb90261309
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
3 changed files with 3 additions and 3 deletions

View File

@ -354,7 +354,7 @@ class StoredObject implements Document, TrackCreationInterface
public static function generatePrefix(): string
{
try {
return base_convert(bin2hex(random_bytes(8)), 16, 36);
return base_convert(bin2hex(random_bytes(32)), 16, 36);
} catch (RandomException $e) {
return uniqid(more_entropy: true);
}

View File

@ -82,7 +82,7 @@ class StoredObjectVersion implements TrackCreationInterface
public static function generateFilename(StoredObjectVersion $storedObjectVersion): string
{
try {
$suffix = base_convert(bin2hex(random_bytes(16)), 16, 36);
$suffix = base_convert(bin2hex(random_bytes(8)), 16, 36);
} catch (RandomException $e) {
$suffix = uniqid(more_entropy: true);
}

View File

@ -104,7 +104,7 @@ final readonly class ChillDocumentManager implements DocumentManagerInterface
throw new \Error('Unknown mimetype for stored document.');
}
return sprintf('%s.%s', $document->getFilename(), reset($exts));
return sprintf('%s.%s', $document->getPrefix(), reset($exts));
}
/**