Code Duplication    Length = 20-20 lines in 2 locations

src/BasePrivateKeyAsymmetricCrypt.php 1 location

@@ 28-47 (lines=20) @@
25
/**
26
 * @package Limoncello\Crypt
27
 */
28
abstract class BasePrivateKeyAsymmetricCrypt extends BaseAsymmetricCrypt
29
{
30
    /**
31
     * @param string $privateKeyOrPath Could be either private key or path to file prefixed with 'file://'.
32
     */
33
    public function __construct(string $privateKeyOrPath)
34
    {
35
        assert(
36
            $this->checkIfPathToFileCheckPrefix($privateKeyOrPath),
37
            'It seems you try to use path to file. If so you should prefix it with \'file://\'.'
38
        );
39
40
        $this->clearErrors();
41
42
        $privateKey = openssl_pkey_get_private($privateKeyOrPath);
43
        $privateKey !== false ?: $this->throwException(new CryptException($this->getErrorMessage()));
44
45
        $this->setKey($privateKey);
46
    }
47
}
48

src/BasePublicKeyAsymmetricCrypt.php 1 location

@@ 28-47 (lines=20) @@
25
/**
26
 * @package Limoncello\Crypt
27
 */
28
abstract class BasePublicKeyAsymmetricCrypt extends BaseAsymmetricCrypt
29
{
30
    /**
31
     * @param string $publicKeyOrPath Could be either public key or path to file prefixed with 'file://'.
32
     */
33
    public function __construct(string $publicKeyOrPath)
34
    {
35
        assert(
36
            $this->checkIfPathToFileCheckPrefix($publicKeyOrPath),
37
            'It seems you try to use path to file. If so you should prefix it with \'file://\'.'
38
        );
39
40
        $this->clearErrors();
41
42
        $publicKey = openssl_pkey_get_public($publicKeyOrPath);
43
        $publicKey !== false ?: $this->throwException(new CryptException($this->getErrorMessage()));
44
45
        $this->setKey($publicKey);
46
    }
47
}
48