summaryrefslogtreecommitdiffstats
path: root/vendor/ipl/validator/src/PrivateKeyValidator.php
blob: b629398c84d810d9c52fe1bcd62e80e61a38c51d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php

namespace ipl\Validator;

use ipl\I18n\Translation;

/**
 * Validates a private key
 */
class PrivateKeyValidator extends BaseValidator
{
    use Translation;

    public function isValid($value)
    {
        // Multiple isValid() calls must not stack validation messages
        $this->clearMessages();

        if (preg_match('/\A\s*\w+:/', $value)) {
            $this->addMessage($this->translate('URLs are not allowed'));

            return false;
        }

        if (openssl_pkey_get_private($value) === false) {
            $this->addMessage($this->translate('Not a valid PEM-encoded private key'));

            return false;
        }

        return true;
    }
}