Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
TsaPolicy
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 keys
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 get
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4/**
5 * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
6 * SPDX-License-Identifier: AGPL-3.0-or-later
7 */
8
9namespace OCA\Libresign\Service\Policy\Provider\Tsa;
10
11use OCA\Libresign\Service\Policy\Contract\IPolicyDefinition;
12use OCA\Libresign\Service\Policy\Contract\IPolicyDefinitionProvider;
13use OCA\Libresign\Service\Policy\Model\PolicySpec;
14use OCA\Libresign\Service\Policy\Provider\Helper\PolicyKeyNormalizer;
15
16final class TsaPolicy implements IPolicyDefinitionProvider {
17    public const KEY = 'tsa_settings';
18    public const SYSTEM_APP_CONFIG_KEY = self::KEY;
19    public const PASSWORD_APP_CONFIG_KEY = self::SYSTEM_APP_CONFIG_KEY . '.password';
20
21    public function __construct(
22        private TsaPolicyManagedValue $managedValue,
23    ) {
24    }
25
26    #[\Override]
27    public function keys(): array {
28        return [
29            self::KEY,
30        ];
31    }
32
33    #[\Override]
34    public function get(string|\BackedEnum $policyKey): IPolicyDefinition {
35        return match (PolicyKeyNormalizer::normalize($policyKey)) {
36            self::KEY => new PolicySpec(
37                key: self::KEY,
38                defaultSystemValue: TsaPolicyValue::encode(TsaPolicyValue::defaults()),
39                allowedValues: static fn (): array => [],
40                normalizer: fn (mixed $rawValue): string => $this->managedValue->normalizeForPersistence($rawValue),
41                appConfigKey: self::SYSTEM_APP_CONFIG_KEY,
42                supportsUserPreference: false,
43                supportsRequestOverride: false,
44                requestLifecycle: PolicySpec::LIFECYCLE_RUNTIME,
45                supportedScopes: [PolicySpec::SCOPE_SYSTEM],
46                supportsGroupAdminDelegation: false,
47            ),
48            default => throw new \InvalidArgumentException('Unknown policy key: ' . PolicyKeyNormalizer::normalize($policyKey)),
49        };
50    }
51}