mirror of
https://github.com/LibreSign/libresign.git
synced 2025-12-17 21:12:16 +01:00
42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
/**
|
|
* SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace OCA\Libresign\Handler\CertificateEngine;
|
|
|
|
use OCA\Libresign\Exception\LibresignException;
|
|
use OCP\AppFramework\Services\IAppConfig;
|
|
|
|
class Handler {
|
|
public function __construct(
|
|
private CfsslHandler $cfsslHandler,
|
|
private OpenSslHandler $openSslHandler,
|
|
private NoneHandler $noneHandler,
|
|
private IAppConfig $appConfig,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @return CfsslHandler|OpenSslHandler|IEngineHandler
|
|
*/
|
|
public function getEngine(string $engineName = '', array $rootCert = []): IEngineHandler {
|
|
if (!$engineName) {
|
|
$engineName = $this->appConfig->getAppValue('certificate_engine', 'openssl');
|
|
}
|
|
if ($engineName === 'openssl') {
|
|
$engine = $this->openSslHandler;
|
|
} elseif ($engineName === 'cfssl') {
|
|
$engine = $this->cfsslHandler;
|
|
} elseif ($engineName === 'none') {
|
|
$engine = $this->noneHandler;
|
|
} else {
|
|
throw new LibresignException('Certificate engine not found: ' . $engineName);
|
|
}
|
|
$engine->populateInstance($rootCert);
|
|
return $engine;
|
|
}
|
|
}
|