libresign/lib/Handler/CertificateEngine/Handler.php
Vitor Mattos 45cd3c374d
chore: Add SPDX header
Signed-off-by: Vitor Mattos <vitor@php.rio>
2024-05-14 12:32:04 -03:00

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;
}
}