| 1 |
<?php |
| 2 |
|
| 3 |
namespace ipl\Validator; |
| 4 |
|
| 5 |
/** |
| 6 |
* Validate a PEM-encoded private key |
| 7 |
*/ |
| 8 |
class PrivateKeyValidator extends BaseValidator |
| 9 |
{ |
| 10 |
/** |
| 11 |
* Check whether the value is a valid PEM-encoded private key |
| 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_pkey_get_private($value) === false) { |
| 29 |
$this->addMessage($this->translate('Not a valid PEM-encoded private key')); |
| 30 |
|
| 31 |
return false; |
| 32 |
} |
| 33 |
|
| 34 |
return true; |
| 35 |
} |
| 36 |
} |