Debian Codegraph @

vendor/ipl/validator/src/X509CertValidator.php

raw
1 <?php
2
3 namespace ipl\Validator;
4
5 /**
6 * Validate a PEM-encoded X.509 certificate
7 */
8 class X509CertValidator extends BaseValidator
9 {
10 /**
11 * Check whether the value is a valid PEM-encoded X.509 certificate
12 *
13 * @param string $value
14 *
15 * @return bool
16 */
17 public function isValid($value): bool
18 {
19 // Reset messages from a previous isValid() call.
20 $this->clearMessages();
21
22 if (preg_match('/\A\s*\w+:/', $value)) {
23 $this->addMessage($this->translate('URLs are not allowed'));
24
25 return false;
26 }
27
28 if (openssl_x509_parse($value) === false) {
29 $this->addMessage($this->translate('Not a valid PEM-encoded X.509 certificate'));
30
31 return false;
32 }
33
34 return true;
35 }
36 }