2023-11-05 17:53:48 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\builder\extension;
|
|
|
|
|
|
|
|
|
|
use SPC\builder\Extension;
|
2025-08-06 20:43:23 +08:00
|
|
|
use SPC\exception\ValidationException;
|
2023-11-05 17:53:48 +08:00
|
|
|
use SPC\util\CustomExt;
|
|
|
|
|
|
|
|
|
|
#[CustomExt('password-argon2')]
|
|
|
|
|
class password_argon2 extends Extension
|
|
|
|
|
{
|
2024-03-16 22:37:39 +08:00
|
|
|
public function getDistName(): string
|
|
|
|
|
{
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-10 21:08:25 +08:00
|
|
|
public function runCliCheckUnix(): void
|
2023-11-05 17:53:48 +08:00
|
|
|
{
|
2025-02-16 02:30:08 +09:00
|
|
|
[$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -n -r "assert(defined(\'PASSWORD_ARGON2I\'));"');
|
2023-11-05 17:53:48 +08:00
|
|
|
if ($ret !== 0) {
|
2025-08-06 20:43:23 +08:00
|
|
|
throw new ValidationException('extension ' . $this->getName() . ' failed sanity check', validation_module: 'password_argon2 function check');
|
2023-11-05 17:53:48 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-07-07 22:44:07 +07:00
|
|
|
|
|
|
|
|
public function patchBeforeMake(): bool
|
|
|
|
|
{
|
2025-07-19 15:10:42 +07:00
|
|
|
$patched = parent::patchBeforeMake();
|
2025-07-07 22:44:07 +07:00
|
|
|
if ($this->builder->getLib('libsodium') !== null) {
|
|
|
|
|
$extraLibs = getenv('SPC_EXTRA_LIBS');
|
|
|
|
|
if ($extraLibs !== false) {
|
|
|
|
|
$extraLibs = str_replace(
|
|
|
|
|
[BUILD_LIB_PATH . '/libargon2.a', BUILD_LIB_PATH . '/libsodium.a'],
|
2025-07-08 11:25:44 +07:00
|
|
|
['', BUILD_LIB_PATH . '/libargon2.a ' . BUILD_LIB_PATH . '/libsodium.a'],
|
2025-07-07 22:44:07 +07:00
|
|
|
$extraLibs,
|
|
|
|
|
);
|
|
|
|
|
$extraLibs = trim(preg_replace('/\s+/', ' ', $extraLibs)); // normalize spacing
|
|
|
|
|
f_putenv('SPC_EXTRA_LIBS=' . $extraLibs);
|
2025-07-19 15:10:42 +07:00
|
|
|
return true;
|
2025-07-07 22:44:07 +07:00
|
|
|
}
|
|
|
|
|
}
|
2025-07-19 15:10:42 +07:00
|
|
|
return $patched;
|
2025-07-07 22:44:07 +07:00
|
|
|
}
|
2025-08-04 10:14:48 +07:00
|
|
|
|
|
|
|
|
public function getConfigureArg(bool $shared = false): string
|
|
|
|
|
{
|
|
|
|
|
if ($this->builder->getLib('openssl') !== null) {
|
|
|
|
|
if ($this->builder->getPHPVersionID() >= 80500 || ($this->builder->getPHPVersionID() >= 80400 && !$this->builder->getOption('enable-zts'))) {
|
|
|
|
|
return '--without-password-argon2'; // use --with-openssl-argon2 in openssl extension instead
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return '--with-password-argon2';
|
|
|
|
|
}
|
2023-11-05 17:53:48 +08:00
|
|
|
}
|