Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
123 lines
2.6 KiB
PHP
123 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Cose;
|
|
|
|
use Brick\Math\BigInteger as BrickBigInteger;
|
|
use Brick\Math\Exception\MathException;
|
|
use function chr;
|
|
use function hex2bin;
|
|
use function strlen;
|
|
use function unpack;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
final class BigInteger
|
|
{
|
|
private function __construct(
|
|
private readonly BrickBigInteger $value
|
|
) {
|
|
}
|
|
|
|
public static function createFromBinaryString(string $value): self
|
|
{
|
|
$res = unpack('H*', $value);
|
|
/** @var non-empty-string $data */
|
|
$data = current($res);
|
|
|
|
return new self(BrickBigInteger::fromBase($data, 16));
|
|
}
|
|
|
|
public static function createFromDecimal(int $value): self
|
|
{
|
|
return new self(BrickBigInteger::of($value));
|
|
}
|
|
|
|
/**
|
|
* Converts a BigInteger to a binary string.
|
|
*/
|
|
public function toBytes(): string
|
|
{
|
|
if ($this->value->isEqualTo(BrickBigInteger::zero())) {
|
|
return '';
|
|
}
|
|
|
|
$temp = $this->value->toBase(16);
|
|
$temp = 0 !== (strlen($temp) & 1) ? '0' . $temp : $temp;
|
|
$temp = hex2bin($temp);
|
|
|
|
return ltrim($temp, chr(0));
|
|
}
|
|
|
|
/**
|
|
* Adds two BigIntegers.
|
|
*/
|
|
public function add(self $y): self
|
|
{
|
|
$value = $this->value->plus($y->value);
|
|
|
|
return new self($value);
|
|
}
|
|
|
|
/**
|
|
* Subtracts two BigIntegers.
|
|
*/
|
|
public function subtract(self $y): self
|
|
{
|
|
$value = $this->value->minus($y->value);
|
|
|
|
return new self($value);
|
|
}
|
|
|
|
/**
|
|
* Multiplies two BigIntegers.
|
|
*/
|
|
public function multiply(self $x): self
|
|
{
|
|
$value = $this->value->multipliedBy($x->value);
|
|
|
|
return new self($value);
|
|
}
|
|
|
|
/**
|
|
* Performs modular exponentiation.
|
|
*/
|
|
public function modPow(self $e, self $n): self
|
|
{
|
|
$value = $this->value->modPow($e->value, $n->value);
|
|
|
|
return new self($value);
|
|
}
|
|
|
|
/**
|
|
* Returns the modular multiplicative inverse of this number modulo $m.
|
|
*
|
|
* @throws MathException if this number is not invertible modulo $m, i.e. if they are not coprime
|
|
*/
|
|
public function modInverse(self $m): self
|
|
{
|
|
$value = $this->value->modInverse($m->value);
|
|
|
|
return new self($value);
|
|
}
|
|
|
|
/**
|
|
* Performs modular exponentiation.
|
|
*/
|
|
public function mod(self $d): self
|
|
{
|
|
$value = $this->value->mod($d->value);
|
|
|
|
return new self($value);
|
|
}
|
|
|
|
/**
|
|
* Compares two numbers.
|
|
*/
|
|
public function compare(self $y): int
|
|
{
|
|
return $this->value->compareTo($y->value);
|
|
}
|
|
}
|