Add optional self-hosted ALTCHA protection and dependency maintenance
This commit is contained in:
1 parent
3b558409f3
commit
2a2f1d5878
59 files changed
+2648
-12
No files matched your search
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace HGCFVendor\AltchaOrg\Altcha;
|
||||
|
||||
class Solution
|
||||
{
|
||||
public function __construct(
|
||||
public readonly int $counter,
|
||||
public readonly string $derivedKey,
|
||||
public readonly ?float $time = null,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$arr = [
|
||||
'counter' => $this->counter,
|
||||
'derivedKey' => $this->derivedKey,
|
||||
];
|
||||
if (null !== $this->time) {
|
||||
$arr['time'] = $this->time;
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $arr
|
||||
*/
|
||||
public static function fromArray(array $arr): self
|
||||
{
|
||||
if (!isset($arr['counter'], $arr['derivedKey']) || !\is_int($arr['counter']) || !\is_string($arr['derivedKey'])) {
|
||||
throw new \InvalidArgumentException('Invalid solution data: expected "counter" (int) and "derivedKey" (string).');
|
||||
}
|
||||
|
||||
return new self(
|
||||
counter: $arr['counter'],
|
||||
derivedKey: $arr['derivedKey'],
|
||||
time: isset($arr['time']) && is_numeric($arr['time']) ? (float) $arr['time'] : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user