Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
68.75% |
33 / 48 |
|
58.82% |
10 / 17 |
CRAP | |
0.00% |
0 / 1 |
| Crl | |
68.75% |
33 / 48 |
|
58.82% |
10 / 17 |
49.25 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
1 | |||
| getStatus | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setStatus | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| getCertificateTypeEnum | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCertificateType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setCertificateType | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| getIssuer | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getIssuerData | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| setIssuer | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setIssuerFromArray | |
50.00% |
2 / 4 |
|
0.00% |
0 / 1 |
2.50 | |||
| getSubject | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSubjectData | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| setSubject | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setSubjectFromArray | |
50.00% |
2 / 4 |
|
0.00% |
0 / 1 |
2.50 | |||
| isRevoked | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isExpired | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| isValid | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * SPDX-FileCopyrightText: 2025 LibreCode coop and contributors |
| 7 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | */ |
| 9 | |
| 10 | namespace OCA\Libresign\Db; |
| 11 | |
| 12 | use OCA\Libresign\Enum\CertificateType; |
| 13 | use OCA\Libresign\Enum\CRLStatus; |
| 14 | use OCP\AppFramework\Db\Entity; |
| 15 | use OCP\DB\Types; |
| 16 | |
| 17 | /** |
| 18 | * @method void setId(int $id) |
| 19 | * @method int getId() |
| 20 | * @method void setSerialNumber(string $serialNumber) |
| 21 | * @method string getSerialNumber() |
| 22 | * @method void setOwner(string $owner) |
| 23 | * @method string getOwner() |
| 24 | * @method void setReasonCode(?int $reasonCode) |
| 25 | * @method ?int getReasonCode() |
| 26 | * @method void setRevokedBy(?string $revokedBy) |
| 27 | * @method ?string getRevokedBy() |
| 28 | * @method void setRevokedAt(?\DateTime $revokedAt) |
| 29 | * @method ?\DateTime getRevokedAt() |
| 30 | * @method void setInvalidityDate(?\DateTime $invalidityDate) |
| 31 | * @method ?\DateTime getInvalidityDate() |
| 32 | * @method void setCrlNumber(?int $crlNumber) |
| 33 | * @method ?int getCrlNumber() |
| 34 | * @method void setIssuedAt(\DateTime $issuedAt) |
| 35 | * @method \DateTime getIssuedAt() |
| 36 | * @method void setValidTo(?\DateTime $validTo) |
| 37 | * @method ?\DateTime getValidTo() |
| 38 | * @method void setComment(?string $comment) |
| 39 | * @method ?string getComment() |
| 40 | * @method void setEngine(string $engine) |
| 41 | * @method string getEngine() |
| 42 | * @method void setInstanceId(?string $instanceId) |
| 43 | * @method ?string getInstanceId() |
| 44 | * @method void setGeneration(?int $generation) |
| 45 | * @method ?int getGeneration() |
| 46 | * @method void setIssuer(?string $issuer) |
| 47 | * @method ?string getIssuer() |
| 48 | * @method void setSubject(?string $subject) |
| 49 | * @method ?string getSubject() |
| 50 | */ |
| 51 | class Crl extends Entity { |
| 52 | protected string $serialNumber = ''; |
| 53 | protected string $owner = ''; |
| 54 | protected string $status = 'issued'; |
| 55 | protected ?int $reasonCode = null; |
| 56 | protected ?string $revokedBy = null; |
| 57 | protected ?\DateTime $revokedAt = null; |
| 58 | protected ?\DateTime $invalidityDate = null; |
| 59 | protected ?int $crlNumber = null; |
| 60 | protected ?\DateTime $issuedAt = null; |
| 61 | protected ?\DateTime $validTo = null; |
| 62 | protected ?string $comment = null; |
| 63 | protected string $engine = ''; |
| 64 | protected ?string $instanceId = null; |
| 65 | protected ?int $generation = null; |
| 66 | protected ?string $issuer = null; |
| 67 | protected ?string $subject = null; |
| 68 | protected string $certificateType = 'leaf'; |
| 69 | |
| 70 | public function __construct() { |
| 71 | $this->addType('id', Types::BIGINT); |
| 72 | $this->addType('serialNumber', Types::STRING); |
| 73 | $this->addType('status', Types::STRING); |
| 74 | $this->addType('reasonCode', Types::SMALLINT); |
| 75 | $this->addType('crlNumber', Types::BIGINT); |
| 76 | $this->addType('revokedAt', Types::DATETIME); |
| 77 | $this->addType('invalidityDate', Types::DATETIME); |
| 78 | $this->addType('issuedAt', Types::DATETIME); |
| 79 | $this->addType('validTo', Types::DATETIME); |
| 80 | $this->addType('comment', Types::STRING); |
| 81 | $this->addType('engine', Types::STRING); |
| 82 | $this->addType('instanceId', Types::STRING); |
| 83 | $this->addType('generation', Types::BIGINT); |
| 84 | $this->addType('issuer', Types::TEXT); |
| 85 | $this->addType('subject', Types::TEXT); |
| 86 | $this->addType('certificateType', Types::STRING); |
| 87 | } |
| 88 | |
| 89 | public function getStatus(): string { |
| 90 | return $this->status; |
| 91 | } |
| 92 | |
| 93 | public function setStatus(CRLStatus|string $status): void { |
| 94 | $value = $status instanceof CRLStatus ? $status->value : $status; |
| 95 | $this->setter('status', [$value]); |
| 96 | } |
| 97 | |
| 98 | public function getCertificateTypeEnum(): CertificateType { |
| 99 | return CertificateType::from($this->certificateType); |
| 100 | } |
| 101 | |
| 102 | public function getCertificateType(): string { |
| 103 | return $this->certificateType; |
| 104 | } |
| 105 | |
| 106 | public function setCertificateType(CertificateType|string $type): void { |
| 107 | $value = $type instanceof CertificateType ? $type->value : $type; |
| 108 | $this->setter('certificateType', [$value]); |
| 109 | } |
| 110 | |
| 111 | public function getIssuer(): ?string { |
| 112 | return $this->issuer; |
| 113 | } |
| 114 | |
| 115 | public function getIssuerData(): ?array { |
| 116 | if ($this->issuer === null) { |
| 117 | return null; |
| 118 | } |
| 119 | $decoded = json_decode($this->issuer, true); |
| 120 | return is_array($decoded) ? $decoded : null; |
| 121 | } |
| 122 | |
| 123 | public function setIssuer(?string $issuer): void { |
| 124 | $this->setter('issuer', [$issuer]); |
| 125 | } |
| 126 | |
| 127 | public function setIssuerFromArray(?array $issuer): void { |
| 128 | if ($issuer === null) { |
| 129 | $this->setter('issuer', [null]); |
| 130 | return; |
| 131 | } |
| 132 | $this->setter('issuer', [json_encode($issuer)]); |
| 133 | } |
| 134 | |
| 135 | public function getSubject(): ?string { |
| 136 | return $this->subject; |
| 137 | } |
| 138 | |
| 139 | public function getSubjectData(): ?array { |
| 140 | if ($this->subject === null) { |
| 141 | return null; |
| 142 | } |
| 143 | $decoded = json_decode($this->subject, true); |
| 144 | return is_array($decoded) ? $decoded : null; |
| 145 | } |
| 146 | |
| 147 | public function setSubject(?string $subject): void { |
| 148 | $this->setter('subject', [$subject]); |
| 149 | } |
| 150 | |
| 151 | public function setSubjectFromArray(?array $subject): void { |
| 152 | if ($subject === null) { |
| 153 | $this->setter('subject', [null]); |
| 154 | return; |
| 155 | } |
| 156 | $this->setter('subject', [json_encode($subject)]); |
| 157 | } |
| 158 | |
| 159 | public function isRevoked(): bool { |
| 160 | return CRLStatus::from($this->status) === CRLStatus::REVOKED; |
| 161 | } |
| 162 | |
| 163 | public function isExpired(): bool { |
| 164 | if ($this->validTo === null) { |
| 165 | return false; |
| 166 | } |
| 167 | return $this->validTo < new \DateTime(); |
| 168 | } |
| 169 | |
| 170 | public function isValid(): bool { |
| 171 | return !$this->isRevoked() && !$this->isExpired(); |
| 172 | } |
| 173 | } |