ldc-arcadia-api/src/Application/Security/Models/ValueObjects/Request/HttpBodyHash.php

22 lines
590 B
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace Application\Security\Models\ValueObjects\Request;
final readonly class HttpBodyHash
{
public function __construct(
#[\SensitiveParameter]
public string $value
) {
if ($value === '') {
throw new \InvalidArgumentException('HttpBody cannot be empty');
}
// NOTE: Check if the body is a valid SHA256 hash (64 hex characters).
if (! preg_match('/^[a-f0-9]{64}$/i', $value)) {
throw new \InvalidArgumentException('HttpBody must be a valid SHA256 hash');
}
}
}