1414use LibreSign \PdfSignatureValidator \Model \ValidationState ;
1515use OCA \Libresign \AppInfo \Application ;
1616use OCP \IAppConfig ;
17+ use OCP \IL10N ;
1718use Psr \Log \LoggerInterface ;
1819
1920/**
@@ -29,6 +30,7 @@ class PdfSignatureValidationService {
2930
3031 public function __construct (
3132 private IAppConfig $ appConfig ,
33+ private IL10N $ l10n ,
3234 private LoggerInterface $ logger ,
3335 ) {
3436 $ this ->validator = new PdfSignatureValidator ();
@@ -158,31 +160,31 @@ private function mapSignatureValidation(ValidationResult $result): array {
158160 return match ($ result ->state ) {
159161 ValidationState::SIGNATURE_VALID => [
160162 'id ' => 1 ,
161- 'label ' => 'Signature is valid. ' ,
163+ 'label ' => $ this -> l10n -> t ( 'Signature is valid. ' ) ,
162164 'isValid ' => true ,
163165 ],
164166 ValidationState::SIGNATURE_INVALID => [
165167 'id ' => 2 ,
166- 'label ' => 'Signature is invalid. ' ,
167- 'reason ' => $ result ->reason ,
168+ 'label ' => $ this -> l10n -> t ( 'Signature is invalid. ' ) ,
169+ 'reason ' => $ this -> translateReason ( $ result ->reason ) ,
168170 'isValid ' => false ,
169171 ],
170172 ValidationState::DIGEST_MISMATCH => [
171173 'id ' => 3 ,
172- 'label ' => 'Digest mismatch. ' ,
173- 'reason ' => $ result ->reason ,
174+ 'label ' => $ this -> l10n -> t ( 'Digest mismatch. ' ) ,
175+ 'reason ' => $ this -> translateReason ( $ result ->reason ) ,
174176 'isValid ' => false ,
175177 ],
176178 ValidationState::NOT_VERIFIED => [
177179 'id ' => 5 ,
178- 'label ' => 'Signature has not yet been verified. ' ,
179- 'reason ' => $ result ->reason ,
180+ 'label ' => $ this -> l10n -> t ( 'Signature has not yet been verified. ' ) ,
181+ 'reason ' => $ this -> translateReason ( $ result ->reason ) ,
180182 'isValid ' => false ,
181183 ],
182184 default => [
183185 'id ' => 6 ,
184- 'label ' => 'Unknown validation failure. ' ,
185- 'reason ' => $ result ->reason ,
186+ 'label ' => $ this -> l10n -> t ( 'Unknown validation failure. ' ) ,
187+ 'reason ' => $ this -> translateReason ( $ result ->reason ) ,
186188 'isValid ' => false ,
187189 ],
188190 };
@@ -195,48 +197,56 @@ private function mapCertificateValidation(ValidationResult $result): array {
195197 return match ($ result ->state ) {
196198 ValidationState::CERT_TRUSTED => [
197199 'id ' => 1 ,
198- 'label ' => 'Certificate is trusted. ' ,
200+ 'label ' => $ this -> l10n -> t ( 'Certificate is trusted. ' ) ,
199201 'isValid ' => true ,
200202 ],
201203 ValidationState::CERT_ISSUER_NOT_TRUSTED => [
202204 'id ' => 2 ,
203- 'label ' => "Certificate issuer isn't trusted. " ,
204- 'reason ' => $ result ->reason ,
205+ 'label ' => $ this -> l10n -> t ( "Certificate issuer isn't trusted. " ) ,
206+ 'reason ' => $ this -> translateReason ( $ result ->reason ) ,
205207 'isValid ' => false ,
206208 ],
207209 ValidationState::CERT_ISSUER_UNKNOWN => [
208210 'id ' => 3 ,
209- 'label ' => 'Certificate issuer is unknown. ' ,
210- 'reason ' => $ result ->reason ,
211+ 'label ' => $ this -> l10n -> t ( 'Certificate issuer is unknown. ' ) ,
212+ 'reason ' => $ this -> translateReason ( $ result ->reason ) ,
211213 'isValid ' => false ,
212214 ],
213215 ValidationState::CERT_REVOKED => [
214216 'id ' => 4 ,
215- 'label ' => 'Certificate has been revoked. ' ,
216- 'reason ' => $ result ->reason ,
217+ 'label ' => $ this -> l10n -> t ( 'Certificate has been revoked. ' ) ,
218+ 'reason ' => $ this -> translateReason ( $ result ->reason ) ,
217219 'isValid ' => false ,
218220 ],
219221 ValidationState::CERT_EXPIRED => [
220222 'id ' => 5 ,
221- 'label ' => 'Certificate has expired. ' ,
222- 'reason ' => $ result ->reason ,
223+ 'label ' => $ this -> l10n -> t ( 'Certificate has expired. ' ) ,
224+ 'reason ' => $ this -> translateReason ( $ result ->reason ) ,
223225 'isValid ' => false ,
224226 ],
225227 ValidationState::CERT_NOT_VERIFIED => [
226228 'id ' => 6 ,
227- 'label ' => 'Certificate has not yet been verified. ' ,
228- 'reason ' => $ result ->reason ,
229+ 'label ' => $ this -> l10n -> t ( 'Certificate has not yet been verified. ' ) ,
230+ 'reason ' => $ this -> translateReason ( $ result ->reason ) ,
229231 'isValid ' => false ,
230232 ],
231233 default => [
232234 'id ' => 7 ,
233- 'label ' => 'Unknown issue with certificate or corrupted data. ' ,
234- 'reason ' => $ result ->reason ,
235+ 'label ' => $ this -> l10n -> t ( 'Unknown issue with certificate or corrupted data. ' ) ,
236+ 'reason ' => $ this -> translateReason ( $ result ->reason ) ,
235237 'isValid ' => false ,
236238 ],
237239 };
238240 }
239241
242+ private function translateReason (?string $ reason ): ?string {
243+ if ($ reason === null || $ reason === '' ) {
244+ return $ reason ;
245+ }
246+
247+ return $ this ->l10n ->t ($ reason );
248+ }
249+
240250 /**
241251 * Check if LibreSign CA is loaded.
242252 */
0 commit comments